diff --git a/docs/src/components/AttributeCard.astro b/docs/src/components/AttributeCard.astro index 6550f9ce..dba99359 100644 --- a/docs/src/components/AttributeCard.astro +++ b/docs/src/components/AttributeCard.astro @@ -3,6 +3,7 @@ import PiiBadge from './PiiBadge.astro'; import VisibilityBadge from './VisibilityBadge.astro'; import OtelBadge from './OtelBadge.astro'; import TypeBadge from './TypeBadge.astro'; +import AttributeLink from './AttributeLink.astro'; import type { Attribute } from '../content.config'; import { parseAttributeId } from '../utils/category'; @@ -76,7 +77,7 @@ const rawJson = JSON.stringify(attribute, null, 2);
{a})}
+ {attribute.alias.map((a) => Use {attribute.deprecation.replacement} instead.
Use
No replacement available at this time.
)} diff --git a/docs/src/components/AttributeLink.astro b/docs/src/components/AttributeLink.astro new file mode 100644 index 00000000..f23e09d9 --- /dev/null +++ b/docs/src/components/AttributeLink.astro @@ -0,0 +1,12 @@ +--- +import { attributeUrl } from '../utils/attributeUrl'; + +interface Props { + name: string; +} + +const { name } = Astro.props; +const href = attributeUrl(name, import.meta.env.BASE_URL); +--- + +{name}
diff --git a/docs/src/components/LinkedTemplate.astro b/docs/src/components/LinkedTemplate.astro
new file mode 100644
index 00000000..08e6ffba
--- /dev/null
+++ b/docs/src/components/LinkedTemplate.astro
@@ -0,0 +1,49 @@
+---
+/**
+ * Renders a span name template string, turning `{{attribute.key}}`
+ * placeholders into clickable links to the corresponding attribute page.
+ */
+import { attributeUrl } from '../utils/attributeUrl';
+
+interface Props {
+ template: string;
+}
+
+const { template } = Astro.props;
+
+const PLACEHOLDER = /\{\{([^}]+)\}\}/g;
+
+interface Segment {
+ type: 'text' | 'link';
+ value: string;
+}
+
+const segments: Segment[] = [];
+let lastIndex = 0;
+
+for (const match of template.matchAll(PLACEHOLDER)) {
+ if (match.index > lastIndex) {
+ segments.push({ type: 'text', value: template.slice(lastIndex, match.index) });
+ }
+ segments.push({ type: 'link', value: match[1] });
+ lastIndex = match.index + match[0].length;
+}
+
+if (lastIndex < template.length) {
+ segments.push({ type: 'text', value: template.slice(lastIndex) });
+}
+
+const hasPlaceholders = segments.some((s) => s.type === 'link');
+---
+
+{hasPlaceholders ? (
+ segments.map((seg) =>
+ seg.type === 'link' ? (
+ {`{{${seg.value}}}`}
+ ) : (
+ {m.data.attribute}
-
+ {template}
- {index === op.templates.length - 1 && !template.includes('{{') && (
+ index === op.templates.length - 1 && !tmpl.includes('{{') ? 'border border-accent' : ''
+ ]}>