+ tree.create_tree_html (tpl, 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 and not symlink
+ else if (fsitem.is_regular_file () && !fsitem.is_symlink()) {
+ // if it is an index file (specially named as index
+ // or index.md or whatever) directly add
+ // the contents to the summary of the Doctree
+ if (fsitem.path().stem().string() == "index")
+ {
+ std::string infilestr = load_from_file (fsitem.path ());
+ this->set_markdown_summary (infilestr);
+ }
+ // else it is a non-index file-
+ // create a Document and add it to the tree
+ else {
+ std::ifstream infile (fsitem.path ());
+ std::shared_ptr<Document> doc
+ (new Document (infile));
+ infile.close ();
+
+ // file modified date from system
+ struct stat buf;
+ if (stat (fsitem.path().string().c_str(), &buf) == 0)
+ doc.get()->set_modified_date (buf.st_mtim.tv_sec);
+
+ this->add_document (doc.get());
+ }
+ }
+ }
+ }
+ catch (std::filesystem::filesystem_error) {
+ std::cout << NO_SUCH_PATH_ERROR << std::endl;
+ }
+
+ // add the trees for the children recursively
+ for (DocumentTree &child : this->children)
+ child.document_tree_builder (srcpath_str + "/" + child.title);