Is it Possible to Specify Featured Image in Markdown Files and Use a Centralized Image Location? #1672
-
I have a question regarding the handling of featured images in the Blowfish Hugo theme. Currently, it appears that the featured image must be saved in the same directory as the markdown file. I’m wondering if there is a way to specify the featured image directly within the markdown file and place the images in a centralized location, such as a general uploads directory. Specific Questions:Featured Image URLIs it possible to specify the URL of the featured image within the markdown file, rather than requiring the image to be in the same directory? Example Markdown File (content/posts/example-post.md):
Centralized Image StorageCan the theme be configured to use a general image directory (e.g., Example Image Location:
Template ModificationsIf this feature is not currently supported, what changes would be needed to the Hugo templates to accommodate this approach? ContextThe goal is to streamline image management by keeping all images in a centralized location, making it easier to organize and manage content without cluttering the markdown directories with images. Any guidance or suggestions on how to achieve this would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I am implementing exactly this in my PR. First fo all, the file # This looks for an image with the substring `feature` in its name in your article's folder.
# If no luck, it tries the substrings `cover` and `thumbnail`.
{{- $images := .Resources.ByType "image" -}}
{{- $featured := $images.GetMatch "*feature*" -}}
{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
# If still no luck, it checks if the front matter parameter `featureimage` is declared.
# It defines a URL of an image and is documented in `https://blowfish.page/docs/front-matter/`.
# Usage example: `featureimage: "https://raw.githubusercontent.com/nunocoracao/blowfish/main/images/screenshot.png"
{{ if .Params.featureimage }}
{{- $url:= .Params.featureimage -}}
{{- if not $featured }}{{ $featured = resources.GetRemote $url }}{{ end -}}
{{ end }} But I still needed a way to include generic featured images. The steps to do it are as follows:
The priorities for finding an image from highest to lowest are (1) image in article's folder, (2) Relevant resources: |
Beta Was this translation helpful? Give feedback.
I am implementing exactly this in my PR.
First fo all, the file
themes/blowfish/layouts/partials/hero/basic.html
contains the following code (the comments are mine):