Skip to content

Enhancement: Referencing fallback images in registerCardImage #619

Description

@scottsweb

Is your feature request related to a problem? Please describe.

This may just be a documentation request, but I was hoping to set a default card image for posts without an explicit image set. I have been testing the new registerCardImage hooks with the code below, but cannot work out how to locally serve an alternative image from within VSCodium.

import { registerCardImage, enableDevelopmentMode } from "https://cdn.jsdelivr.net/npm/@frontmatter/extensibility/+esm";
enableDevelopmentMode();

/**
 * @param {string} filePath - The path of the file
 * @param {object} data - The metadata of the file
 * @returns {string} - The HTML to be rendered in the card footer
 */
registerCardImage(async (filePath, metadata) => {
    const image = metadata.fmPreviewImage ? metadata.fmPreviewImage : '/path/to/fallback.jpg';
    return `<img src="${image}" alt="${metadata.title}" style="object-fit: cover;" class="h-36" />`;
});

The default images seem to be prefixed with a local / CDN URL which is probably what I need to do here as well.

Describe the solution you'd like

Some documentation or an example of how to reference images from within these hooks.

Describe alternatives you've considered

Possibly just using an inline SVG as a temporary solution.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions