Good evening, I’m having some trouble due to unresolved problem linked here:
My goal is just to have “n” website generated with hugo. They are with same theme, same configuration etc…the differences will be only the logo and the contents.
So, I’d like to “reuse” the same CSS, FONTS and JS directories.
To do that, I have setup Hugo in order to have the following directories:
-CommonServices (with inside the CSS, FONTS and JS)
-Site1
-Site2
-…
-SiteN
I try to “modify” the theme in “partial/myfile.html”…but I found this problem.
{{- with resources.Get "/css/file.css" }}
<link href="{{ .RelPermalink }}{{ $assetBusting }}" rel="stylesheet"></link>
{{- end }}
What I want to do is easily this:
{{- with resources.Get "/css/file.css" }}
<link href="{{ replace .RelPermalink "/css" "../CommonServices/css" }}{{ $assetBusting }}" rel="stylesheet"></link>
{{- end }}
Due the problem metioned in the link I have not the right result and the only way is to write a script in some language that read all html files and do the substituion of
foreach fileHTML in Site
originalHTML = read(fileHTML)
newHTML = originalHTML.replace("/css","../CommonServices/css")
fileHTML = save(newHTML)
Instead of write this “script”, is possible to do that in goHugo bypassing the “bug”?
Good morning, thanks for the reply.
I have one directory called CommonSevices, where I have put manually all the common files once.
Then I have several Hugo Projects (= websites). When I want to publish I run hugo -d myDirectory for a single website. In the script for the “publication” I then delete the directory “JS, Fonts and CSS” because I want to use the files inside the “CommonServices” that is outside the publication directory of each hugo project.
As I organized, my goal is just to add “../CommonServices” in front of “/js”, “/css”, “/font”.
To do that, I need that hugo give me the string .RelPermalink as it was evaluated inside an href attribute and then I can proceed with the replace operation.
Actually I can’t do that because when I write replace .RelPermaLink "/js" "../CommonServices/js" .RelPermaLink is not evaluated as it was in a href attribute, but as it was outside.
I also try this code but does not work (the relative characters .. is lost):
Example:
{{$x := string (print `href=` .RelPermalink) }}
{{ $x }} <<--- show: `href=../fonts/etc`
{{ replace $x `href=` `` }} <<-- show: `/font/etc` (the `..` is lost :tired_face: )
It seems like we’re trying to solve the wrong problem here. Your approach in an anti-pattern.
Typically you would place the shared source files in their own directory, then mount that directory to assets. Or use environments. Or create 4 repositories: 1 for the shared theme/config, and the others for each site.