ThemeTony / hugo-theme-tony

【不更新新内容了 / Not Maintaining】An Elegant Hugo Theme Based on WordPress Theme Tony ✌️ | 一个简洁强大的 Hugo 博客主题
https://htony.js.org/
GNU General Public License v3.0
27 stars 4 forks source link

Hugo demo site does not update theme #7

Closed so1ve closed 4 years ago

so1ve commented 4 years ago

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

cc: @digitalcraftsman

digitalcraftsman commented 4 years ago

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 commented 4 years ago

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

so1ve commented 4 years ago

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

digitalcraftsman commented 4 years ago

As stated above we're pulling commits from the master branch of your repository. The latest commit from master is https://github.com/ThemeTony/hugo-theme-tony/commit/003fda5f0a5b2820601e8d9ff511a667f3ad581d 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 commented 4 years ago

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

digitalcraftsman commented 4 years ago

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 commented 4 years ago

1 Can you help me solve this problem?

digitalcraftsman commented 4 years ago

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 commented 4 years ago

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

digitalcraftsman commented 4 years ago

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:

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 commented 4 years ago

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

digitalcraftsman commented 4 years ago

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 commented 4 years ago

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

so1ve commented 4 years ago

Fixed, please try to pull the code?

digitalcraftsman commented 4 years ago

In case you've not noticed: https://github.com/ThemeTony/hugo-theme-tony/commit/aaf70728cacdb51083d7894b82b407a9f643e299#r40273020

digitalcraftsman commented 4 years ago

Hello Ray,

the changes in https://github.com/ThemeTony/hugo-theme-tony/commit/aaf70728cacdb51083d7894b82b407a9f643e299 (20 days ago) were fine and fixed the problem by removing .Lang. In https://github.com/ThemeTony/hugo-theme-tony/commit/e01e218e56dfa5a003dd6bee89a020c0fe437e14#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 https://github.com/ThemeTony/hugo-theme-tony/commit/aaf70728cacdb51083d7894b82b407a9f643e299#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 commented 4 years ago

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 commented 4 years ago

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 https://github.com/ThemeTony/hugo-theme-tony/commit/e01e218e56dfa5a003dd6bee89a020c0fe437e14#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 commented 4 years ago

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

digitalcraftsman commented 4 years ago

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 commented 4 years ago

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

digitalcraftsman commented 4 years ago

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

so1ve commented 4 years ago

Okey, thank you very much.