1
0
mirror of https://github.com/ohwgiles/laminar.git synced 2026-10-18 00:54:25 +00:00

Add the ability to customize index.html (#113)

User may provide a custom index.html template file to be used instead
of the built-in version. Changes to this file are watched by laminard
using inotify in order to load and compress the custom file for gzip
delivery, reusing the existing method for serving static assets.

This feature obviates the custom css feature, so remove references from
the manual and add a deprecation warning if it is used.

Add a section to the UserManual describing how to use this feature and
including a link to an example using Semantic UI.
This commit is contained in:
Cameron Eagans
2020-03-10 11:40:14 -06:00
committed by GitHub
parent f981491a34
commit 2e54773e83
7 changed files with 90 additions and 35 deletions

View File

@@ -113,6 +113,12 @@ Laminar::Laminar(Server &server, Settings settings) :
.addPath((homePath/"cfg"/"jobs").toString(true).cStr())
.addPath((homePath/"cfg").toString(true).cStr()); // for groups.conf
loadCustomizations();
srv.watchPaths([this]{
LLOG(INFO, "Reloading customizations");
loadCustomizations();
}).addPath((homePath/"custom").toString(true).cStr());
srv.listenRpc(*rpc, settings.bind_rpc);
srv.listenHttp(*http, settings.bind_http);
@@ -121,6 +127,14 @@ Laminar::Laminar(Server &server, Settings settings) :
loadConfiguration();
}
void Laminar::loadCustomizations() {
KJ_IF_MAYBE(templ, fsHome->tryOpenFile(kj::Path{"custom","index.html"})) {
http->setHtmlTemplate((*templ)->readAllText().cStr());
} else {
http->setHtmlTemplate();
}
}
uint Laminar::latestRun(std::string job) {
auto it = activeJobs.byJobName().equal_range(job);
if(it.first == it.second) {
@@ -789,8 +803,14 @@ R"x(
return true;
}
// TODO: deprecate
std::string Laminar::getCustomCss() {
KJ_IF_MAYBE(cssFile, fsHome->tryOpenFile(kj::Path{"custom","style.css"})) {
static bool warningShown = false;
if(!warningShown) {
LLOG(WARNING, "Custom CSS has been deprecated and will be removed from a future release. Use a custom HTML template instead.");
warningShown = true;
}
return (*cssFile)->readAllText().cStr();
} else {
return std::string();