From: Harishankar Date: Sat, 23 May 2020 14:50:04 +0000 (+0530) Subject: Refactored DocListItem to take Document in constructor X-Git-Url: https://harishankar.org/repos/?a=commitdiff_plain;h=bfdbd4a6df9232fb6b7f7754903584167b620fe4;p=biaweb2.git Refactored DocListItem to take Document in constructor Refactored DocListItem class to take Document in the constructor instead of individual fields. Also fixed minor issue in link in feed.xml link in DocumentTree generation. --- diff --git a/biawebdoclist.hpp b/biawebdoclist.hpp index 5922303..8995c3c 100644 --- a/biawebdoclist.hpp +++ b/biawebdoclist.hpp @@ -24,50 +24,33 @@ namespace biaweb { 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::string desc ) { - this->title = escape_html (title); - this->url = url; - this->ctime = ctime; - this->mtime = mtime; - this->desc = desc; + DocListItem (Document *doc, std::string urlpath) { + this->title = doc->get_title (); + this->url = urlpath + doc->get_filename() + ".html"; + this->ctime = doc->get_creation_date (); + this->mtime = doc->get_modified_date (); + this->desc = doc->get_meta_desc (); } std::string get_desc () { return this->desc; } - void set_desc (std::string desc) { - this->desc = escape_html (desc); - } - std::time_t get_mtime() { return this->mtime; } - void set_mtime(std::time_t mtime) { - this->mtime = mtime; - } + std::time_t get_ctime() { return this->ctime; } - void set_ctime(std::time_t ctime) { - this->ctime = ctime; - } std::string get_url() { return this->url; } - void set_url(std::string url) { - this->url = url; - } - std::string get_title() { return this->title; } - void set_title(std::string title) { - this->title = escape_html (title); - } // output to HTML vide the template std::string to_html (Template *t); @@ -96,7 +79,7 @@ namespace biaweb { std::list items; public: void set_title (std::string title) { - this->title = escape_html (title); + this->title = title; } // add a document item void add_document_item (DocListItem docitem) { diff --git a/biawebdocumenttree.hpp b/biawebdocumenttree.hpp index 53023f1..0aba119 100644 --- a/biawebdocumenttree.hpp +++ b/biawebdocumenttree.hpp @@ -248,11 +248,8 @@ namespace biaweb { // If the items don't exceed max size of RSS feed if (feed.get()->get_num_items() <= MAX_RSS_FEED) feed.get()->add_rss_item (fitem); - // Add the document to the document list - DocListItem item (doc.get_title(), - urlpath + doc.get_filename() + ".html", - doc.get_creation_date(), doc.get_modified_date (), - doc.get_meta_desc()); + // Add the document details to the document list + DocListItem item (&doc, urlpath); article_list.get()->add_document_item (item); // output the document also, add the navigation bit and side bars @@ -275,14 +272,17 @@ namespace biaweb { std::unique_ptr bar3 (new SideBar ()); bar3.get()->set_title (tpl->get_stringbit (SUBSCRIBE)); bar3.get()->add_sidebar_item ( - GenericLinkItem (tpl->get_stringbit(RSS_FEED), urlpath + "/feed.xml")); + GenericLinkItem (tpl->get_stringbit(RSS_FEED), urlpath + "feed.xml")); index.get()->add_side_bar (*bar3.get()); } // add the navigation bit index.get()->set_navigation_bit (*navbit.get()); - // index should contain the summary followed by the article list - index.get()->set_content (this->summary + article_list.get()->to_html(tpl)); + // index should contain the summary followed by the the article list + // and the sub categories + index.get()->set_content (this->summary + + article_list.get()->to_html(tpl) + + bar2.get()->to_html (tpl)); // output the index file index.get()->output_to_html (tpl, filepath);