From ac793c6d398845ddd3904256f973ef29fdf857ad Mon Sep 17 00:00:00 2001 From: Albert S Date: Sun, 27 Mar 2022 08:37:55 +0200 Subject: [PATCH] handlers: HandlerPageView: Add '[dynamic:postlist]' tag by callback --- handlers/handlerpageview.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/handlers/handlerpageview.cpp b/handlers/handlerpageview.cpp index dce8a2b..5dfb0e0 100644 --- a/handlers/handlerpageview.cpp +++ b/handlers/handlerpageview.cpp @@ -23,7 +23,7 @@ SOFTWARE. #include "../logger.h" #include "../parser.h" #include "../htmllink.h" - +#include "../dynamic/dynamiccontentpostlist.h" bool HandlerPageView::canAccess(std::string page) { return effectivePermissions(page).canRead(); @@ -136,10 +136,21 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename, std::string indexcontent; std::string parsedcontent; + std::function dynamicParseCallback = + [&](std::string_view key, std::string_view value) -> std::string + { + if(key == "dynamic:postlist") + { + std::shared_ptr postlist = createDynamic(); + postlist->setCategory(std::string(value)); + return postlist->render(); + } + return std::string{}; + }; if(revisionid > 0) { indexcontent = createIndexContent(parser, revision->content); - parsedcontent = parser.parse(pageDao, *this->urlProvider, revision->content); + parsedcontent = parser.parse(pageDao, *this->urlProvider, revision->content, dynamicParseCallback); } else { @@ -162,7 +173,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename, } else { - parsedcontent = parser.parse(pageDao, *this->urlProvider, revision->content); + parsedcontent = parser.parse(pageDao, *this->urlProvider, revision->content, dynamicParseCallback); this->cache->put(cachekeyparsedcontent, parsedcontent); } } @@ -171,7 +182,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename, page.setVar("content", parsedcontent); page.setVar("index", indexcontent); page.setVar("editedby", revision->author); - page.setVar("editedon", utils::toISODate(revision->timestamp)); + page.setVar("editedon", utils::toISODateTime(revision->timestamp)); page.setVar("historyurl", this->urlProvider->pageHistory(pagename)); page.setVar("revision", revisionstr); setPageVars(page, pagename);