Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Hugo demo site does not update theme #7

Closed
so1ve opened this issue Jun 20, 2020 · 23 comments
Closed

Hugo demo site does not update theme #7

so1ve opened this issue Jun 20, 2020 · 23 comments

Comments

@so1ve
Copy link
Collaborator

so1ve commented Jun 20, 2020

Hugo demo site does not update theme, please update submodule.

cc: @digitalcraftsman

@digitalcraftsman
Copy link

digitalcraftsman commented Jun 20, 2020

Hello Ray,

the hugoTheme repository points to the latest commit on the master branch since 11 days. I've rebuild the site for www.themes.gohugo.io with a cleared cache but the build log still show an error message. When running your exampleSite with cd exampleSite && hugo server -t ../.. using Hugo v0.72.0 I get the same error message.

In that regard, the theme site is as up to date as it can be. Please let me know I missed something.

@so1ve
Copy link
Collaborator Author

so1ve commented Jun 21, 2020

Hi, I don't quite understand what is going on...
image

@so1ve
Copy link
Collaborator Author

so1ve commented Jun 21, 2020

Hi, digitalcraftsman.
I don't think you have updated the theme.
image
This is still the version 14 days ago.

@digitalcraftsman
Copy link

As stated above we're pulling commits from the master branch of your repository. The latest commit from master is 003fda5 which is the same hash shown in your screenshot. Should another branch be used for the theme site? Which commit do you expect to be the "latest"?

@so1ve
Copy link
Collaborator Author

so1ve commented Jun 22, 2020

Yes, I think I made a mistake. But why does it produce different compilation results?

@digitalcraftsman
Copy link

Both in my locale machine and in the build log I see the following error message:

6:09:39 PM: Building site for theme hugo-theme-tony using default content to ../themeSite/static/theme/hugo-theme-tony/
6:09:40 PM: Error: Error building site: TOCSS: failed to transform "en/styles/main-rendered.scss" (text/x-scss): resource "scss/scss/main.scss_b30d9fedec997fa1974d814d8e3cd983" not found in file cache

Hugo is looking for a stylesheet called but such a file isn't present in resources/_gen/assets/scss/scss. My guess is that you've modified your stylesheets but didn't commit the newly generated scss file with hash b30d9fedec997fa1974d814d8e3cd983.

For the Hugo theme site the regular version of Hugo (without integrated SCSS compiler) is used. You on the other hand likely using the extended version of Hugo that can compile a new SCSS file if modifications have been detected. The regular Hugo version can't do that.

@so1ve
Copy link
Collaborator Author

so1ve commented Jun 23, 2020

1
Can you help me solve this problem?

@digitalcraftsman
Copy link

The exnteded version of Hugo (0.72.0) generates the stylesheet main.scss_b30d9fedec997fa1974d814d8e3cd983 when creating a new site that uses your theme:

hugo new site foo
cd foo
git clone https://github.com/ThemeTony/hugo-theme-tony themes/tony
cp themes/tony/exampleSite/config.toml .
hugo

Afterwards I see the new stylesheets under foo/_gen/assets/scss/scss:

> ls _gen/assets/scss/scss
main.scss_b30d9fedec997fa1974d814d8e3cd983.content  main.scss_b30d9fedec997fa1974d814d8e3cd983.json

Those would only have to be copied to the corresponding folder in this repository.

As far as I can see in your gif your are on the site-source branch. Are the stylesheets on this branch different/older than on the master branch? That might explain why no new stylesheets are generated for your.

@so1ve
Copy link
Collaborator Author

so1ve commented Jun 26, 2020

Hello, I have updated the theme. Please try to pull the code?

@digitalcraftsman
Copy link

I've pulled your latest changes and looked at them. But in order to fix the error message you have to commit the following files:

  • main.scss_b30d9fedec997fa1974d814d8e3cd983.content
  • main.scss_b30d9fedec997fa1974d814d8e3cd983.json

You may have to use the files present in the master branch and to run Hugo in the extended version in order to get these stylesheets.

@so1ve
Copy link
Collaborator Author

so1ve commented Jun 27, 2020

But my scss file here is still main.scss_2abeb0f3c9ce7af11570a3c4f0f748a5.json and main.scss_2abeb0f3c9ce7af11570a3c4f0f748a5.content.

