-
-
Notifications
You must be signed in to change notification settings - Fork 772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds multiple pages based on different config files #177
Conversation
Hi @luixal! Thanks for your contribution! Same here, that sounds great, I will look more closely into it soon! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a breaking change for #8 (subdir hosting). The quickest fix I could think of is using a query string instead of a path for additional pages. I've added the corresponding suggestions in the review.
Personally using #page2
instead of ?page2
in the config seems more visually pleasing (and intuitive) to me, but as anchor links don't reload the page an additional mechanism would be needed.
On a side note and please correct me if I'm wrong, even ignoring the breaking change, doesn't a path like /page2
require additional configuration on the server? This would than also not work on the current docker image. For this to work on nginx
I had to configure:
location /page2 {
alias /usr/share/nginx/html;
try_files $uri $uri/index.html $uri/ =404;
}
More importantly one has to be careful that the server does not add a trailing slash, which breaks the config file retrieval.
@@ -33,7 +33,7 @@ export default { | |||
methods: { | |||
checkOffline: function () { | |||
let that = this; | |||
return fetch(window.location.href + "?alive", { | |||
return fetch(window.location.origin + "?alive", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break #8 as window.location.origin
only returns http://localhost
if the website is located in a subdirectory; eg: http://localhost/homer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a query string this can reverted back to href
.
return fetch(window.location.origin + "?alive", { | |
return fetch(window.location.href + "?alive", { |
src/App.vue
Outdated
@@ -13,7 +13,7 @@ | |||
<section v-if="config.header" class="first-line"> | |||
<div v-cloak class="container"> | |||
<div class="logo"> | |||
<img v-if="config.logo" :src="config.logo" alt="dashboard logo" /> | |||
<a href="/"><img v-if="config.logo" :src="config.logo" alt="dashboard logo" /></a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again breaks #8 as this will return to http://localhost
and not the subdirectory the page is hosted on (http://localhost/homer
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If using a query string, just clear it.
<a href="/"><img v-if="config.logo" :src="config.logo" alt="dashboard logo" /></a> | |
<a href="?"><img v-if="config.logo" :src="config.logo" alt="dashboard logo" /></a> |
src/App.vue
Outdated
@@ -153,6 +153,13 @@ export default { | |||
let config; | |||
try { | |||
config = await this.getConfig(); | |||
const path = (window.location.pathname != '/') ? window.location.pathname : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a path, maybe use a query string instead, which allows for subdirectory hosting.
const path = (window.location.pathname != '/') ? window.location.pathname : null; | |
const path = (window.location.search.substring(1) != '') ? window.location.search.substring(1) : null; |
src/App.vue
Outdated
@@ -153,6 +153,13 @@ export default { | |||
let config; | |||
try { | |||
config = await this.getConfig(); | |||
const path = (window.location.pathname != '/') ? window.location.pathname : null; | |||
if (path) { | |||
let pathConfig = await this.getConfig(`assets${path}.yml`); // the slash (/) is included in the pathname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using a query string the slash is no longer part of the pathname and needs to be added.
let pathConfig = await this.getConfig(`assets${path}.yml`); // the slash (/) is included in the pathname | |
let pathConfig = await this.getConfig(`assets/${path}.yml`); |
docs/configuration.md
Outdated
# see url field and assets/page.yml used in this example: | ||
- name: "Second Page" | ||
icon: "fas fa-file-alt" | ||
url: "/page2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
url: "/page2" | |
url: "?page2" |
Changes sound good to me. Didn't notice the #8 feature. Maybe a doc with all features will be nice to have :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be fair, I only checked for the feature after the fact. Still running an old fork locally that does not support it. I've just had my fair share of fights with applications that don't play well with relative paths and noticed that this change may be problematic in a subdir deployment. Some features are listed under Features
in the README.md
, maybe hosting in a subdir could be added?
I'm still more fond of using #page2
rather than ?page2
. Not just visually, but also because using the query string could block or make it harder for future additions to make use of it. I've added another review with changes for using #page2
.
docs/configuration.md
Outdated
# see url field and assets/page.yml used in this example: | ||
- name: "Second Page" | ||
icon: "fas fa-file-alt" | ||
url: "/page2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
url: "/page2" | |
url: "#page2" |
src/App.vue
Outdated
@@ -13,7 +13,7 @@ | |||
<section v-if="config.header" class="first-line"> | |||
<div v-cloak class="container"> | |||
<div class="logo"> | |||
<img v-if="config.logo" :src="config.logo" alt="dashboard logo" /> | |||
<a href="/"><img v-if="config.logo" :src="config.logo" alt="dashboard logo" /></a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<a href="/"><img v-if="config.logo" :src="config.logo" alt="dashboard logo" /></a> | |
<a href="#"><img v-if="config.logo" :src="config.logo" alt="dashboard logo" /></a> |
src/App.vue
Outdated
@@ -153,6 +153,13 @@ export default { | |||
let config; | |||
try { | |||
config = await this.getConfig(); | |||
const path = (window.location.pathname != '/') ? window.location.pathname : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const path = (window.location.pathname != '/') ? window.location.pathname : null; | |
const path = (window.location.hash.substring(1) != '') ? window.location.hash.substring(1) : null; |
src/App.vue
Outdated
@@ -153,6 +153,13 @@ export default { | |||
let config; | |||
try { | |||
config = await this.getConfig(); | |||
const path = (window.location.pathname != '/') ? window.location.pathname : null; | |||
if (path) { | |||
let pathConfig = await this.getConfig(`assets${path}.yml`); // the slash (/) is included in the pathname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let pathConfig = await this.getConfig(`assets${path}.yml`); // the slash (/) is included in the pathname | |
let pathConfig = await this.getConfig(`assets/${path}.yml`); |
@@ -33,7 +33,7 @@ export default { | |||
methods: { | |||
checkOffline: function () { | |||
let that = this; | |||
return fetch(window.location.href + "?alive", { | |||
return fetch(window.location.origin + "?alive", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fetch(window.location.origin + "?alive", { | |
return fetch(window.location.href + "?alive", { |
Just tested your suggested changes and it works great. Just cleanning up and will push for merge. Thanks! :) |
Thanks for the great work @luixal & @pdevq ! I merged that as is to just modified a few thing:
Hope that sounds good to you! btw, I updated the demo to show the second page feature. |
Awesome work! The 'no full reload' is a lot better. Guess I'll have to finally update my local copy, don't know yet what I need the multipages for, but I really like them. |
Great! Avoiding full reload was a next stage I had on mind but I didn't found the moment to do it, awesome you could! |
Description
As proposed in the related issue, this PR allows to have multiple pages based on different config files.
How does this work?
In the links section, you can add a page with a related path, for example (look at the "Second page"):
When you navigate to this link, Homer will load the
assets/config.yml
file and theassets/page2.yml
file; then it overwrites the fields present on the second config over the first one. This way you can keep the config presets from the main config and only include the ones you want to be different in the second.For example, if your
page2.yml
file is like this:It will overwrite fields
title
,subtitle
,message
(gets removed as it's empty),links
andservices
with config from this file, but kill keep other fields from the defaultconfig.yml
file.Considerations
For this to work without errors, I had to change line (36@ConnectivityChecker.vue)[https://github.com/bastienwirtz/homer/blob/3786f80dae2df7780d19ba8ffd9374ef3c2fc30f/src/components/ConnectivityChecker.vue#L36] so it refers to
window.location.origin
instead ofwindow.location.href' or it would try to use
/page2?alive` for checking connectivity. Seems to work fine this way.Fixes #152
Type of change
Checklist:
config.yml
file