Included functionality to describe the document in the input file
[biaweb2.git] / biawebdocumenttree.hpp
index 66dcd9f..c58a534 100644 (file)
@@ -163,6 +163,7 @@ namespace biaweb {
     // create the tree - the index file for this tree and all the documents and
     // the child trees recursively - using the template specified
     void DocumentTree::create_tree_html (std::string templatedir, std::string destdir) {
+        // create a document to represent the index of the tree.
         std::unique_ptr<Document> index (new Document (this->title));
         index.get()->set_index ();
         // set the file name path
@@ -227,6 +228,7 @@ namespace biaweb {
         // index should contain the summary followed by the article list
         index.get()->set_content (this->summary + article_list.get()->to_html(templatedir));
 
+        // output the index file
         index.get()->output_to_html (templatedir, filepath);
 
         // recursively create index for children
@@ -253,30 +255,28 @@ namespace biaweb {
                 }
                 // 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 
+                    // 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::ifstream infile (fsitem.path());
+                        std::string infilestr ( (std::istreambuf_iterator<char> (infile)),
+                                                (std::istreambuf_iterator<char> ()) );
                         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 (fsitem.path().stem().string()));
+                                (new Document (infile));
+                        infile.close ();
                         
-                        // file creation/modified date from system
+                        // file 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());
                     }