Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow loading cover from /assets folder #1187

Merged

Conversation

timonback
Copy link
Contributor

What does this PR change? What problem does it solve?

My initial issue is that I store all cover images in the /assets folder, separate from my posts (to be precise, I even store them via git submodules in a different git repo). I still want to benefit from the Hugo Pipes image processing to render different image sizes.

Behaviour after the change:
By default, the cover is loaded from the page resources folder (same folder). If the image is not found, the (global) /assets folder is searched as well. If found, the same processing is done. Otherwise, the fallback remains with linking to the image directly.

Tested with hugo v0.111.3+extended
Hugo Pipes Docs (incl. /assets folder): https://gohugo.io/hugo-pipes/introduction/#asset-directory

PR Checklist

  • This change adds/updates translations and I have used the template present here.
  • I have enabled maintainer edits for this PR.
  • I have verified that the code works as described/as intended.
  • This change adds a Social Icon which has a permissive license to use it.
  • This change does not include any CDN resources/links.
  • This change does not include any unrelated scripts such as bash and python scripts.
  • This change updates the overridden internal templates from HUGO's repository.

By default, the cover is loaded from the page resources folder (same folder).
If the image is not found, the (global) assets folder is searched as well. If found, the same processing is done.
Otherwise, the fallback remains with linking to the image directly.
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Owner

@adityatelange adityatelange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timonback Thanks! This was really missing.

@adityatelange adityatelange merged commit d6f911c into adityatelange:master Apr 28, 2023
romainx pushed a commit to romainx/hugo-PaperMod that referenced this pull request May 1, 2023
By default, the cover is loaded from the page resources folder (same folder).
If the image is not found, the (global) assets folder is searched as well. If found, the same processing is done.
Otherwise, the fallback remains with linking to the image directly.
@git-clone-abhinav
Copy link

git-clone-abhinav commented May 1, 2023

@timonback Appreciate the contrib.

Wondering why I am getting this error while compiling with hugo --minify. I am not sure if this is due to my front-matter settings or some other stuff.

Start building sites … 
hugo v0.92.2+extended linux/amd64 BuildDate=2023-01-31T11:11:57Z VendorInfo=ubuntu:0.92.2-1ubuntu0.1
ERROR 2023/05/01 23:25:54 render of "page" failed: execute of template failed: template: _default/single.html:25:6: executing "main" at <partial "cover.html" (dict "cxt" . "IsHome" false "isHidden" $isHidden)>: error calling partial: "<path_to_my_site>/themes/PaperMod/layouts/partials/cover.html:8:34": execute of template failed: template: partials/cover.html:8:34: executing "partials/cover.html" at <resources>: can't evaluate field ByType in type interface {}
ERROR 2023/05/01 23:25:54 render of "page" failed: execute of template failed: template: _default/single.html:25:6: executing "main" at <partial "cover.html" (dict "cxt" . "IsHome" false "isHidden" $isHidden)>: error calling partial: "<path_to_my_site>/themes/PaperMod/layouts/partials/cover.html:8:34": execute of template failed: template: partials/cover.html:8:34: executing "partials/cover.html" at <resources>: can't evaluate field ByType in type interface {}
ERROR 2023/05/01 23:25:54 render of "page" failed: execute of template failed: template: _default/single.html:25:6: executing "main" at <partial "cover.html" (dict "cxt" . "IsHome" false "isHidden" $isHidden)>: error calling partial: "<path_to_my_site>/themes/PaperMod/layouts/partials/cover.html:8:34": execute of template failed: template: partials/cover.html:8:34: executing "partials/cover.html" at <resources>: can't evaluate field ByType in type interface {}
ERROR 2023/05/01 23:25:54 render of "page" failed: execute of template failed: template: _default/single.html:25:6: executing "main" at <partial "cover.html" (dict "cxt" . "IsHome" false "isHidden" $isHidden)>: error calling partial: "<path_to_my_site>/themes/PaperMod/layouts/partials/cover.html:8:34": execute of template failed: template: partials/cover.html:8:34: executing "partials/cover.html" at <resources>: can't evaluate field ByType in type interface {}
Error: Error building site: failed to render pages: render of "page" failed: execute of template failed: template: _default/single.html:25:6: executing "main" at <partial "cover.html" (dict "cxt" . "IsHome" false "isHidden" $isHidden)>: error calling partial: "<path_to_my_site>/themes/PaperMod/layouts/partials/cover.html:8:34": execute of template failed: template: partials/cover.html:8:34: executing "partials/cover.html" at <resources>: can't evaluate field ByType in type interface {}
Total in 280 ms

I reverted your commit on my local copy of the repository and stuff seems to work. Any idea what could be the cause ?

Thanks and Regards
Abhinav

@timonback
Copy link
Contributor Author

Hi @git-clone-abhinav,
My understanding is, that the resources feature was added with https://github.com/gohugoio/hugo/releases/tag/v0.90.0

I had no issues when testing locally, although with a newer version as mentioned above. Not sure if it is feasible to update Hugo - just for verification?

@git-clone-abhinav
Copy link

update Hugo - just for verification?

Updated Hugo to Hugo Latest Release v0.111.3. The problem seem to revolve around older Hugo version. The commit works like butter now.

Note :
Older not supported version : Hugo v0.92.2
Updated Supported version : Hugo v0.111.3

Thanks and Regards
Abhinav

@adityatelange
Copy link
Owner

Thank you for identifying this.

@timonback @git-clone-abhinav Can we find out the minimum hugo version required for this patch to work well?

@git-clone-abhinav
Copy link

git-clone-abhinav commented May 1, 2023

Can we find out the minimum hugo version required for this patch to work well?

Okay, so I tested with some Hugo versions, however I skipped some too in order to make the process faster. The minimum required Hugo Version is v0.97.0, binaries of which can be downloaded from here

The table below provides more details of the tests in the order they were performed. Binaries that I used were downloaded in the following name pattern : hugo_<Hugo Version>_Linux-64bit.tar.gz

Test No. Hugo Version Patch support Remarks
1 Hugo v0.92.2 My original machine
2 Hugo v0.111.3 ✔️ My Update (current latest)
3 Hugo v0.109.0 ✔️
4 Hugo v0.102.0 ✔️
5 Hugo v0.99.0 ✔️
6 Hugo v0.96.0
7 Hugo v0.97.0 ✔️ Minimum Hugo version for this patch to work

My Local Machine :

uname -r

5.19.0-41-generic

cat /etc/os-release | head -n7

PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian

@adityatelange Thanks for this amazing theme.

Regards
Abhinav

@adityatelange
Copy link
Owner

Thank you @git-clone-abhinav for the test :)
Will update min hugo version in docs

adityatelange added a commit that referenced this pull request May 7, 2023
romainx pushed a commit to romainx/hugo-PaperMod that referenced this pull request Jun 5, 2023
jdxgfty pushed a commit to jdxgfty/hugo-PaperMod that referenced this pull request Nov 3, 2024
By default, the cover is loaded from the page resources folder (same folder).
If the image is not found, the (global) assets folder is searched as well. If found, the same processing is done.
Otherwise, the fallback remains with linking to the image directly.
jdxgfty pushed a commit to jdxgfty/hugo-PaperMod that referenced this pull request Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants