From 29c2406c040ebb530ae73cbcf7f560b4849e1811 Mon Sep 17 00:00:00 2001 From: Szymon P Date: Thu, 15 Jan 2026 10:23:14 +0100 Subject: [PATCH 1/2] added blog entry template --- templates/blog_entry.html | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 templates/blog_entry.html diff --git a/templates/blog_entry.html b/templates/blog_entry.html new file mode 100644 index 0000000..1557347 --- /dev/null +++ b/templates/blog_entry.html @@ -0,0 +1,24 @@ + + + + + + {{metadata.title}} + + +
+

{{metadata.title}}

+
+ +
+
+ {{content}} +
+
+ + + + + From 241121b35565b2ddaeb624837b3154e0ef6acbec Mon Sep 17 00:00:00 2001 From: Szymon P Date: Thu, 15 Jan 2026 10:50:34 +0100 Subject: [PATCH 2/2] bunch of random ass shit tbh --- src/builder/builder.cpp | 29 +++++++++++++++----- src/builder/builder.hpp | 9 ++++++ src/tests.cpp | 58 +++++++++++++++++++++++++++++++++++---- templates/blog_entry.html | 9 ++---- templates/footer.html | 2 +- templates/head.html | 2 +- templates/header.html | 2 +- templates/index.html | 10 +++---- 8 files changed, 95 insertions(+), 26 deletions(-) diff --git a/src/builder/builder.cpp b/src/builder/builder.cpp index 8216505..0eafde8 100644 --- a/src/builder/builder.cpp +++ b/src/builder/builder.cpp @@ -5,18 +5,33 @@ std::string build_index(const std::string &TEMPLATE, const Page &PAGE, const Information &INFORMATION) { std::string result = TEMPLATE; - result = format_file(result, "{{lang}}", INFORMATION.config.general.lang); - result = format_file(result, "{{head}}", PAGE.head); - result = format_file(result, "{{header}}", PAGE.header); - result = format_file(result, "{{main}}", PAGE.main); - result = format_file(result, "{{footer}}", PAGE.footer); + result = + format_file(result, "{{config.lang}}", INFORMATION.config.general.lang); + result = format_file(result, "{{page.head}}", PAGE.head); + result = format_file(result, "{{page.header}}", PAGE.header); + result = format_file(result, "{{page.main}}", PAGE.main); + result = format_file(result, "{{page.footer}}", PAGE.footer); + return result; +} + +std::string build_blog_entry(const std::string &TEMPLATE, const Page &BLOG, + const Information &INFORMATION) { + std::string result = TEMPLATE; + result = + format_file(result, "{{config.lang}}", INFORMATION.config.general.lang); + result = format_file(result, "{{page.head}}", BLOG.head); + result = format_file(result, "{{page.header}}", BLOG.header); + result = + format_file(result, "{{metadata.title}}", INFORMATION.metadata.title); + result = format_file(result, "{{page.content}}", BLOG.main); + result = format_file(result, "{{page.footer}}", BLOG.footer); return result; } std::string build_header(const std::string &TEMPLATE, const Information &INFORMATION) { std::string result = - format_file(TEMPLATE, "{{title}}", INFORMATION.metadata.title); + format_file(TEMPLATE, "{{metadata.title}}", INFORMATION.metadata.title); ; return result; @@ -25,7 +40,7 @@ std::string build_header(const std::string &TEMPLATE, std::string build_head(const std::string &TEMPLATE, const Information &INFORMATION) { std::string result = - format_file(TEMPLATE, "{{title}}", INFORMATION.metadata.title); + format_file(TEMPLATE, "{{metadata.title}}", INFORMATION.metadata.title); return result; } diff --git a/src/builder/builder.hpp b/src/builder/builder.hpp index 08c2373..9ed52ed 100644 --- a/src/builder/builder.hpp +++ b/src/builder/builder.hpp @@ -20,3 +20,12 @@ struct Information { // @return Built index.html in string std::string build_index(const std::string &TEMPLATE, const Page &PAGE, const Information &INFORMATION); + +// @brief Function that builds particular blog entry. It takes all it's +// information flog `Page struct` that should be built before calling it. +// @param TEMPLATE Template file for blog +// @param PAGE Page struct with information on blog entry content +// @param INFORMATION Information metadata about config and metadata of the file +// @return Built blog_entry.html in string +std::string build_blog_entry(const std::string &TEMPLATE, const Page &BLOG, + const Information &INFORMATION); diff --git a/src/tests.cpp b/src/tests.cpp index 4d61b81..accd94d 100644 --- a/src/tests.cpp +++ b/src/tests.cpp @@ -131,16 +131,30 @@ This [should be clickable](https://example.com) - nine)"; constexpr const char *template_index = R"( - + - {{head}} + {{page.head}} -
{{header}}
+
{{page.header}}
- {{main}} + {{page.main}}
- {{footer}} + {{page.footer}} + +)"; + +constexpr const char *template_blog_entry = R"( + + + {{page.head}} + + +
{{page.header}}
+
+
{{page.content}}
+
+ {{page.footer}} )"; @@ -291,3 +305,37 @@ TEST_CASE("build_index correctly assembles the page", "[builder]") { std::string result = build_index(TestFiles::template_index, page, info); REQUIRE(result == expected_output); } + +TEST_CASE("test build_blog_entry correctly assembles the page", "[builder]") { + Config config; + config.general.lang = "pl"; + Metadata metadata; + + Information info; + info.config = config; + info.metadata = metadata; + + Page page; + page.head = "Test"; + page.header = ""; + page.main = "Hej ho!"; + page.footer = "
Stopka
"; + + std::string expected_output = R"( + + + Test + + +
+
+
Hej ho!
+
+
Stopka
+ +)"; + + std::string result = + build_blog_entry(TestFiles::template_blog_entry, page, info); + REQUIRE(result == expected_output); +} diff --git a/templates/blog_entry.html b/templates/blog_entry.html index 1557347..6cc962a 100644 --- a/templates/blog_entry.html +++ b/templates/blog_entry.html @@ -1,9 +1,7 @@ - - - {{metadata.title}} + {{page.head}}
@@ -12,13 +10,12 @@
- {{content}} + {{page.content}}
-
- {{footer}} + {{page.footer}}
diff --git a/templates/footer.html b/templates/footer.html index 11d79ff..ea66bef 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -1,5 +1,5 @@