How to have cover image in frontmatter? #82
-
For a portfolio type site, is there a simple way to put an image as frontmatter? So if have In dev mode this works: extendFrontmatter (frontmatter, filename) {
frontmatter.cover = filename.slice(0, filename.lastIndexOf('/') + 1) + frontmatter.cover
}, But the filename will break in prod, since it's not actually processed. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
@luminarious There are different ways to achieve this, depending on what you need. Direct ReferencesThe simplest way would be to put the images in cover: /images/specific-project/project.jpg Shorter ReferencesUsing cover: project.jpg Dynamic ReferencesYou could use It has no runtime cost if you are using îles, but the code is not pretty. On the other hand, it has the advantage of using fingerprinted assets, so you can use
|
Beta Was this translation helpful? Give feedback.
-
I tried the third version as the most mobile-friendly, but there seems to be some issue with the @islands/images plugin itself? I tried programmatic paths and hard-coded paths but all cases return this:
|
Beta Was this translation helpful? Give feedback.
@luminarious There are different ways to achieve this, depending on what you need.
Direct References
The simplest way would be to put the images in
public
, and reference the full public path in the frontmatter. Example:Shorter References
Using
extendFrontmatter
(as in your example) you could modifycover
to achieve the same result, but without specifying the full path:Dynamic References
You could use
import.meta.globEager
to obtain a fingerprinted path to all images, and then index that using themeta.filename
or frontmatter information.It has no runtime cost if you are using îles, but the code is not pretty. On the other h…