#include "biawebutil.hpp"
#include "biawebsidebar.hpp"
#include "biawebstrings.hpp"
+#include "biawebnavigationbit.hpp"
// class to represent a biaweb document which can have a file name, title, description,
// keywords, content and sidebar items
std::string meta_desc;
std::string meta_keywords;
std::string content;
- std::list<SideBar> sidebars;
+ std::list<SideBar> sidebars;
+ NavigationBit navbit;
std::time_t cdate;
std::time_t mdate;
bool is_index;
// fourth line onwards: Markdown contents
Document (std::istream &file) ;
+ // set the navigation bit
+ void set_navigation_bit (NavigationBit navbit) {
+ this->navbit = navbit;
+ }
+
// set whether this is the index document
void set_index (bool index = true) {
this->is_index = index;
sidebartext += bar.to_html (templatedir);
}
+ // render the navigation bit
+ std::string navbit_str = this->navbit.to_html (templatedir);
+
// time of creation and modification
struct std::tm c, m;
c = *std::localtime (&this->cdate);
fmt::arg ("description", this->meta_desc),
fmt::arg ("cdate", c),
fmt::arg ("mdate", m),
+ fmt::arg ("navbit", navbit_str),
fmt::arg ("contents", this->content),
fmt::arg ("sidebar", sidebartext)
);
// 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");
+ GenericLinkItem item0;
+ bar1.get()->set_title (NAVIGATE);
+ item0.set_item_text (INDEX);
+ item0.set_item_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");
+ GenericLinkItem item1;
+ item1.set_item_text (GO_UP);
+ item1.set_item_url (this->stub_hierarchy() + "index.html");
bar1.get()->add_sidebar_item (item1);
}
index.get()->add_side_bar (*bar1.get());
// 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 +
+ GenericLinkItem item (tree.get_title(), urlpath +
tree.stub + "/" + "index.html");
bar2.get()->add_sidebar_item (item);
}
// sort the documents as per creation time and then add the document
// links - newest documents should appear above older ones.
sort_documents_creation_time ();
+
+ // create the navigation bit
+ std::shared_ptr<NavigationBit> navbit (new NavigationBit ());
+ auto par1 = this;
+ // get the link to each level in the hierarchy and add it as
+ // an inline list
+ while (par1 != nullptr) {
+ if (par1->parent != nullptr)
+ navbit.get()->add_link_item (GenericLinkItem(par1->stub,
+ par1->stub_hierarchy() + par1->stub + "/index.html"));
+ else
+ navbit.get()->add_link_item (GenericLinkItem(HOME, "index.html"));
+ par1 = par1->parent;
+ }
+
for (Document doc : this->docs) {
DocListItem item (doc.get_title(),
urlpath + doc.get_filename() + ".html",
doc.get_creation_date(), doc.get_modified_date ());
article_list.get()->add_document_item (item);
- // output the document also, add the side bars
+ // output the document also, add the navigation bit and side bars
+
+ doc.set_navigation_bit (*navbit.get());
doc.add_side_bar (*bar1.get());
doc.add_side_bar (*bar2.get());
doc.output_to_html (templatedir, filepath);
}
+
+ // 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(templatedir));
--- /dev/null
+#ifndef __BIAWEBNAVIGATIONBIT__
+#define __BIAWEBNAVIGATIONBIT__
+
+#include <list>
+#include <fstream>
+#include <fmt/format.h>
+#include "biawebutil.hpp"
+#include "biawebsidebar.hpp"
+
+namespace biaweb {
+ // class to represent a navigation bit like this in html
+ // > Parent > Child > Subchild
+ // etc.
+ class NavigationBit {
+ protected:
+ std::list<GenericLinkItem> items;
+ public:
+ // add a generic link item - this should add to beginning of the list
+ void add_link_item (GenericLinkItem item) {
+ items.insert (items.cbegin(), item);
+ }
+
+ // render using the given template directory
+ std::string to_html (std::string templatedir) ;
+ };
+
+ // render using the given template
+ std::string NavigationBit::to_html (std::string templatedir) {
+ std::ifstream templ (templatedir + "/navigationbit.tpl.html");
+ std::string templ_str ((std::istreambuf_iterator<char> (templ)),
+ (std::istreambuf_iterator<char> ()));
+
+
+ std::string output_html = "";
+ std::string items_str = "";
+ for (GenericLinkItem item : this->items)
+ items_str += item.to_html (templatedir);
+
+ if (this->items.size () > 0)
+ output_html = fmt::format (templ_str, fmt::arg ("items", items_str));
+
+ return output_html;
+ }
+}
+
+#endif
\ No newline at end of file
#include <fmt/format.h>
#include "biawebutil.hpp"
-// classes to describe the a list of items and sidebar item containers which form part of
+// classes to describe the a list of (link) items and sidebar containers which form part of
// main document
namespace biaweb {
- // class to represent a sidebar item which can contain a text and link or only
+ // class to represent a generic link item which can contain a text and link or only
// text
- class SideBarItem {
+ class GenericLinkItem {
protected:
// sidebar text and url
- std::string sidebar_text;
- std::string sidebar_url;
+ std::string itemtext;
+ std::string itemurl;
public:
- std::string get_sidebar_text () {
- return this->sidebar_text;
+ std::string get_item_text () {
+ return this->itemtext;
}
- void set_sidebar_text (std::string text) {
- this->sidebar_text = escape_html (text);
+ void set_item_text (std::string text) {
+ this->itemtext = escape_html (text);
}
- std::string get_sidebar_url () {
- return this->sidebar_url;
+ std::string get_item_url () {
+ return this->itemurl;
}
- void set_sidebar_url (std::string url) {
- this->sidebar_url = escape_html (url);
+ void set_item_url (std::string url) {
+ this->itemurl = escape_html (url);
}
// output to HTML using a template directory specified
std::string to_html (std::string templatedir);
- SideBarItem (std::string text = "", std::string url = "") {
- this->sidebar_text = escape_html (text);
- this->sidebar_url = escape_html (url);
+ GenericLinkItem (std::string text = "", std::string url = "") {
+ this->itemtext = escape_html (text);
+ this->itemurl = escape_html (url);
}
};
- std::string SideBarItem::to_html (std::string templatedir) {
- std::string html;
+ std::string GenericLinkItem::to_html (std::string templatedir) {
+ std::string html = "";
// if url is not empty it is a link item so load the sidebar link template
- if (! this->sidebar_url.empty ()) {
- if (!this->sidebar_text.empty ())
+ if (! this->itemurl.empty ()) {
+ if (!this->itemtext.empty ())
{
- std::ifstream tpl_linkitem (templatedir + "/sidebarlinkitem.tpl.html");
+ std::ifstream tpl_linkitem (templatedir + "/genericlinklistitem.tpl.html");
+
std::string tpl_linkitem_str ( (std::istreambuf_iterator<char> (tpl_linkitem)),
(std::istreambuf_iterator<char> ()));
tpl_linkitem.close ();
html = fmt::format (tpl_linkitem_str,
- fmt::arg ("itemurl", this->sidebar_url),
- fmt::arg ("itemtext", this->sidebar_text));
+ fmt::arg ("itemurl", this->itemurl),
+ fmt::arg ("itemtext", this->itemtext));
}
- // no text or url - item is empty - so it should be blank
- else
- html = "";
}
// Non link item. Load the normal sidebar item template.
- else
+ else if (! this->itemtext.empty ())
{
- std::ifstream tpl_item (templatedir + "/sidebaritem.tpl.html");
+ std::ifstream tpl_item (templatedir + "/genericlistitem.tpl.html");
+
std::string tpl_item_str ( (std::istreambuf_iterator<char> (tpl_item)),
(std::istreambuf_iterator<char> ()));
tpl_item.close ();
- html = fmt::format (tpl_item_str, fmt::arg ("itemtext", this->sidebar_text) );
+ html = fmt::format (tpl_item_str, fmt::arg ("itemtext", this->itemtext) );
}
return html;
}
class SideBar {
protected:
std::string sidebar_title;
- std::list <SideBarItem> items;
+ std::list <GenericLinkItem> items;
public:
void set_title (std::string title) {
this->sidebar_title = title;
}
- void add_sidebar_item (SideBarItem item) {
+ void add_sidebar_item (GenericLinkItem item) {
this->items.insert (this->items.cend(), item);
}
sidetpl.close ();
std::string listitems;
// first get the sidebar items and render them to HTML
- for (SideBarItem item : this->items) {
+ for (GenericLinkItem item : this->items) {
listitems += item.to_html (templatedir);
}
const char* SUB_CAT = "Sub categories: ";
const char* ART_LIST = "List of Articles";
const char* INDEX = "Index Page";
+ const char* NAVIGATE = "Navigation";
const char* WARNING_PARSE_FAILED = "Warning: date parse failed on " ;
+ const char* HOME = "Home";
// DATE FORMAT
const char* DATE_IN_FORMAT = "%Y-%m-%d %H:%M %Z";
}
doc = mkd_string (str.c_str(), str.size(), 0);
char tempfile[20];
strcpy (tempfile, "/tmp/biawebXXXXXX");
- mkstemp (tempfile);
- FILE *f = fopen (tempfile, "w");
+ int fd = mkstemp (tempfile);
+ FILE *f = fdopen (fd, "w");
markdown (doc, f, 0);
fclose (f);
std::ifstream ftmp (tempfile);
);
ftmp.close ();
mkd_cleanup (doc);
+ remove (tempfile);
return tmpl;
}
--- /dev/null
+<li><a href="{itemurl}">{itemtext}</a></li>
\ No newline at end of file
--- /dev/null
+<li>{itemtext}</li>
\ No newline at end of file
</style>
</head>
<body>
- <div id="header"></div>
- <div id="content">
+ <header></header>
+ <section id="content">
<div id="modification">Created on: {cdate:%d %b %Y, %H:%M %Z},
last modified: {mdate:%d %b %Y, %H:%M %Z}</div>
+ {navbit}
{contents}
- </div>
- <div id="sidebar">
+ </section>
+ <nav id="sidebar">
{sidebar}
- </div>
- <div id ="footer">
+ </nav>
+ <footer>
My copyright
- </div>
+ </footer>
</body>
</html>
--- /dev/null
+<div id="navbit">
+ →
+ <ul class="inlinelist">
+ {items}
+ </ul>
+</div>
\ No newline at end of file
+++ /dev/null
-<li>{itemtext}</li>
\ No newline at end of file
+++ /dev/null
-<li><a href="{itemurl}">{itemtext}</a></li>
\ No newline at end of file
h1, h2, h3, h4, h5, h6 {
font-family: Georgia, 'Times New Roman', Times, serif;
}
-div#header {
+header {
width: 100%;
color: white;
background-color:#a1a0c0;
height: 50px;
float: left;
}
+
+.inlinelist {
+ display: inline-block;
+ padding: 0em;
+ margin: 0em;
+}
+
+.inlinelist li {
+ display: inline-block;
+ margin-right: 0.9em;
+}
+
div#modification {
width: 100%;
- color: darkslateblue;
- font-size: 0.9em;
+ color:darkgray;
+ font-size: 0.8em;
float:left;
}
-div#footer {
+div#navbit {
+ width: 100%;
+ float: left;
+ font-size: 0.8em;
+}
+footer {
width: 100%;
text-align: center;
background-color: #a1a0c0;
color: white;
float:left;
}
-div#sidebar {
+nav#sidebar {
float :right;
background-color: #f0f0f0;
color: black;
padding: 1%;
}
-div#content {
+section#content {
width: 63%;
margin-right:1%;
margin-left: 1%;