mirror of
https://github.com/szymon-jozef/static-site-generator.git
synced 2026-06-05 17:00:10 +02:00
Merge branch 'master' of github.com:szymon-jozef/static-site-generator
This commit is contained in:
32
flake.nix
32
flake.nix
@@ -6,25 +6,21 @@
|
||||
};
|
||||
|
||||
outputs =
|
||||
{ self, nixpkgs }:
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
}:
|
||||
|
||||
{
|
||||
devShells = {
|
||||
default = nixpkgs.mkShell {
|
||||
packages = with nixpkgs; [
|
||||
gcc
|
||||
gnumake
|
||||
|
||||
md4c
|
||||
catch2_3
|
||||
|
||||
clang-tools
|
||||
gdb
|
||||
];
|
||||
};
|
||||
devShells.${system}.default = pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
gcc
|
||||
gnumake
|
||||
md4c
|
||||
catch2_3
|
||||
clang-tools
|
||||
gdb
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -131,16 +131,30 @@ This [should be clickable](https://example.com)
|
||||
- nine)";
|
||||
|
||||
constexpr const char *template_index = R"(<!DOCTYPE html>
|
||||
<html lang="{{lang}}">
|
||||
<html lang="{{config.lang}}">
|
||||
<head>
|
||||
{{head}}
|
||||
{{page.head}}
|
||||
</head>
|
||||
<body>
|
||||
<header>{{header}}</header>
|
||||
<header>{{page.header}}</header>
|
||||
<main>
|
||||
{{main}}
|
||||
{{page.main}}
|
||||
</main>
|
||||
{{footer}}
|
||||
{{page.footer}}
|
||||
</body>
|
||||
</html>)";
|
||||
|
||||
constexpr const char *template_blog_entry = R"(<!DOCTYPE html>
|
||||
<html lang="{{config.lang}}">
|
||||
<head>
|
||||
{{page.head}}
|
||||
</head>
|
||||
<body>
|
||||
<header>{{page.header}}</header>
|
||||
<main>
|
||||
<article>{{page.content}}</article>
|
||||
</main>
|
||||
{{page.footer}}
|
||||
</body>
|
||||
</html>)";
|
||||
|
||||
@@ -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 = "<meta charset='utf-8'><title>Test</title>";
|
||||
page.header = "<nav>Menu</nav>";
|
||||
page.main = "Hej ho!";
|
||||
page.footer = "<footer>Stopka</footer>";
|
||||
|
||||
std::string expected_output = R"(<!DOCTYPE html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset='utf-8'><title>Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<header><nav>Menu</nav></header>
|
||||
<main>
|
||||
<article>Hej ho!</article>
|
||||
</main>
|
||||
<footer>Stopka</footer>
|
||||
</body>
|
||||
</html>)";
|
||||
|
||||
std::string result =
|
||||
build_blog_entry(TestFiles::template_blog_entry, page, info);
|
||||
REQUIRE(result == expected_output);
|
||||
}
|
||||
|
||||
21
templates/blog_entry.html
Normal file
21
templates/blog_entry.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{config.lang}}">
|
||||
<head>
|
||||
{{page.head}}
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>{{metadata.title}}</h1>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<article>
|
||||
{{page.content}}
|
||||
</article>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
{{page.footer}}
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,5 +1,5 @@
|
||||
<footer>
|
||||
<p>Strona napisana przez: {{author}}</p>
|
||||
<p>Blog owned by: {{config.author}}</p>
|
||||
<ul>
|
||||
{{if email}}
|
||||
<li><a href="mailto:{{email}}">{{email}}</a></li>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{title}}</title>
|
||||
<title>{{metadata.title}}</title>
|
||||
<link rel="stylesheet" href="/style/style.css">
|
||||
</head>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<header>
|
||||
<h1>{{title}}</h1>
|
||||
<h1>{{metadata.title}}</h1>
|
||||
</header>
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{lang}}">
|
||||
<html lang="{{config.lang}}">
|
||||
<head>
|
||||
{{head}}
|
||||
{{page.head}}
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
{{header}}
|
||||
{{page.header}}
|
||||
</header>
|
||||
<main>
|
||||
{{main}}
|
||||
{{page.main}}
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
{{footer}}
|
||||
{{page.footer}}
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user