aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2021-10-19 00:43:49 +0200
committerToni Uhlig <matzeton@googlemail.com>2021-10-19 00:43:49 +0200
commit7b01dd8e4b1779e4c4dd782dbec87acce0f4754b (patch)
tree2e6268167fdddf209a6e8e161736f5e6aff6b7d3 /src
parent51d9d23c99d77edad03e6425f3ab35a390156117 (diff)
Added blog listing sorting and template checks.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src')
-rw-r--r--src/TemplateManager.cpp22
-rw-r--r--src/content/blog/Blog.cpp18
-rw-r--r--src/content/blog/Blog.hpp2
3 files changed, 40 insertions, 2 deletions
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;