Support for <meta> attributes
This commit is contained in:
4
build.sh
4
build.sh
@@ -1,7 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
bin2cpp --file=client/header_top.html --output=server/src/generated
|
||||||
|
bin2cpp --file=client/header_bottom.html --output=server/src/generated
|
||||||
|
|
||||||
bin2cpp --file=client/footer.html --output=server/src/generated
|
bin2cpp --file=client/footer.html --output=server/src/generated
|
||||||
bin2cpp --file=client/header.html --output=server/src/generated
|
|
||||||
bin2cpp --file=client/e404.html --output=server/src/generated
|
bin2cpp --file=client/e404.html --output=server/src/generated
|
||||||
bin2cpp --file=client/style.css --output=server/src/generated
|
bin2cpp --file=client/style.css --output=server/src/generated
|
||||||
bin2cpp --file=client/script.js --output=server/src/generated
|
bin2cpp --file=client/script.js --output=server/src/generated
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>posts</title>
|
|
||||||
<link rel="stylesheet" type="text/css" href="/style.css">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<script src="/script.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="postbox">
|
<div class="postbox">
|
||||||
7
client/header_top.html
Normal file
7
client/header_top.html
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>posts</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/style.css">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<script src="/script.js"></script>
|
||||||
@@ -5,7 +5,8 @@ sources = [
|
|||||||
'src/post.cpp',
|
'src/post.cpp',
|
||||||
'src/db.cpp',
|
'src/db.cpp',
|
||||||
'src/generated/e404.cpp',
|
'src/generated/e404.cpp',
|
||||||
'src/generated/header.cpp',
|
'src/generated/header_top.cpp',
|
||||||
|
'src/generated/header_bottom.cpp',
|
||||||
'src/generated/footer.cpp',
|
'src/generated/footer.cpp',
|
||||||
'src/generated/style.cpp',
|
'src/generated/style.cpp',
|
||||||
'src/generated/script.cpp',
|
'src/generated/script.cpp',
|
||||||
|
|||||||
@@ -12,19 +12,22 @@
|
|||||||
#include "post.h"
|
#include "post.h"
|
||||||
|
|
||||||
#include "generated/e404.h"
|
#include "generated/e404.h"
|
||||||
#include "generated/header.h"
|
#include "generated/header_top.h"
|
||||||
|
#include "generated/header_bottom.h"
|
||||||
#include "generated/footer.h"
|
#include "generated/footer.h"
|
||||||
#include "generated/style.h"
|
#include "generated/style.h"
|
||||||
#include "generated/script.h"
|
#include "generated/script.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
const bin2cpp::File& headerfile = bin2cpp::getHeaderHtmlFile();
|
const bin2cpp::File& headerTopFile = bin2cpp::getHeader_topHtmlFile();
|
||||||
|
const bin2cpp::File& headerBottomFile = bin2cpp::getHeader_bottomHtmlFile();
|
||||||
const bin2cpp::File& footerfile = bin2cpp::getFooterHtmlFile();
|
const bin2cpp::File& footerfile = bin2cpp::getFooterHtmlFile();
|
||||||
const bin2cpp::File& e404file = bin2cpp::getE404HtmlFile();
|
const bin2cpp::File& e404file = bin2cpp::getE404HtmlFile();
|
||||||
const bin2cpp::File& stylefile = bin2cpp::getStyleCssFile();
|
const bin2cpp::File& stylefile = bin2cpp::getStyleCssFile();
|
||||||
const bin2cpp::File& scriptfile = bin2cpp::getScriptJsFile();
|
const bin2cpp::File& scriptfile = bin2cpp::getScriptJsFile();
|
||||||
|
|
||||||
std::string header{headerfile.getBuffer(), headerfile.getSize()};
|
std::string headerTop{headerTopFile.getBuffer(), headerTopFile.getSize()};
|
||||||
|
std::string headerBottom{headerBottomFile.getBuffer(), headerBottomFile.getSize()};
|
||||||
std::string footer{footerfile.getBuffer(), footerfile.getSize()};
|
std::string footer{footerfile.getBuffer(), footerfile.getSize()};
|
||||||
std::string e404{e404file.getBuffer(), e404file.getSize()};
|
std::string e404{e404file.getBuffer(), e404file.getSize()};
|
||||||
std::string style{stylefile.getBuffer(), stylefile.getSize()};
|
std::string style{stylefile.getBuffer(), stylefile.getSize()};
|
||||||
@@ -44,10 +47,10 @@ int main() {
|
|||||||
response.set_content(script, "text/css");
|
response.set_content(script, "text/css");
|
||||||
});
|
});
|
||||||
|
|
||||||
svr.Get("/", [&header, &footer, &database, &data_mutex](const httplib::Request& request, httplib::Response& response) {
|
svr.Get("/", [&headerTop, &headerBottom, &footer, &database, &data_mutex](const httplib::Request& request, httplib::Response& response) {
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << header;
|
ss << headerTop << "<meta content='Chookchat' property='og:title' /><meta content='See posts from cool people' property='og:description' />" << headerBottom;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(data_mutex);
|
std::lock_guard<std::mutex> lock(data_mutex);
|
||||||
|
|
||||||
@@ -68,7 +71,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
svr.Get("/posts/:id", [&header, &footer, &e404, &database, &data_mutex](const httplib::Request& request, httplib::Response& response) {
|
svr.Get("/posts/:id", [&headerTop, &headerBottom, &footer, &e404, &database, &data_mutex](const httplib::Request& request, httplib::Response& response) {
|
||||||
std::string postId = request.path_params.at("id");
|
std::string postId = request.path_params.at("id");
|
||||||
try {
|
try {
|
||||||
uint64_t postIdNum = std::stoll(postId);
|
uint64_t postIdNum = std::stoll(postId);
|
||||||
@@ -81,7 +84,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << header << post->genHtml() << footer;
|
ss << headerTop << post->genHtmlMeta() << headerBottom << post->genHtml() << footer;
|
||||||
response.set_content(ss.str(), "text/html");
|
response.set_content(ss.str(), "text/html");
|
||||||
} catch (const std::runtime_error& e) {
|
} catch (const std::runtime_error& e) {
|
||||||
response.status = 500;
|
response.status = 500;
|
||||||
|
|||||||
@@ -60,3 +60,14 @@ std::string Post::genHtml() const {
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::regex tags("<[^<]*>");
|
||||||
|
|
||||||
|
std::string Post::genHtmlMeta() const {
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
ss << "<meta content='" << user << " on Chookchat' property='og:title' />";
|
||||||
|
ss << "<meta content='" << std::regex_replace(content, tags, "") << "' property='og:description' />";
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ struct Post {
|
|||||||
uint64_t userId = 0;
|
uint64_t userId = 0;
|
||||||
|
|
||||||
std::string genHtml() const;
|
std::string genHtml() const;
|
||||||
|
std::string genHtmlMeta() const;
|
||||||
|
|
||||||
Post(std::string contentin, const std::string& user);
|
Post(std::string contentin, const std::string& user);
|
||||||
Post(std::string contentin, uint64_t user);
|
Post(std::string contentin, uint64_t user);
|
||||||
|
|||||||
Reference in New Issue
Block a user