Document tree generation to HTML output completed
[biaweb2.git] / biawebdocumenttree.hpp
index 41aa81a..cf75c86 100644 (file)
@@ -41,7 +41,7 @@ namespace biaweb {
         }
 
         // 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) {
@@ -131,8 +131,9 @@ namespace biaweb {
                 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
@@ -145,26 +146,63 @@ namespace biaweb {
         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);
     }
 }