Adding external config support

This commit is contained in:
Bastien Wirtz 2020-06-09 19:11:42 -07:00
parent 52ed5af607
commit 1a42e30a17
2 changed files with 25 additions and 12 deletions

View File

@ -85,6 +85,10 @@ Title, icons, links, colors, and services can be configured in the `config.yml`
# Homepage configuration # Homepage configuration
# See https://fontawesome.com/icons for icons options # See https://fontawesome.com/icons for icons options
# Optional: Use external configuration file.
# Using this will ignore remaining config in this file
# externalConfig: https://example.com/server-luci/config.yaml
title: "App dashboard" title: "App dashboard"
subtitle: "Homer" subtitle: "Homer"
logo: "assets/homer.png" logo: "assets/homer.png"

View File

@ -63,7 +63,7 @@
</h2> </h2>
<Service <Service
v-for="item in group.items" v-for="item in group.items"
:key="item.url" :key="item.name"
v-bind:item="item" v-bind:item="item"
class="column is-one-third-widescreen" class="column is-one-third-widescreen"
/> />
@ -153,19 +153,28 @@ export default {
document.title = `${this.config.title} | ${this.config.subtitle}`; document.title = `${this.config.title} | ${this.config.subtitle}`;
}, },
methods: { methods: {
getConfig: function () { getConfig: function (path = "config.yml") {
return fetch("config.yml") return fetch(path).then((response) => {
.then((response) => {
if (!response.ok) { if (!response.ok) {
throw Error(response.statusText); throw Error(response.statusText);
} }
return response.text().then((body) => {
const that = this;
return response
.text()
.then((body) => {
return jsyaml.load(body); return jsyaml.load(body);
}); })
.then(function (config) {
if (config.externalConfig) {
return that.getConfig(config.externalConfig);
}
return config;
}) })
.catch((error) => { .catch((error) => {
return this.handleErrors("⚠️ Error loading configuration", error); return this.handleErrors("⚠️ Error loading configuration", error);
}); });
});
}, },
matchesFilter: function (item) { matchesFilter: function (item) {
return ( return (