diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2021-10-19 00:43:49 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2021-10-19 00:43:49 +0200 |
commit | 7b01dd8e4b1779e4c4dd782dbec87acce0f4754b (patch) | |
tree | 2e6268167fdddf209a6e8e161736f5e6aff6b7d3 | |
parent | 51d9d23c99d77edad03e6425f3ab35a390156117 (diff) |
Added blog listing sorting and template checks.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r-- | blog/my-second-blog-entry.json | 5 | ||||
-rw-r--r-- | blog/my-second-blog-entry.md | 2 | ||||
-rw-r--r-- | src/TemplateManager.cpp | 22 | ||||
-rw-r--r-- | src/content/blog/Blog.cpp | 18 | ||||
-rw-r--r-- | src/content/blog/Blog.hpp | 2 | ||||
-rw-r--r-- | wwwroot/index.html | 3 |
6 files changed, 50 insertions, 2 deletions
diff --git a/blog/my-second-blog-entry.json b/blog/my-second-blog-entry.json new file mode 100644 index 0000000..b8c2ec0 --- /dev/null +++ b/blog/my-second-blog-entry.json @@ -0,0 +1,5 @@ +{ + "createDate": "23.02.1989 23:59", + "publishDate": "30.12.2020 1:00", + "published": false +} diff --git a/blog/my-second-blog-entry.md b/blog/my-second-blog-entry.md new file mode 100644 index 0000000..292b1e1 --- /dev/null +++ b/blog/my-second-blog-entry.md @@ -0,0 +1,2 @@ +Text +======= diff --git a/src/TemplateManager.cpp b/src/TemplateManager.cpp index 99af2ad..ddde2c4 100644 --- a/src/TemplateManager.cpp +++ b/src/TemplateManager.cpp @@ -12,6 +12,28 @@ TemplateManager::TemplateManager() (void)args; return true; }); + /* + * indent(input: str, width: int, first: bool, blank: bool); + */ + AddInjaCallback("indent", 4, [](inja::Arguments & args) { + std::stringstream stream(args.at(0)->get<std::string>()); + std::string line, out; + bool is_first_line = true; + while (std::getline(stream, line)) + { + if (is_first_line == false || args.at(2)->get<bool>() == true) + { + if (line != "" || args.at(3)->get<bool>() == false) + { + line.insert(0, args.at(1)->get<std::size_t>(), ' '); + } + } + line += '\n'; + out += line; + is_first_line = false; + } + return out; + }); } void TemplateManager::ParseTemplates(Filesystem & fs) diff --git a/src/content/blog/Blog.cpp b/src/content/blog/Blog.cpp index 1893cc5..d2a66c8 100644 --- a/src/content/blog/Blog.cpp +++ b/src/content/blog/Blog.cpp @@ -41,6 +41,9 @@ bool Blog::Init() m_Redirections.push_back(std::filesystem::path(jfile.first).stem()); } + std::sort(m_BlogEntriesSortedByDate.begin(), m_BlogEntriesSortedByDate.end(), [](auto const & a, auto const & b) { + return a->publishDate > b->publishDate; + }); m_BlogContents.Init(); @@ -169,16 +172,29 @@ bool Blog::ValidateEntries() const return retval; } -void Blog::GenerateBlogListing(RenderData & rd) const +void Blog::GenerateBlogListing(RenderData & rd) { for (auto const & e : m_BlogEntriesSortedByDate) { + if (e->published == false) + { + continue; + } + RenderData re; re["metadata_filename"] = e->metadata_filename; re["content_filename"] = e->content_filename; re["createDate"] = e->createDate; re["publishDate"] = e->publishDate; re["published"] = e->published; + if (m_BlogContents.HasMarkdownFile(e->content_filename) == true) + { + re["content"] = m_BlogContents.GetMarkdownHTML(e->content_filename)->c_str(); + } + else + { + re["content"] = ""; + } rd += re; } diff --git a/src/content/blog/Blog.hpp b/src/content/blog/Blog.hpp index a0e35b1..f577d69 100644 --- a/src/content/blog/Blog.hpp +++ b/src/content/blog/Blog.hpp @@ -40,7 +40,7 @@ public: static bool ValidateAndSetMetdadata(BlogMetadata const & blogMetadata, BlogEntry & blogEntry); bool ValidateEntries() const; - void GenerateBlogListing(RenderData & rd) const; + void GenerateBlogListing(RenderData & rd); private: std::string m_UriBasePath; diff --git a/wwwroot/index.html b/wwwroot/index.html index b0a9fbf..8d3bbd4 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -3,9 +3,12 @@ <b>blabla</b> Test fn....: <b>{{ test_fn }}</b><br> Test RetFN.: <b>{{ test_return_true }}</b><br> +{% if exists("blog_listing") and length(blog_listing) > 0 %} ## for entry in blog_listing {{ loop.index1 }}: {{ entry.content_filename }} -> {{ entry.published }}<br> <b>{{ entry }}</b><br> + {{ indent(entry.content, 8, false, false) }}<br> ## endfor +{% endif %} </p> </body></html> |