newsroom icon indicating copy to clipboard operation
newsroom copied to clipboard

RFC: Make resources URL non-absolute

Open McSneaky opened this issue 3 years ago • 1 comments

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

McSneaky avatar Aug 12 '21 00:08 McSneaky

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 avatar Aug 13 '21 10:08 onweru

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/

onweru avatar Jan 05 '23 17:01 onweru