yay initial commit

This commit is contained in:
2026-07-20 10:57:07 +10:00
commit e1751a3ece
18 changed files with 22476 additions and 0 deletions

40
server/src/post.cpp Normal file
View File

@@ -0,0 +1,40 @@
#include "post.h"
#include <memory>
#include <sstream>
#include <string>
#include <ctime>
#include <maddy/parser.h>
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<maddy::Parser> parser = std::make_shared<maddy::Parser>();
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<maddy::Parser> parser = std::make_shared<maddy::Parser>();
content = parser->Parse(input);
}
std::string Post::genHtml() const {
std::stringstream ss;
ss << "<hr>\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 << "<p><i>" << user << "</i> posted this at " << buf << "</p>\n";
ss << content;
ss << "<p>" << likes << " likes</p>";
return ss.str();
}