onweru / newsroom

A simple, minimalistic Hugo theme. View Demo here
https://rooms.netlify.app/
Other
287 stars 114 forks source link

RFC: Make resources URL non-absolute #39

Closed McSneaky closed 1 year ago

McSneaky commented 3 years ago

Hello!

I've been using your theme on https://adonisjs-news.com/ and I really like it, real good job :+1:

Since I'm doing a lot of deployments to some random URLs to test stuff I've been running into issues, that I can't set baseURL in configuration correctly (coz URL changes with every commit I do - one example URL: https://f20eb25b.adonisjs-news.pages.dev/)

Now the issue is, that when I new domain is generated it still tries to load some stuff from adonisjs-news.com not from that new domain. Since I have set https://adonisjs-news.com/ as my baseURL that's why some of the resources are not loading in correctly. You can open dev tools in https://f20eb25b.adonisjs-news.pages.dev/ and see what I mean

Fix is to not add whole baseURL in front of resources, but just add / in front of there. I already did that in some template files and it works all good (just replaced .Permalink with .RelPermalink)

For example styles.html:

{{- $options := (dict "targetPath" "css/styles.css" "outputStyle" "expanded" "enableSourceMap" "true") -}}
{{ $mainSassFile := "sass/main.sass" }}
{{- $styles := resources.Get $mainSassFile | resources.ExecuteAsTemplate $mainSassFile . | resources.ToCSS $options |
resources.Fingerprint "sha512" }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}">

That fix works for me, but I think it would break for people who use theme under some sub-path, like mysite.com/blog/? :thinking:

Is there some way to make it work both ways? Or maybe should introduce some new config variable? Or maybe there's already some config in there for Hugo? :thinking:

Edit: I can open PR with those RelPermalink changes, just not sure about sub-paths if it will break or not

onweru commented 3 years ago

That fix works for me, but I think it would break for people who use theme under some sub-path, like mysite.com/blog/? 🤔

@McSneaky, yeah that's why theme developers are required to use absolute links.

Or maybe should introduce some new config variable?

Interesting idea, I can look into it when I get some time.

onweru commented 1 year ago

Not possible because of this requirement

but I think it would break for people who use theme under some sub-path, like mysite.com/blog/

Such people will be ok if their baaseURL to https://mysite.com/blog/