HandlerPageView: First resolve all dynamics before parsing tags

Should make more sense this way, especially to extract headlines.
This commit is contained in:
Albert S. 2022-03-29 22:36:03 +02:00
parent fbca85e5ed
commit 1e224fdac6

View File

@ -25,6 +25,9 @@ SOFTWARE.
#include "../htmllink.h" #include "../htmllink.h"
#include "../dynamic/dynamiccontentpostlist.h" #include "../dynamic/dynamiccontentpostlist.h"
#include "../dynamic/dynamiccontentincludepage.h" #include "../dynamic/dynamiccontentincludepage.h"
#include "../dynamic/dynamiccontentsetvar.h"
#include "../dynamic/dynamiccontentgetvar.h"
bool HandlerPageView::canAccess(std::string page) bool HandlerPageView::canAccess(std::string page)
{ {
return effectivePermissions(page).canRead(); return effectivePermissions(page).canRead();
@ -137,8 +140,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
std::string indexcontent; std::string indexcontent;
std::string parsedcontent; std::string parsedcontent;
bool keepParsing = true; std::map<std::string, std::string> dynamicVarsMap;
std::function<std::string(std::string_view, std::string_view)> dynamicParseCallback = std::function<std::string(std::string_view, std::string_view)> dynamicParseCallback =
[&](std::string_view key, std::string_view value) -> std::string [&](std::string_view key, std::string_view value) -> std::string
{ {
@ -150,16 +152,34 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
} }
if(key == "dynamic:includepage") if(key == "dynamic:includepage")
{ {
std::shared_ptr<DynamicContentIncludePage> includePage = createDynamic<DynamicContentIncludePage>(); if((effectivePermissions(std::string(value)).canRead()))
includePage->setArgument(std::string(value)); {
return parser.parse(pageDao, *this->urlProvider, includePage->render(), dynamicParseCallback); std::shared_ptr<DynamicContentIncludePage> includePage = createDynamic<DynamicContentIncludePage>();
includePage->setArgument(std::string(value));
return parser.parseDynamics(includePage->render(), dynamicParseCallback);
}
}
if(key == "dynamic:setvar")
{
std::shared_ptr<DynamicContentSetVar> setVar = createDynamic<DynamicContentSetVar>();
setVar->setMap(dynamicVarsMap);
setVar->setArgument(std::string(value));
return setVar->render();
}
if(key == "dynamic:getvar")
{
std::shared_ptr<DynamicContentGetVar> getVar = createDynamic<DynamicContentGetVar>();
getVar->setMap(dynamicVarsMap);
getVar->setArgument(std::string(value));
return getVar->render();
} }
return std::string{}; return std::string{};
}; };
std::string resolvedContent = parser.parseDynamics(revision->content, dynamicParseCallback);
if(revisionid > 0) if(revisionid > 0)
{ {
indexcontent = createIndexContent(parser, revision->content); indexcontent = createIndexContent(parser, resolvedContent);
parsedcontent = parser.parse(pageDao, *this->urlProvider, revision->content, dynamicParseCallback); parsedcontent = parser.parse(pageDao, *this->urlProvider, resolvedContent);
} }
else else
{ {
@ -173,7 +193,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
} }
else else
{ {
indexcontent = createIndexContent(parser, revision->content); indexcontent = createIndexContent(parser, resolvedContent);
this->cache->put(cachekeyindexcontent, indexcontent); this->cache->put(cachekeyindexcontent, indexcontent);
} }
if(cachedparsedcontent) if(cachedparsedcontent)
@ -182,7 +202,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
} }
else else
{ {
parsedcontent = parser.parse(pageDao, *this->urlProvider, revision->content, dynamicParseCallback); parsedcontent = parser.parse(pageDao, *this->urlProvider, resolvedContent);
this->cache->put(cachekeyparsedcontent, parsedcontent); this->cache->put(cachekeyparsedcontent, parsedcontent);
} }
} }