@digitalcraftsman
Copy link

I guess I've found the reason the different hash values. Both stylesheets on the master and site-source branch are identical (which I suspected to be the reason). However, before generating the fingerprint for the stylesheet you can see that in one stage the asset pipline depends on the .Lang variable:

 resources.ExecuteAsTemplate (printf "%s/styles/main-rendered.scss" .Lang)

For the Hugo theme site the defaultContentLanguage is set to en while your demo on the site-source branch uses zh as defaultContentLanguage. To verify this I've changed zh to en and got the hash value b30d9fedec997fa1974d814d8e3cd983.

@so1ve
Copy link
Collaborator Author

so1ve commented Jun 27, 2020

Okay, thank you very much! ! ! ! ! ! ! I will fix this problem soon.

@so1ve
Copy link
Collaborator Author

so1ve commented Jun 28, 2020

Fixed, please try to pull the code?

@digitalcraftsman
Copy link

In case you've not noticed: aaf7072#r40273020

@digitalcraftsman
Copy link

Hello Ray,

the changes in aaf7072 (20 days ago) were fine and fixed the problem by removing .Lang. In e01e218#diff-cdeb1af1874b1a8f2273f1950c8eba00R6 however the path to the stylesheet has again been made dependent on . (aka the context), whose value might change for different pages and thus creates a different hash.

This can be fixed the same was as before: see aaf7072#r40273020

To clarify your intentions: why did chose .Lang as prefix for the path to the stylesheet the first time? Do you intended to display different stylesheets depending on the language? Regarding the latest changes: why did you prefix the path now with the contents of .?

@so1ve
Copy link
Collaborator Author

so1ve commented Jul 18, 2020

Hello, @digitalcraftsman.
In fact, I don’t know much about hugo's templates. I actually just help my friends transplant themes, so I just copied the styles.html of hugo-theme-meme...

@digitalcraftsman
Copy link

Thank you for pointing to your source. I've done a bit of reasearch:

The meme theme uses template logic in the stylesheets as well (see here) with a focus on i18n. This way the stylesheet could look different in each language, depending on your content file.

As stated in the docs, the second argument of ExecuteTemplateAs is the target path. Therefore, the language prefix has to be added because all files for the chinese version of a website might end up in /zh/css/styles.min.css, not in /css/styles.min.css.

Even if the config is the same across all languages the hash for the stylesheets (one per language) is still different, because all three arguments to ExecuteTemplateAs will be used as cache key and thus in a different hash.

Because you changed the second argument for ExecuteTemplateAs (i.e. the target path of the rendered css file) in e01e218#diff-cdeb1af1874b1a8f2273f1950c8eba00R6 the hash changed as well. This in turn acutally creates a new CSS file that has to be commited. Otherwise Hugo is unable to find the stylesheet and throws an error.


As I learned this now it should be fine to use resources.ExecuteAsTemplate (printf "%s/styles/main-rendered.scss" .Lang) if you intend to have a website that uses multiple languages. Just remember: everytime you change the last code snippet or modify the stylesheets a stylesheet with a new hash in it's filename is created, that has to be comitted. And always generate the stylesheets for the master branch on the master branch.

Otherwise we face our initial issue that on the master branch the defaultContentLanguage (and therefore .Lang) is set to en, while on the master branch the defaultContentLanguage is set to zh.

@so1ve
Copy link
Collaborator Author

so1ve commented Jul 18, 2020

Okay, thanks for your analysis. I have pushed the latest code, can you try pull?

@digitalcraftsman
Copy link

With your latest changes the master branch doesn't contain a valid theme structure anymore (i.e. after running hugo new theme <name> from which a demo could be generated.

The source branch for the demo has to have the same structure as in https://github.com/ThemeTony/hugo-theme-tony/tree/e01e218e56dfa5a003dd6bee89a020c0fe437e14

@so1ve
Copy link
Collaborator Author

so1ve commented Jul 18, 2020

It was my fault... I accidentally pushed the demo site and it has now been fixed.

@digitalcraftsman
Copy link

Thanks. Your theme is already live again on www.themes.gohugo.io

@so1ve
Copy link
Collaborator Author

so1ve commented Jul 18, 2020

Okey, thank you very much.

@so1ve so1ve closed this as completed Jul 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants