Skip to content
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

[BUG] Broken style when deployed to sub-folder #74

Closed
mihalyr opened this issue Mar 7, 2022 · 7 comments · Fixed by #75
Closed

[BUG] Broken style when deployed to sub-folder #74

mihalyr opened this issue Mar 7, 2022 · 7 comments · Fixed by #75
Assignees
Labels
bug Something isn't working

Comments

@mihalyr
Copy link
Contributor

mihalyr commented Mar 7, 2022

The style is broken when the site is not deployed to the root path.

Reproducer:

hugo new site compose-example
cd compose-example
git init
git submodule add --force https://github.com/onweru/compose/ themes/compose
cp -rav themes/compose/exampleSite/* .

After committing and starting hugo server everything works nicely on the code snippets page:

image

Now try the same with a different baseURL:

HUGO_BASEURL="http://localhost:1313/compose/example" hugo server

image

And the worst is when you deploy this theme to a sub-folder in a GitLab pages project where it completely breaks the page with the syntax highlighting examples:

image

This happens on both Firefox and Chromium, not browser related. My OS is Linux (Fedora 34), not sure what GitLab Pages use.

Hugo version I use locally: v0.80.0/extended

Hugo version in GitLab Pages: hugo_extended:latest

My suspicion is that the theme has some / and points to an absolute path under the root for loading some assets, but haven't tracked it down yet.

@mihalyr mihalyr added the bug Something isn't working label Mar 7, 2022
@mihalyr
Copy link
Contributor Author

mihalyr commented Mar 7, 2022

I've generated the page now with the following:

rm -rf public
HUGO_BASEURL="http://localhost:1313/compose/example" hugo -d public/compose/example

And then started serving this with Python:

cd public
python -m http.server -b localhost 1313

I can see from the server logs that the website is asking for icons at the wrong location - at the root, instead of at the baseURL.

127.0.0.1 - - [07/Mar/2022 12:06:18] "GET /compose/example/icons/next.svg HTTP/1.1" 200 -
127.0.0.1 - - [07/Mar/2022 12:06:18] code 404, message File not found
127.0.0.1 - - [07/Mar/2022 12:06:18] "GET /icons/copy.svg HTTP/1.1" 404 -
127.0.0.1 - - [07/Mar/2022 12:06:18] code 404, message File not found
127.0.0.1 - - [07/Mar/2022 12:06:18] "GET /icons/order.svg HTTP/1.1" 404 -
127.0.0.1 - - [07/Mar/2022 12:06:18] code 404, message File not found
127.0.0.1 - - [07/Mar/2022 12:06:18] "GET /icons/carly.svg HTTP/1.1" 404 -
127.0.0.1 - - [07/Mar/2022 12:06:18] code 404, message File not found
127.0.0.1 - - [07/Mar/2022 12:06:18] "GET /icons/expand.svg HTTP/1.1" 404 -
127.0.0.1 - - [07/Mar/2022 12:06:18] code 404, message File not found
127.0.0.1 - - [07/Mar/2022 12:06:18] "GET /icons/copy.svg HTTP/1.1" 404 -
127.0.0.1 - - [07/Mar/2022 12:06:18] code 404, message File not found
127.0.0.1 - - [07/Mar/2022 12:06:18] "GET /icons/order.svg HTTP/1.1" 404 -
127.0.0.1 - - [07/Mar/2022 12:06:18] code 404, message File not found
127.0.0.1 - - [07/Mar/2022 12:06:18] "GET /icons/carly.svg HTTP/1.1" 404 -
127.0.0.1 - - [07/Mar/2022 12:06:18] code 404, message File not found
127.0.0.1 - - [07/Mar/2022 12:06:18] "GET /icons/expand.svg HTTP/1.1" 404 -
127.0.0.1 - - [07/Mar/2022 12:06:18] code 404, message File not found
127.0.0.1 - - [07/Mar/2022 12:06:18] "GET /icons/copy.svg HTTP/1.1" 404 -
127.0.0.1 - - [07/Mar/2022 12:06:18] code 404, message File not found
127.0.0.1 - - [07/Mar/2022 12:06:18] "GET /icons/order.svg HTTP/1.1" 404 -
127.0.0.1 - - [07/Mar/2022 12:06:18] code 404, message File not found
127.0.0.1 - - [07/Mar/2022 12:06:18] "GET /icons/carly.svg HTTP/1.1" 404 -
127.0.0.1 - - [07/Mar/2022 12:06:18] code 404, message File not found
127.0.0.1 - - [07/Mar/2022 12:06:18] "GET /icons/expand.svg HTTP/1.1" 404 -
127.0.0.1 - - [07/Mar/2022 12:06:18] code 404, message File not found
127.0.0.1 - - [07/Mar/2022 12:06:18] "GET /index.json HTTP/1.1" 404 -

@mihalyr
Copy link
Contributor Author

mihalyr commented Mar 7, 2022

I think one of the problems is here where we load svgs from the rootURL: https://github.com/onweru/compose/blob/master/assets/js/functions.js#L177

function loadSvg(file, parent, path = iconsPath) {
  const link = new URL(`${path}${file}.svg`, rootURL).href;

@mihalyr
Copy link
Contributor Author

mihalyr commented Mar 7, 2022

This seems to be the reason why search is not working either:

https://github.com/onweru/compose/blob/master/assets/js/search.js#L196

window.addEventListener('load', function() {
  fetch(new URL("index.json", rootURL).href)

https://github.com/onweru/compose/blob/master/assets/js/search.js#L112

          if(searchTerm.length)  {
            window.location.href = new URL(`search/?query=${searchTerm}`, rootURL).href;

@mihalyr
Copy link
Contributor Author

mihalyr commented Mar 7, 2022

And rootURL is defined as: https://github.com/onweru/compose/blob/master/assets/js/variables.js#L7

const rootURL = window.location.protocol + "//" + window.location.host;

@onweru onweru self-assigned this Mar 7, 2022
@mihalyr
Copy link
Contributor Author

mihalyr commented Mar 7, 2022

I've tested an easy fix this works for me in variables.js

// rootURL must end with '/' for relative URLs to work properly
const rootURL = '{{ strings.TrimSuffix "/" .Site.BaseURL }}/';

@mihalyr
Copy link
Contributor Author

mihalyr commented Mar 7, 2022

I've created a pull request with my proposal #75

@mihalyr
Copy link
Contributor Author

mihalyr commented Mar 7, 2022

Just wanted to add that I have a very easy workaround, I can override the variables.js in my local site as well for now.

PS: I am new to Hugo, just trying it the first time for documentation and needed a simple theme without dependencies that looks good, that's how I ended up using your theme. Thank you very much for creating this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants