{
std::shared_ptr<DocumentTree> 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<DocumentTree> a1 (new DocumentTree("Child a1"));
std::shared_ptr<DocumentTree> a2 (new DocumentTree("Child a2"));
};
void Document::set_markdown_content (std::string str) {
- // discount is a C library and it doesn't work well with C++ streams
- // and there seems no way to get the output of any of these functions
- // into an std::string.
- // the only option seems to be to write the output of the markdown()
- // function to a temporary working file and then read it back into C++
- // with the normal std::ifstream and feed it into the std::string
- // till a cleaner solution can be found.
- MMIOT *doc;
- doc = mkd_string (str.c_str(), str.size(), 0);
- FILE *f = fopen (".biaweb.tmp", "w");
- markdown (doc, f, 0);
- fclose (f);
- std::ifstream ftmp (".biaweb.tmp");
- std::string tmpl ( (std::istreambuf_iterator<char> (ftmp)),
- (std::istreambuf_iterator<char> ())
- );
-
- while (! ftmp.eof ())
- {
- std::string line;
- ftmp >> line;
- tmpl.append (line);
- tmpl.append (" ");
- }
- ftmp.close ();
- remove (".biaweb.tmp");
- this->content.append (tmpl);
- mkd_cleanup (doc);
+ this->content = convert_to_markdown (str);
}
void Document::output_to_html (std::string path)
std::list<DocumentTree> children;
// title of this tree
std::string title;
+ // summary for this tree - this is displayed in the index.html file of
+ // this tree before the list of articles in the tree
+ std::string summary;
// file stub of this tree
std::string stub;
// list of documents in this tree
this->parent = nullptr;
}
+ // set the summary for this tree
+ void set_summary (std::string summary) {
+ this->summary = summary;
+ }
+
+ // set the summary for this tree as markdown text
+ void set_markdown_summary (std::string summary) {
+ this->summary = convert_to_markdown (summary);
+ }
+
+ std::string get_summary () {
+ return this->summary;
+ }
+
// create the document index for this tree
void create_tree_html (std::string destdir);
doc.add_side_bar (*bar2.get());
doc.output_to_html (filepath);
}
- index.get()->set_content (article_list.to_html());
+ index.get()->set_content (this->summary + article_list.to_html());
index.get()->output_to_html (filepath);
#ifndef __BIAWEBUTIL__
#define __BIAWEBUTIL__
#include <string>
+// "discount" markdown library is a C library and hence requires to be wrapped in
+// extern "C"
+extern "C" {
+ #include <mkdio.h>
+}
// utility functions for Biaweb that don't fit into any class and can be used by
// any class
namespace biaweb {
+ // convert markdown
+
+ std::string convert_to_markdown (std::string str) {
+ // discount is a C library and it doesn't work well with C++ streams
+ // and there seems no way to get the output of any of these functions
+ // into an std::string.
+ // the only option seems to be to write the output of the markdown()
+ // function to a temporary working file and then read it back into C++
+ // with the normal std::ifstream and feed it into the std::string
+ // till a cleaner solution can be found.
+ MMIOT *doc;
+ doc = mkd_string (str.c_str(), str.size(), 0);
+ FILE *f = fopen (".biaweb.tmp", "w");
+ markdown (doc, f, 0);
+ fclose (f);
+ std::ifstream ftmp (".biaweb.tmp");
+ std::string tmpl ( (std::istreambuf_iterator<char> (ftmp)),
+ (std::istreambuf_iterator<char> ())
+ );
+ ftmp.close ();
+ mkd_cleanup (doc);
+ remove (".biaweb.tmp");
+ return tmpl;
+ }
+
// convert a document title to a file title - strip out the non-alpha
// chars and spaces
std::string convert_title (std::string title)