aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2021-10-23 03:58:35 +0200
committerToni Uhlig <matzeton@googlemail.com>2021-10-23 03:58:35 +0200
commitf8d857d13b8ee76d7b4a03a9572257d8060ba19e (patch)
tree067c1fea1f43cabee289454c79b1f316d04eaa74
parent47f09ad8fb52de7ee9ed6c63574ea2f77e314fa2 (diff)
Removed EvHTTP chunked response support (for now).
* single blog post rendering Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--src/EventManager.cpp13
-rw-r--r--src/EventManager.hpp1
-rw-r--r--src/content/blog/Blog.cpp46
-rw-r--r--src/content/blog/Blog.hpp10
-rw-r--r--src/content/markdown/Markdown.cpp2
-rw-r--r--src/content/markdown/Markdown.hpp2
6 files changed, 39 insertions, 35 deletions
diff --git a/src/EventManager.cpp b/src/EventManager.cpp
index 4ca377a..90efa4b 100644
--- a/src/EventManager.cpp
+++ b/src/EventManager.cpp
@@ -10,15 +10,6 @@
extern "C"
{
- struct chunk_req_state
- {
- struct event_base * base;
- struct evhttp_request * req;
- struct event * timer;
-
- off_t out_offset;
- };
-
static void GenerateInternalErrorPage(struct evhttp_request * const req, std::string text)
{
evhttp_clear_headers(evhttp_request_get_output_headers(req));
@@ -233,7 +224,3 @@ void EventManager::AddCallback(std::string url, EvFunction fn, EvUserData dat)
{
m_UrlCallbacks.push_back(EvUrlCallback(url, {fn, dat}));
}
-
-void EventManager::AddChunkedCallback(std::string url, EvFunction fn, EvUserData dat, struct timeval chunk_timer)
-{
-}
diff --git a/src/EventManager.hpp b/src/EventManager.hpp
index f994510..a5516bb 100644
--- a/src/EventManager.hpp
+++ b/src/EventManager.hpp
@@ -32,7 +32,6 @@ public:
bool Init(std::string = "127.0.0.1", uint16_t port = 9000);
void SetDefaultCallback(EvFunction fn, EvUserData dat);
void AddCallback(std::string url, EvFunction fn, EvUserData dat);
- void AddChunkedCallback(std::string url, EvFunction fn, EvUserData dat, struct timeval chunk_timer);
private:
std::shared_ptr<ContentManager> m_ContentManager;
diff --git a/src/content/blog/Blog.cpp b/src/content/blog/Blog.cpp
index 5eb126f..03ccb28 100644
--- a/src/content/blog/Blog.cpp
+++ b/src/content/blog/Blog.cpp
@@ -41,8 +41,9 @@ bool Blog::Init()
std::cerr << "Blog Metadata validation failed." << std::endl;
retval = false;
}
- m_BlogEntriesSortedByDate.push_back(be);
+ m_BlogEntriesSortedByDate.push_back(be);
+ m_BlogEntries[full_uri_path] = be;
m_Redirections.push_back(full_uri_path);
}
std::sort(m_BlogEntriesSortedByDate.begin(), m_BlogEntriesSortedByDate.end(), [](auto const & a, auto const & b) {
@@ -79,7 +80,7 @@ bool Blog::Render(RequestResponse & rr, RenderData & rd, std::string & out)
}
else
{
- return false;
+ GetBlogPost(rd["blog_post"], rr.GetUriPath());
}
return true;
@@ -170,7 +171,7 @@ bool Blog::ValidateAndSetMetdadata(BlogMetadata const & blogMetadata, BlogEntry
return retval;
}
-bool Blog::ValidateEntries() const
+bool Blog::ValidateEntries()
{
bool retval = true;
@@ -183,7 +184,7 @@ bool Blog::ValidateEntries() const
retval = false;
}
}
- for (auto const & m : m_BlogContents.GetMarkdowns())
+ for (auto & m : m_BlogContents.GetMarkdowns())
{
if (std::any_of(m_BlogEntriesSortedByDate.cbegin(),
m_BlogEntriesSortedByDate.cend(),
@@ -198,6 +199,18 @@ bool Blog::ValidateEntries() const
return retval;
}
+void Blog::FillRenderData(RenderData & re, BlogEntry const & be)
+{
+ re["filename"] = be->filename;
+ re["title"] = be->title;
+ re["tags"] = be->tags;
+ re["author"] = be->author;
+ re["createDate"] = be->createDate;
+ re["publishDate"] = be->publishDate;
+ re["published"] = be->published;
+ re["content"] = "";
+}
+
void Blog::GenerateBlogListing(RenderData & rd)
{
for (auto const & e : m_BlogEntriesSortedByDate)
@@ -208,22 +221,23 @@ void Blog::GenerateBlogListing(RenderData & rd)
}
RenderData re;
- re["filename"] = e->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;
+ FillRenderData(re, e);
if (m_BlogContents.HasMarkdownFile(e->filename) == true)
{
re["content"] = m_BlogContents.GetMarkdownHTML(e->filename)->c_str();
}
- else
- {
- re["content"] = "";
- }
-
rd += re;
}
}
+
+void Blog::GetBlogPost(RenderData & rd, char const * blogPostUri)
+{
+ RenderData re;
+
+ if (m_BlogContents.HasMarkdownFile(blogPostUri) == true)
+ {
+ FillRenderData(re, m_BlogEntries[blogPostUri]);
+ re["content"] = m_BlogContents.GetMarkdownHTML(blogPostUri)->c_str();
+ }
+ rd = re;
+}
diff --git a/src/content/blog/Blog.hpp b/src/content/blog/Blog.hpp
index 79c06a2..abdb522 100644
--- a/src/content/blog/Blog.hpp
+++ b/src/content/blog/Blog.hpp
@@ -25,7 +25,8 @@ struct blog_entry
using BlogMetadata = inja::json;
using BlogEntry = std::shared_ptr<struct blog_entry>;
-using BlogEntries = std::vector<BlogEntry>;
+using BlogEntriesVector = std::vector<BlogEntry>;
+using BlogEntriesMap = std::unordered_map<std::string, BlogEntry>;
class Blog : public Content
{
@@ -41,8 +42,10 @@ public:
Redirections & GetRedirections();
static bool ValidateAndSetMetdadata(BlogMetadata const & blogMetadata, BlogEntry & blogEntry);
- bool ValidateEntries() const;
+ bool ValidateEntries();
+ void FillRenderData(RenderData & re, BlogEntry const & be);
void GenerateBlogListing(RenderData & rd);
+ void GetBlogPost(RenderData & rd, char const * blogPostUri);
private:
std::string m_UriBasePath;
@@ -50,7 +53,8 @@ private:
std::string m_BlogPath;
Redirections m_Redirections;
Markdown m_BlogContents;
- BlogEntries m_BlogEntriesSortedByDate;
+ BlogEntriesVector m_BlogEntriesSortedByDate;
+ BlogEntriesMap m_BlogEntries;
};
#endif
diff --git a/src/content/markdown/Markdown.cpp b/src/content/markdown/Markdown.cpp
index de05080..14a308f 100644
--- a/src/content/markdown/Markdown.cpp
+++ b/src/content/markdown/Markdown.cpp
@@ -173,7 +173,7 @@ bool Markdown::HasMarkdownURI(std::string uriPath) const
return HasMarkdownFile(uriPath.substr(m_UriBasePath.length() + 1, std::string::npos));
}
-Markdowns const & Markdown::GetMarkdowns() const
+Markdowns & Markdown::GetMarkdowns()
{
return m_Markdowns;
}
diff --git a/src/content/markdown/Markdown.hpp b/src/content/markdown/Markdown.hpp
index fe0d968..dfb6451 100644
--- a/src/content/markdown/Markdown.hpp
+++ b/src/content/markdown/Markdown.hpp
@@ -22,7 +22,7 @@ public:
bool HasMarkdownFile(std::string filePath) const;
bool HasMarkdownURI(std::string uriPath) const;
- Markdowns const & GetMarkdowns() const;
+ Markdowns & GetMarkdowns();
std::shared_ptr<std::string> const & GetMarkdownHTML(std::string uriPath);
private: