summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--music.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/music.cpp b/music.cpp
index cebf745..ee9f2ba 100644
--- a/music.cpp
+++ b/music.cpp
@@ -204,13 +204,26 @@ void MusicDirectory::render(HTTP::Connection::p req) {
std::string base_path = boost::algorithm::join(req->base_path, "/");
+ // strip root_directory from the absolute file path
+ std::string rel_base(path.string().substr(music::root_directory.string().size()));
+ // set relative base to "/" if we're at the root_directory
+ if(!rel_base.size())
+ rel_base = "/";
+ req->send_data(boost::str(boost::format("<h1>%s</h1>") % rel_base));
+
+ // link to parent directory if we're not at the root_directory
+ if(rel_base != "/") {
+ std::string rel_parent(rel_base.substr(0, rel_base.find_last_of('/')));
+ req->send_data(boost::str(boost::format("<a href=\"/%s%s/\">..</a><br />") % base_path % rel_parent));
+ }
+
for(PathListings::iterator it = directories.begin(); it != directories.end(); it++) {
std::string rel_path = it->string().substr(music::root_directory.string().size());
- req->send_data(boost::str(boost::format("<a href=\"/%s%s\">%s</a><br />") % base_path % rel_path % rel_path));
+ req->send_data(boost::str(boost::format("<a href=\"/%s%s/\">%s</a><br />") % base_path % rel_path % it->filename()));
}
for(PathListings::iterator it = tracks.begin(); it != tracks.end(); it++) {
std::string rel_path = it->string().substr(music::root_directory.string().size());
- req->send_data(boost::str(boost::format("<a href=\"/%s%s\">%s</a><br />") % base_path % rel_path % rel_path));
+ req->send_data(boost::str(boost::format("<a href=\"/%s%s\">%s</a><br />") % base_path % rel_path % it->filename()));
}
}