From 802d0b0599093a6c5b30f946cd45c9ed7ebd4833 Mon Sep 17 00:00:00 2001 From: Harishankar Date: Thu, 21 May 2020 20:37:30 +0530 Subject: [PATCH] Added some template changes - Document List now shows description The document list now shows the brief description below the link in the generate HTML --- biaweb.cpp | 77 ++++------------------------------ biawebdoclist.hpp | 15 ++++++- biawebdocumenttree.hpp | 3 +- biawebstrings.hpp | 1 + templates/doclist.tpl.html | 6 +-- templates/doclistitem.tpl.html | 2 +- templates/style.tpl.css | 19 ++++++++- 7 files changed, 46 insertions(+), 77 deletions(-) diff --git a/biaweb.cpp b/biaweb.cpp index 2ed34fb..f720fe0 100644 --- a/biaweb.cpp +++ b/biaweb.cpp @@ -4,79 +4,18 @@ using namespace biaweb; int main (int argc, char *argv[]) { - -// if (argc == 2) -// { -// std::shared_ptr tree (new DocumentTree (argv[1])); -// tree.get()->set_stub (""); -// tree.get()->set_markdown_summary ("# Hello there\n\n\ -// These are some contents for this page."); - -// std::shared_ptr a1 (new DocumentTree("Child a1")); -// std::shared_ptr a2 (new DocumentTree("Child a2")); -// std::shared_ptr a3 (new DocumentTree("Child a3")); -// std::shared_ptr a4 (new DocumentTree("Child a4")); -// std::shared_ptr d2 (new Document ("Another document")); -// d2.get()->set_creation_date (124012); -// std::shared_ptr d1 (new Document("Test Document")); -// d1.get()->set_creation_date (100000); -// d1.get()->set_markdown_content ("# Heading \n\nThis is some text, hello world"); -// d2.get()->set_markdown_content ("Some document \n\nThis is some document"); -// a1.get()->add_document (d2.get()); -// 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_tree_html ("/home/hari/Projects/BiaWeb2/templates", -// convert_title (argv[1])); -// } -// // else { -// // std::cout << "Usage: " << argv[0] << "
" << std::endl; - + // Compute the speed of generating the document tree and output HTML from sources std::chrono::steady_clock::time_point t1 (std::chrono::steady_clock::now()); - DocumentTree tree (""); - tree.document_tree_builder ("Test/Reviews"); - tree.visualize_tree (); + + // An empty document tree + std::unique_ptr tree (new DocumentTree ("")); + tree.get()->document_tree_builder ("Test/Reviews"); + tree.get()->visualize_tree (); Template tpl ("templates"); - tree.create_tree_html (&tpl, "Test/Out"); + tree.get()->create_tree_html (&tpl, "Test/Out"); std::chrono::steady_clock::time_point t2 (std::chrono::steady_clock::now()); std::chrono::duration dur (t2 - t1); - std::cout << dur.count () << std::endl; - -// // } - - // Document doc; - // SideBar items; - // std::string title, contents, sidetitle; - // std::cout << "Enter document title: "; - // std::getline (std::cin, title); - // std::cout << "Enter markdown file of document: "; - // std::getline (std::cin, contents); - // while (1) { - // std::string name, url; - // std::cout << "Enter a sidebar item text (empty to end): "; - // std::getline (std::cin, name); - // if (name.empty()) break; - // std::cout << "Enter a sidebar item URL: "; - // std::getline (std::cin, url); - // SideBarItem item (name, url); - // items.add_sidebar_item (item); - // } - // std::cout << "Enter heading for sidebar: "; - // std::getline (std::cin, sidetitle); - // items.set_title (sidetitle); - // doc.set_title (title); - // std::ifstream f (contents); - // std::string markdown_contents ( (std::istreambuf_iterator (f)), - // (std::istreambuf_iterator ()) ); - - // doc.set_markdown_content (markdown_contents); - // doc.add_side_bar (items); - - // doc.output_to_html (); + std::cout << GENERATED_IN << dur.count () << std::endl; return 0; } diff --git a/biawebdoclist.hpp b/biawebdoclist.hpp index 8a92cdd..5922303 100644 --- a/biawebdoclist.hpp +++ b/biawebdoclist.hpp @@ -20,15 +20,25 @@ namespace biaweb { // Just the required fields to build the item std::string title; std::string url; + std::string desc; std::time_t ctime; std::time_t mtime; public: DocListItem (std::string title, std::string url, - std::time_t ctime, std::time_t mtime ) { + std::time_t ctime, std::time_t mtime, std::string desc ) { this->title = escape_html (title); this->url = url; this->ctime = ctime; this->mtime = mtime; + this->desc = desc; + } + + std::string get_desc () { + return this->desc; + } + + void set_desc (std::string desc) { + this->desc = escape_html (desc); } std::time_t get_mtime() { @@ -71,7 +81,8 @@ namespace biaweb { m = *std::localtime (&this->mtime); std::string outputhtml = fmt::format (templstr, fmt::arg("url", this->url), - fmt::arg("doctitle", this->title), + fmt::arg("doctitle", this->title), + fmt::arg("desc", this->desc), fmt::arg("cdate", c), fmt::arg("mdate", m)); diff --git a/biawebdocumenttree.hpp b/biawebdocumenttree.hpp index e1e6401..70471f3 100644 --- a/biawebdocumenttree.hpp +++ b/biawebdocumenttree.hpp @@ -238,7 +238,8 @@ namespace biaweb { for (Document doc : this->docs) { DocListItem item (doc.get_title(), urlpath + doc.get_filename() + ".html", - doc.get_creation_date(), doc.get_modified_date ()); + doc.get_creation_date(), doc.get_modified_date (), + doc.get_meta_desc()); article_list.get()->add_document_item (item); // output the document also, add the navigation bit and side bars diff --git a/biawebstrings.hpp b/biawebstrings.hpp index c87f882..970fede 100644 --- a/biawebstrings.hpp +++ b/biawebstrings.hpp @@ -6,6 +6,7 @@ namespace biaweb { const char* WARNING_PARSE_FAILED = "Warning: date parse failed on " ; const char* NO_SUCH_PATH_ERROR = "No such path! Specify an existing file path" ; const char* DATE_IN_FORMAT = "%Y-%m-%d %H:%M %Z"; + const char* GENERATED_IN = "Generated in (s): "; // NAMED INDEX FOR DOCUMENT STRING BITS (LOADED FROM TEMPLATE FILE stringbits.txt) const unsigned int HOME = 0; diff --git a/templates/doclist.tpl.html b/templates/doclist.tpl.html index 206c4ac..f9b8a99 100644 --- a/templates/doclist.tpl.html +++ b/templates/doclist.tpl.html @@ -1,8 +1,8 @@

{title}

- - +
+ - + diff --git a/templates/doclistitem.tpl.html b/templates/doclistitem.tpl.html index 3a17d80..550303c 100644 --- a/templates/doclistitem.tpl.html +++ b/templates/doclistitem.tpl.html @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/templates/style.tpl.css b/templates/style.tpl.css index d1688ca..2f9d6b5 100644 --- a/templates/style.tpl.css +++ b/templates/style.tpl.css @@ -5,7 +5,8 @@ body { font-size: 0.9em; margin: 0; padding: 0; -} +} + h1, h2, h3, h4, h5, h6 { font-family: Georgia, 'Times New Roman', Times, serif; } @@ -16,6 +17,22 @@ header { float: left; text-align: center; } +.doclisttable { + width: 100%; + text-align: left; +} + +.doclisttable thead { + font-weight: bold; +} + +.doclisttable tbody { + color: #3f3f3f; +} + +.doclisttable td { + padding:0.2em; +} .inlinelist { display: inline-block; -- 2.20.1
Document titleDocument title Created on Last modified
{doctitle}{doctitle}
{desc}
{cdate:%d %b %Y, %H:%M %Z} {mdate:%d %b %Y, %H:%M %Z}