make html <title></title> configurable

This commit is contained in:
Albert S. 2019-10-02 21:40:58 +02:00
父節點 7fc9c090ed
當前提交 1c646fa165
共有 3 個文件被更改,包括 14 次插入4 次删除

查看文件

@ -18,10 +18,12 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include "config.h"
#include "permissions.h"
#include <exception> #include <exception>
#include <iostream> #include <iostream>
#include "config.h"
#include "permissions.h"
#include "varreplacer.h"
std::string Config::required(const std::string &key) std::string Config::required(const std::string &key)
{ {
auto it = this->configmap.find(key); auto it = this->configmap.find(key);
@ -99,6 +101,7 @@ Config::Config(const std::map<std::string, std::string> &map)
this->handlersConfig.max_pagename_length = optional("max_pagename_length", 256); this->handlersConfig.max_pagename_length = optional("max_pagename_length", 256);
this->session_max_lifetime = optional("session_max_lifetime", 3600); this->session_max_lifetime = optional("session_max_lifetime", 3600);
this->handlersConfig.query_limit = optional("query_limit", 200); this->handlersConfig.query_limit = optional("query_limit", 200);
this->handlersConfig.page_title_template = optional("page_title_template", "{title} - {wikiname}");
this->threadscount = optional("threadscount", 1); this->threadscount = optional("threadscount", 1);
this->handlersConfig.anon_permissions = Permissions(required("anon_permissions")); this->handlersConfig.anon_permissions = Permissions(required("anon_permissions"));
@ -109,6 +112,10 @@ Config::Config(const std::map<std::string, std::string> &map)
ConfigVariableResolver resolver{this->configmap}; ConfigVariableResolver resolver{this->configmap};
this->configVarResolver = resolver; this->configVarResolver = resolver;
Varreplacer replacer("{");
replacer.addKeyValue("wikiname", this->handlersConfig.wikiname);
this->handlersConfig.page_title_template = replacer.parse(this->handlersConfig.page_title_template);
} }
ConfigReader::ConfigReader(const std::string &file) ConfigReader::ConfigReader(const std::string &file)

查看文件

@ -13,6 +13,7 @@ struct HandlerConfig
Permissions anon_permissions; Permissions anon_permissions;
std::string wikiname; std::string wikiname;
std::string anon_username; std::string anon_username;
std::string page_title_template;
int max_pagename_length; int max_pagename_length;
int query_limit; int query_limit;
}; };

查看文件

@ -43,9 +43,11 @@ Response Handler::errorResponse(std::string errortitle, std::string errormessage
return {status, error.render()}; return {status, error.render()};
} }
std::string Handler::createPageTitle(std::string append) std::string Handler::createPageTitle(std::string title)
{ {
return this->handlersConfig->wikiname + " - " + append; // TODO: we might wanna make the format configurable Varreplacer replacer("{");
replacer.addKeyValue("title", title);
return replacer.parse(this->handlersConfig->page_title_template);
} }
QueryOption Handler::queryOption(const Request &r) const QueryOption Handler::queryOption(const Request &r) const