#include <iostream>
#include <filesystem>
#include "biawebdocument.hpp"
+#include "biawebstrings.hpp"
// to implement a document tree - both with or without subtrees
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) {
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 () {
unsigned int get_level ();
// get the stub hierarchy
- std::string stub_hierarchy () {
- std::list<std::string> 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) {
return lev;
}
+ // get the stub hierarchy for this tree
+ std::string DocumentTree::stub_hierarchy () {
+ std::list<std::string> 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
}
// create the tree index - the index file for this tree
- void DocumentTree::create_index () {
+ void DocumentTree::create_index (std::string destdir) {
std::unique_ptr<Document> 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<SideBar> 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);
}
// create index for children
for (DocumentTree tree : this->children)
- tree.create_index ();
+ tree.create_index (destdir);
}
}