aboutsummaryrefslogtreecommitdiff
path: root/src/content
diff options
context:
space:
mode:
Diffstat (limited to 'src/content')
-rw-r--r--src/content/blog/Blog.cpp54
-rw-r--r--src/content/blog/Blog.hpp4
-rw-r--r--src/content/markdown/Markdown.cpp32
3 files changed, 74 insertions, 16 deletions
diff --git a/src/content/blog/Blog.cpp b/src/content/blog/Blog.cpp
index d2a66c8..ba8638e 100644
--- a/src/content/blog/Blog.cpp
+++ b/src/content/blog/Blog.cpp
@@ -41,9 +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;
- });
+ std::sort(m_BlogEntriesSortedByDate.begin(),
+ m_BlogEntriesSortedByDate.end(),
+ [](auto const & a, auto const & b) { return a->publishDate > b->publishDate; });
m_BlogContents.Init();
@@ -100,17 +100,19 @@ bool Blog::ValidateAndSetMetdadata(BlogMetadata const & blogMetadata, BlogEntry
{
bool retval = true;
std::function<bool(BlogMetadata const &, std::string const)> validateMetadata =
- [blogEntry](BlogMetadata const & bm, std::string const tname) {
- if (bm.find(tname) == bm.cend())
- {
- std::cerr << "Metadata validation: JSON key '" << tname << "' missing in "
- << blogEntry->metadata_filename << std::endl;
- return false;
- }
- return true;
- };
- std::function<bool(std::string const &, std::time_t &)> parseDateTime = [](std::string const & timeStr,
- std::time_t & time) {
+ [blogEntry](BlogMetadata const & bm, std::string const tname)
+ {
+ if (bm.find(tname) == bm.cend())
+ {
+ std::cerr << "Metadata validation: JSON key '" << tname << "' missing in " << blogEntry->metadata_filename
+ << std::endl;
+ return false;
+ }
+ return true;
+ };
+ std::function<bool(std::string const &, std::time_t &)> parseDateTime =
+ [](std::string const & timeStr, std::time_t & time)
+ {
std::tm tm = {};
std::stringstream ss(timeStr);
ss >> std::get_time(&tm, "%d.%m.%y %H:%M");
@@ -124,6 +126,27 @@ bool Blog::ValidateAndSetMetdadata(BlogMetadata const & blogMetadata, BlogEntry
return true;
};
+ if (validateMetadata(blogMetadata, "title") == false)
+ {
+ retval = false;
+ }
+ blogEntry->title = blogMetadata["title"];
+
+ if (validateMetadata(blogMetadata, "tags") == false)
+ {
+ retval = false;
+ }
+ for (auto const & tag : blogMetadata["tags"])
+ {
+ blogEntry->tags.push_back(tag);
+ }
+
+ if (validateMetadata(blogMetadata, "author") == false)
+ {
+ retval = false;
+ }
+ blogEntry->author = blogMetadata["author"];
+
if (validateMetadata(blogMetadata, "createDate") == false ||
parseDateTime(blogMetadata["createDate"], blogEntry->createDate) == false)
{
@@ -184,6 +207,9 @@ void Blog::GenerateBlogListing(RenderData & rd)
RenderData re;
re["metadata_filename"] = e->metadata_filename;
re["content_filename"] = e->content_filename;
+ re["title"] = e->title;
+ re["tags"] = e->tags;
+ re["author"] = e->author;
re["createDate"] = e->createDate;
re["publishDate"] = e->publishDate;
re["published"] = e->published;
diff --git a/src/content/blog/Blog.hpp b/src/content/blog/Blog.hpp
index f577d69..d99185a 100644
--- a/src/content/blog/Blog.hpp
+++ b/src/content/blog/Blog.hpp
@@ -16,6 +16,10 @@ struct blog_entry
std::string const metadata_filename;
std::string const content_filename;
+
+ std::string title;
+ std::vector<std::string> tags;
+ std::string author;
std::time_t createDate;
std::time_t publishDate;
bool published;
diff --git a/src/content/markdown/Markdown.cpp b/src/content/markdown/Markdown.cpp
index 63358b4..a85f333 100644
--- a/src/content/markdown/Markdown.cpp
+++ b/src/content/markdown/Markdown.cpp
@@ -1,5 +1,7 @@
#include "Markdown.hpp"
+#include <md4c-html.h>
+
Markdown::Markdown(std::string uriBasePath, std::string markdownFilesPath, std::string mainTemplatePath)
: Content(),
m_UriBasePath(uriBasePath),
@@ -8,6 +10,13 @@ Markdown::Markdown(std::string uriBasePath, std::string markdownFilesPath, std::
{
}
+extern "C" void markdown_to_html_conversion(const MD_CHAR * const text, MD_SIZE size, void * const userdata)
+{
+ std::string * html = (std::string *)userdata;
+
+ html->append(text, size);
+}
+
bool Markdown::Init()
{
std::cout << "Markdown files path: " << m_MarkdownFilesPath << std::endl;
@@ -22,8 +31,27 @@ bool Markdown::Init()
for (auto const & mfile : fs.GetFiles())
{
- m_Markdowns[mfile.first] =
- std::make_shared<std::string>(std::string(mfile.second.data.begin(), mfile.second.data.end()));
+ Data const & data = mfile.second.data;
+ std::string html;
+
+ html.reserve(data.size() / 8 + 64);
+ int ret = md_html((MD_CHAR const *)data.data(),
+ data.size(),
+ markdown_to_html_conversion,
+ &html,
+ MD_DIALECT_GITHUB,
+ MD_FLAG_COLLAPSEWHITESPACE | MD_FLAG_PERMISSIVEURLAUTOLINKS | MD_FLAG_PERMISSIVEWWWAUTOLINKS |
+ MD_FLAG_PERMISSIVEEMAILAUTOLINKS | MD_FLAG_PERMISSIVEAUTOLINKS | MD_FLAG_TABLES |
+ MD_FLAG_STRIKETHROUGH | MD_FLAG_LATEXMATHSPANS | MD_FLAG_WIKILINKS | MD_FLAG_TASKLISTS |
+ MD_FLAG_UNDERLINE);
+
+ if (ret != 0)
+ {
+ std::cerr << "Markdown HTML rendering failed." << std::endl;
+ return false;
+ }
+
+ m_Markdowns[mfile.first] = std::make_shared<std::string>(html);
}
return true;