diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2011-01-06 15:08:08 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2011-01-06 15:08:08 +0100 |
commit | 9abc3cad022da793ae16912d7feced8eef58be3d (patch) | |
tree | 4fb72f090a03799ffa20640264eff3607d92bf70 | |
parent | 1ec5d937f619e3a9caa77b2210042607f00ab83c (diff) |
MusicDirectory::render() now outputs current directory and links to parent directory when applicable.
-rw-r--r-- | music.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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())); } } |