std::shared_ptr<DocumentTree> a2 (new DocumentTree("Child a2"));
std::shared_ptr<DocumentTree> a3 (new DocumentTree("Child a3"));
std::shared_ptr<DocumentTree> a4 (new DocumentTree("Child a4"));
+ std::shared_ptr<Document> d1 (new Document("Test Document", "",
+ ""));
+ d1.get()->set_markdown_content ("# Heading \n\nThis is some text, hello world");
+ a1.get()->add_document (d1.get());
a3.get()->add_child (a4.get());
a1.get()->add_child (a2.get());
a1.get()->add_child (a3.get());
tree.get()->add_child (a1.get());
std::cout << a3.get()->stub_hierarchy () << a3.get()->get_stub () << std::endl;
tree.get()->visualize_tree ();
- tree.get()->create_index (convert_title (argv[1]));
+ tree.get()->create_tree_html (convert_title (argv[1]));
}
else
std::cout << "Usage: " << argv[0] << " <main tree>" << std::endl;
this->meta_keywords = meta_keywords;
this->content = content;
this->is_index = is_index;
- if (is_index)
+ if (! is_index)
this->filename = convert_title (title);
else
this->filename = "index";
// set whether this is the index document
void set_index (bool index = true) {
this->is_index = index;
+ index == true ? this->filename = "index" :
+ this->filename = convert_title (this->title);
}
// get whether this is the index document
return this->is_index;
}
+ // get the file name
+ std::string get_filename () {
+ return this->filename;
+ }
+
// set the document modification date
void set_modified_date (std::time_t modif) {
this->mdate = modif;
}
// create the document index for this tree
- void create_index (std::string destdir);
+ void create_tree_html (std::string destdir);
// set the title
void set_title (std::string title) {
child.visualize_tree ();
}
- // create the tree index - the index file for this tree
- void DocumentTree::create_index (std::string destdir) {
+ // create the tree - the index file for this tree and all the documents and
+ // the child trees recursively
+ void DocumentTree::create_tree_html (std::string destdir) {
std::unique_ptr<Document> index (new Document (this->title));
index.get()->set_index ();
// set the file name path
if (urlpath != "")
urlpath += "/";
- // create the sidebar
- std::unique_ptr<SideBar> bar (new SideBar ());
- bar.get()->set_title (SUB_CAT + this->title);
+ // create the sidebars
+ // First sidebar
+ // Create a link to the index page and
+ // If this tree has a parent, create a sidebar link to the level up
+ std::unique_ptr<SideBar> bar1 (new SideBar());
+ SideBarItem item0;
+ item0.set_sidebar_text (INDEX);
+ item0.set_sidebar_url (urlpath + "index.html");
+ bar1.get()->add_sidebar_item (item0);
+ if (this->get_parent() != nullptr) {
+ SideBarItem item1;
+ item1.set_sidebar_text (GO_UP);
+ item1.set_sidebar_url (this->stub_hierarchy() + "index.html");
+ bar1.get()->add_sidebar_item (item1);
+ }
+ index.get()->add_side_bar (*bar1.get());
+
+ // create a sidebar for the child levels if there are children
+ std::unique_ptr<SideBar> bar2 (new SideBar ());
+ bar2.get()->set_title (SUB_CAT + this->title);
for (DocumentTree tree : this->children) {
// 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);
+ bar2.get()->add_sidebar_item (item);
}
- index.get()->add_side_bar (*bar.get());
+ index.get()->add_side_bar (*bar2.get());
// create the path and then the index file
std::filesystem::create_directories (filepath);
- index->output_to_html (filepath);
+
+ // Create the list of documents in this tree with links
+ // Reuse the sidebar class and sidebaritem class which is
+ // basically a list of links but instead of adding a sidebar
+ // add it to the content portion
+ SideBar article_list;
+ article_list.set_title (this->title + ": " + ART_LIST);
+ for (Document doc : this->docs) {
+ SideBarItem item;
+ item.set_sidebar_text (doc.get_title());
+ item.set_sidebar_url (urlpath + doc.get_filename() + ".html");
+ article_list.add_sidebar_item (item);
+ // output the document also, add the side bars
+ if (this->get_parent() != nullptr)
+ doc.add_side_bar (*bar1.get());
+ doc.add_side_bar (*bar2.get());
+ doc.output_to_html (filepath);
+ }
+ index.get()->set_content (article_list.to_html());
+
+ index.get()->output_to_html (filepath);
// create index for children
for (DocumentTree tree : this->children)
- tree.create_index (destdir);
+ tree.create_tree_html (destdir);
}
}