#include "post.h" #include #include #include #include #include Post::Post(const std::string& contentin, const std::string& user) : user(user), time(std::time(nullptr)) { // parse the post content markdown std::stringstream input(contentin); std::shared_ptr parser = std::make_shared(); content = parser->Parse(input); } Post::Post(const std::string& contentin, uint64_t user) : userId(user), time(std::time(nullptr)) { // parse the post content markdown std::stringstream input(contentin); std::shared_ptr parser = std::make_shared(); content = parser->Parse(input); } std::string Post::genHtml() const { std::stringstream ss; ss << "
\n"; // do time char buf[256]; struct tm ts; ts = *localtime(&time); strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", &ts); ss << "

" << user << " posted this at " << buf << "

\n"; ss << content; ss << "

" << likes << " likes

"; return ss.str(); }