+ tree.create_tree_html (templatedir, destdir);
+ }
+
+ // build a document tree from a filesystem path recursively
+ void DocumentTree::document_tree_builder (std::string srcpath_str) {
+ std::filesystem::path srcpath (srcpath_str);
+ this->title = srcpath.stem().string ();
+
+ // Get the directories to this child and add them as sub document
+ // trees
+ try {
+ for (auto fsitem : std::filesystem::directory_iterator (srcpath) )
+ {
+ // if it is a directory then build the tree for that directory
+ if (fsitem.is_directory ()) {
+ std::shared_ptr <DocumentTree> doctree
+ (new DocumentTree (fsitem.path().filename().string()));
+
+ this->add_child (doctree.get());
+ }
+ // add the regular files as documents in the tree
+ else if (fsitem.is_regular_file ()) {
+ // read the contents of the file
+ std::ifstream infile (fsitem.path().string());
+ std::string infilestr ((std::istreambuf_iterator<char> (infile)),
+ (std::istreambuf_iterator<char> ()));
+ // if it is an index file (specially named index) add
+ // the contents to the summary of the Doctree
+ if (fsitem.path().stem().string() == "index")
+ {
+ this->set_markdown_summary (infilestr);
+ }
+ // else it is a non-index file-
+ // create a Document and add it to the tree
+ else {
+ std::shared_ptr<Document> doc
+ (new Document (fsitem.path().stem().string()));
+
+ // file creation/modified date from system
+ struct stat buf;
+ if (stat (fsitem.path().string().c_str(), &buf) == 0)
+ {
+ doc.get()->set_creation_date (buf.st_ctim.tv_sec);
+ doc.get()->set_modified_date (buf.st_mtim.tv_sec);
+ }
+ doc.get()->set_markdown_content (infilestr);
+
+ this->add_document (doc.get());
+ }
+ }
+ }
+ }
+ catch (std::filesystem::filesystem_error) {
+ std::cout << "No such path! Specify an existing file path" << std::endl;
+ }
+
+ // add the trees for the children recursively
+ for (DocumentTree &child : this->children)
+ child.document_tree_builder (srcpath_str + "/" + child.title);