+ // Parse and construct a document from a stream instead of individual fields
+ Document::Document (std::istream &infile) {
+ infile.seekg (0);
+ // parse the title, description, keywords, creation time and and contents
+ std::string title, description, keywords, creattime, contents;
+ // read the title
+ std::getline (infile, title);
+ if (infile.eof ()) return;
+ this->title = escape_html (title);
+ this->filename = convert_title (title);
+ // read description
+ std::getline (infile, description);
+ if (infile.eof ()) return;
+ this->meta_desc = escape_html (description);
+ // read the keywords
+ std::getline (infile, keywords);
+ if (infile.eof ()) return;
+ this->meta_keywords = escape_html (keywords);
+ // read the creation date/time and also set the modification time
+ // to creation date/time by default
+ std::getline (infile, creattime);
+ if (infile.eof ()) return;
+ std::stringstream s (creattime);
+ std::tm t;
+ s >> std::get_time (&t, DATE_IN_FORMAT);
+ if (s.fail ())
+ std::cout << WARNING_PARSE_FAILED << this->filename << "\n";
+
+ this->cdate = mktime (&t);
+ this->mdate = this->cdate;
+ // read the rest of contents
+ std::string line;
+ while (! infile.eof ()) {
+ std::getline (infile, line);
+ contents.append (line + "\n");
+ }
+ this->set_markdown_content (contents);
+ }
+