Document tree generation to HTML output completed
authorHarishankar <v.harishankar@gmail.com>
Sat, 16 May 2020 15:15:00 +0000 (20:45 +0530)
committerHarishankar <v.harishankar@gmail.com>
Sat, 16 May 2020 15:15:00 +0000 (20:45 +0530)
Completed the document tree generation - now the tree is created
along with all children and also the documents in the tree

biaweb.cpp
biawebdocument.hpp
biawebdocumenttree.hpp
biawebsidebar.hpp
biawebstrings.hpp
templates/main.tpl.html

index 0d9a3e8..b1c827b 100644 (file)
@@ -14,13 +14,17 @@ int main (int argc, char *argv[]) {
         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<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 ();
         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;
     }
     else
         std::cout << "Usage: " << argv[0] << " <main tree>" << std::endl;
index f001373..0c0b74c 100644 (file)
@@ -41,7 +41,7 @@ namespace biaweb {
             this->meta_keywords = meta_keywords;
             this->content = content;
             this->is_index = is_index;
             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";
                 this->filename = convert_title (title);
             else 
                 this->filename = "index";
@@ -52,6 +52,8 @@ namespace biaweb {
         // set whether this is the index document
         void set_index (bool index = true) {
             this->is_index = 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
         }
 
         // get whether this is the index document
@@ -59,6 +61,11 @@ namespace biaweb {
             return this->is_index;
         }
 
             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;
         // set the document modification date
         void set_modified_date (std::time_t modif) {
             this->mdate = modif;
index 41aa81a..cf75c86 100644 (file)
@@ -41,7 +41,7 @@ namespace biaweb {
         }
 
         // create the document index for this tree
         }
 
         // 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) {
 
         // set the title 
         void set_title (std::string title) {
@@ -131,8 +131,9 @@ namespace biaweb {
                 child.visualize_tree ();
     }
 
                 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
         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 += "/";
 
         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");
         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);
 
         // 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)
 
         // create index for children
         for (DocumentTree tree : this->children)
-            tree.create_index (destdir);
+            tree.create_tree_html (destdir);
     }
 }
 
     }
 }
 
index 5b73b75..75761da 100644 (file)
@@ -6,7 +6,7 @@
 #include <fstream>
 #include "biawebutil.hpp"
 
 #include <fstream>
 #include "biawebutil.hpp"
 
-// classes to describe the sidebar and sidebar item containers which form part of 
+// classes to describe the a list of items and sidebar item containers which form part of 
 // main document
 namespace biaweb {
     // class to represent a sidebar item which can contain a text and link or only
 // main document
 namespace biaweb {
     // class to represent a sidebar item which can contain a text and link or only
index 8e2f947..df9af51 100644 (file)
@@ -4,6 +4,8 @@
 namespace biaweb {
     const char* GO_UP = "Go up";
     const char* SUB_CAT = "Sub categories: ";
 namespace biaweb {
     const char* GO_UP = "Go up";
     const char* SUB_CAT = "Sub categories: ";
+    const char* ART_LIST = "List of Articles";
+    const char* INDEX = "Index Page";
 }
 
 #endif
 }
 
 #endif
index 0bdf62f..b506bc9 100644 (file)
@@ -40,7 +40,7 @@
         width: 32%;
         padding: 1%;
     }
         width: 32%;
         padding: 1%;
     }
-    div#sidebar a, a:visited {
+    div#sidebar a, div#sidebar a:visited {
         color: white;
     }
     div#main {
         color: white;
     }
     div#main {