@astrojs/markdoc@0.9.0
版本发布时间: 2024-02-12 22:27:21
withastro/astro最新发布版本:astro@4.16.16(2024-11-27 22:22:39)
Minor Changes
-
#9958
14ce8a6ebfc9daf951d2dca54737d857c229667c
Thanks @Princesseuh! - Adds support for using a custom tag (component) for optimized imagesStarting from this version, when a tag called
image
is used, itssrc
attribute will automatically be resolved if it's a local image. Astro will pass the resultImageMetadata
object to the underlying component as thesrc
prop. For non-local images (i.e. images using URLs or absolute paths), Astro will continue to pass thesrc
as a string.// markdoc.config.mjs import { component, defineMarkdocConfig, nodes } from '@astrojs/markdoc/config'; export default defineMarkdocConfig({ tags: { image: { attributes: nodes.image.attributes, render: component('./src/components/MarkdocImage.astro'), }, }, });
--- // src/components/MarkdocImage.astro import { Image } from 'astro:assets'; interface Props { src: ImageMetadata | string; alt: string; width: number; height: number; } const { src, alt, width, height } = Astro.props; --- <Image {src} {alt} {width} {height} />
{% image src="./astro-logo.png" alt="Astro Logo" width="100" height="100" %}