X-Git-Url: https://harishankar.org/repos/?p=biaweb2.git;a=blobdiff_plain;f=biawebdocumenttree.hpp;fp=biawebdocumenttree.hpp;h=41aa81aea2aa4c3f483decfccea2d87a5ccb9a8b;hp=9c91ed9028e63cc793691ab1b7af227ffd11c342;hb=406aa544d873974501056201467c88366f9d31f9;hpb=9dd960dd37c92af1ca6531c72b82849ea59a354c diff --git a/biawebdocumenttree.hpp b/biawebdocumenttree.hpp index 9c91ed9..41aa81a 100644 --- a/biawebdocumenttree.hpp +++ b/biawebdocumenttree.hpp @@ -5,6 +5,7 @@ #include #include #include "biawebdocument.hpp" +#include "biawebstrings.hpp" // to implement a document tree - both with or without subtrees namespace biaweb { @@ -40,7 +41,7 @@ namespace biaweb { } // create the document index for this tree - void create_index (); + void create_index (std::string destdir); // set the title void set_title (std::string title) { @@ -50,13 +51,8 @@ namespace biaweb { this->stub = convert_title (title); } - // set the stub either from a text or convert the title to stub - // if no stub is set explicitly void set_stub (std::string stub) { - if (stub != "") - this->stub = stub; - else - this->stub = convert_title (this->title); + this->stub = stub; } std::string get_title () { @@ -71,19 +67,7 @@ namespace biaweb { unsigned int get_level (); // get the stub hierarchy - std::string stub_hierarchy () { - std::list levels; - DocumentTree *par = this->get_parent(); - while (par!= nullptr) { - levels.push_front (par->get_stub()); - par = par->get_parent (); - } - std::string stub_str; - for (std::string level : levels) { - stub_str += level + "/"; - } - return stub_str; - } + std::string stub_hierarchy (); // add a child tree to this tree void add_child (DocumentTree *child) { @@ -116,6 +100,23 @@ namespace biaweb { return lev; } + // get the stub hierarchy for this tree + std::string DocumentTree::stub_hierarchy () { + std::list levels; + DocumentTree *par = this->get_parent(); + while (par!= nullptr) { + levels.push_front (par->get_stub()); + par = par->get_parent (); + } + std::string stub_str; + for (std::string level : levels) { + // if stub is empty, don't append a / + if (level != "") + stub_str += level + "/"; + } + return stub_str; + } + // print the representation of this tree void DocumentTree::visualize_tree () { // print the tree level @@ -131,17 +132,27 @@ namespace biaweb { } // create the tree index - the index file for this tree - void DocumentTree::create_index () { + void DocumentTree::create_index (std::string destdir) { std::unique_ptr index (new Document (this->title)); index.get()->set_index (); - // set the file name - std::string filepath = this->stub_hierarchy () + - this->stub; + // set the file name path + std::string filepath = destdir + "/" + this->stub_hierarchy () + this->stub; + // set the url path - this should not have destdir as it is not part + // of the site tree + std::string urlpath = this->stub_hierarchy () + this->stub; + // if urlpath is not empty then append a / to the end of the URL. This + // is so that the base URL is not absolute + if (urlpath != "") + urlpath += "/"; + // create the sidebar std::unique_ptr bar (new SideBar ()); - bar.get()->set_title (this->title); + bar.get()->set_title (SUB_CAT + this->title); for (DocumentTree tree : this->children) { - SideBarItem item (tree.get_title(), filepath + "/" + + // we use site relative URLs that rely on the base href tag + // so for biaweb generated sites, the base href tag should be + // used in the main template + SideBarItem item (tree.get_title(), urlpath + tree.stub + "/" + "index.html"); bar.get()->add_sidebar_item (item); } @@ -153,7 +164,7 @@ namespace biaweb { // create index for children for (DocumentTree tree : this->children) - tree.create_index (); + tree.create_index (destdir); } }