feat: componenti T e TImg per contenuti taggati

This commit is contained in:
2026-07-05 15:46:11 +02:00
parent b22cc40b03
commit b079ded266
2 changed files with 25 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
---
import { resolveContent } from '../../lib/content';
interface Props { tag: string; as?: string; class?: string }
const { tag, as = 'span', class: cls } = Astro.props;
const Tag = as;
const c = resolveContent(tag);
const classes = [cls, c.classes].filter(Boolean).join(' ') || undefined;
---
{c.type === 'html'
? <Tag data-tag={tag} class={classes} set:html={c.value} />
: <Tag data-tag={tag} class={classes}>{c.value}</Tag>}
+14
View File
@@ -0,0 +1,14 @@
---
import { Image } from 'astro:assets';
import type { ImageMetadata } from 'astro';
import { getImageOverride } from '../../lib/content';
interface Props {
tag: string; src: ImageMetadata; alt: string;
class?: string; loading?: 'lazy' | 'eager'; widths?: number[]; sizes?: string;
}
const { tag, src, alt, class: cls, ...rest } = Astro.props;
const override = getImageOverride(tag);
---
{override
? <img src={override} alt={alt} class={cls} data-tag={tag} loading={rest.loading} />
: <Image src={src} alt={alt} class={cls} data-tag={tag} {...rest} />}