HandlerPageView: Add [cmd:pagetitle] to set custom per-page titles
This commit is contained in:
parent
ca0c8a94fb
commit
1d5bf80710
@ -167,6 +167,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string revisionstr = std::to_string(revision->revision);
|
std::string revisionstr = std::to_string(revision->revision);
|
||||||
|
std::string customtitle = parser.extractCommand("pagetitle", revision->content);
|
||||||
page.setVar("content", parsedcontent);
|
page.setVar("content", parsedcontent);
|
||||||
page.setVar("index", indexcontent);
|
page.setVar("index", indexcontent);
|
||||||
page.setVar("editedby", revision->author);
|
page.setVar("editedby", revision->author);
|
||||||
@ -174,6 +175,10 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
|
|||||||
page.setVar("historyurl", this->urlProvider->pageHistory(pagename));
|
page.setVar("historyurl", this->urlProvider->pageHistory(pagename));
|
||||||
page.setVar("revision", revisionstr);
|
page.setVar("revision", revisionstr);
|
||||||
setPageVars(page, pagename);
|
setPageVars(page, pagename);
|
||||||
|
if(!customtitle.empty())
|
||||||
|
{
|
||||||
|
page.setVar("title", createPageTitle(customtitle));
|
||||||
|
}
|
||||||
std::string body = page.render();
|
std::string body = page.render();
|
||||||
if(revisionid == 0 && !this->userSession->loggedIn)
|
if(revisionid == 0 && !this->userSession->loggedIn)
|
||||||
{
|
{
|
||||||
|
45
parser.cpp
45
parser.cpp
@ -120,27 +120,32 @@ std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, std::st
|
|||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
// we don't care about commands, but we nevertheless replace them with empty strings
|
// we don't care about commands, but we nevertheless replace them with empty strings
|
||||||
std::regex tagfinder(R"(\[(b|i|u|li||ul|ol|link|wikilink|h\d|cmd:rename|cmd:redirect|category)*?\]((\s|\S)*?)\[/\1])");
|
std::regex tagfinder(
|
||||||
result = utils::regex_callback_replacer(tagfinder, content, [&](std::smatch &match) {
|
R"(\[(b|i|u|li||ul|ol|link|wikilink|h\d|cmd:rename|cmd:redirect|cmd:pagetitle|category)*?\]((\s|\S)*?)\[/\1])");
|
||||||
std::string tag = match.str(1);
|
result = utils::regex_callback_replacer(
|
||||||
std::string content = match.str(2);
|
tagfinder, content,
|
||||||
std::string justreplace[] = {"b", "i", "u", "ul", "li", "ol"};
|
[&](std::smatch &match)
|
||||||
content = parse(pagedao, provider, content);
|
|
||||||
if(std::find(std::begin(justreplace), std::end(justreplace), tag) != std::end(justreplace))
|
|
||||||
{
|
{
|
||||||
return "<" + tag + ">" + content + "</" + tag + ">";
|
std::string tag = match.str(1);
|
||||||
}
|
std::string content = match.str(2);
|
||||||
if(tag == "link" || tag == "wikilink")
|
std::string justreplace[] = {"b", "i", "u", "ul", "li", "ol"};
|
||||||
{
|
content = parse(pagedao, provider, content);
|
||||||
return this->processLink(pagedao, provider,
|
if(std::find(std::begin(justreplace), std::end(justreplace), tag) != std::end(justreplace))
|
||||||
match); // TODO: recreate this so we don't check inside the function stuff again
|
{
|
||||||
}
|
return "<" + tag + ">" + content + "</" + tag + ">";
|
||||||
if(tag[0] == 'h')
|
}
|
||||||
{
|
if(tag == "link" || tag == "wikilink")
|
||||||
return "<" + tag + " id='" + content + "'>" + content + "</" + tag + ">";
|
{
|
||||||
}
|
return this->processLink(
|
||||||
return std::string("");
|
pagedao, provider,
|
||||||
});
|
match); // TODO: recreate this so we don't check inside the function stuff again
|
||||||
|
}
|
||||||
|
if(tag[0] == 'h')
|
||||||
|
{
|
||||||
|
return "<" + tag + " id='" + content + "'>" + content + "</" + tag + ">";
|
||||||
|
}
|
||||||
|
return std::string("");
|
||||||
|
});
|
||||||
result = utils::strreplace(result, "\r\n", "<br>");
|
result = utils::strreplace(result, "\r\n", "<br>");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user