media
Track
Standalone track or recording with metadata
Install
- Add the package:
npm install @refrakt-md/media - Add it to the
pluginsarray inrefrakt.config.json:"plugins": ["@refrakt-md/media"]
Source
import Markdoc from '@markdoc/markdoc';
import type { RenderableTreeNodes } from '@markdoc/markdoc';
const { Tag } = Markdoc;
import {
createContentModelSchema,
createComponentRenderable,
renderNodes,
SCHEMA_TYPE_EXPLICIT,
textContent,
} from '@refrakt-md/runes';
import { parseDuration } from '../duration.js';
const trackType = ['song', 'episode', 'chapter', 'talk', 'video'] as const;
export const TYPE_IMPLICIT = SCHEMA_TYPE_EXPLICIT;
const trackCommon = {
name: 'name',
duration: 'duration',
url: 'url',
position: 'position',
date: 'datePublished',
} as const;
export const trackSchema = {
by: 'type',
rows: {
song: { type: 'MusicRecording', properties: { ...trackCommon, artist: 'byArtist' } },
episode: { type: 'PodcastEpisode', properties: trackCommon },
chapter: { type: 'Chapter', properties: trackCommon },
talk: { type: 'CreativeWork', properties: trackCommon },
video: { type: 'VideoObject', properties: trackCommon },
},
fallback: { type: 'MusicRecording', properties: { ...trackCommon, artist: 'byArtist' } },
};
export const track = createContentModelSchema({
schema: trackSchema,
attributes: {
src: {
type: String,
required: false,
description: 'URL of the audio or video file for this track.',
},
artist: {
type: String,
required: false,
description: 'Performer or creator name for this track.',
},
duration: {
type: String,
required: false,
description: 'Track length in m:ss, h:mm:ss, or ISO 8601 duration format.',
},
number: {
type: Number,
required: false,
description: 'Position number of the track in its parent listing.',
},
date: {
type: String,
required: false,
description: 'Publication or release date for the track.',
},
url: {
type: String,
required: false,
description: 'External link to the track on a streaming platform or website.',
},
type: {
type: String,
required: false,
matches: trackType.slice(),
description: 'Media category: song, episode, chapter, talk, or video.',
},
meta: {
type: String,
required: false,
matches: ['row', 'byline'],
description:
'Where the artist, date and running time sit: in the row beside the name (`row`), or beneath it (`byline`). A playlist passes its own to its tracks.',
},
},
contentModel: {
type: 'sequence',
fields: [
{ name: 'title', match: 'heading|paragraph', optional: true },
{ name: 'body', match: 'any', optional: true, greedy: true },
],
},
transform(resolved, attrs, config) {
const src = (attrs.src as string) ?? '';
const artist = (attrs.artist as string) ?? '';
const duration = (attrs.duration as string) ?? '';
const number = attrs.number as number | undefined;
const date = (attrs.date as string) ?? '';
const url = (attrs.url as string) ?? '';
// An absent `type` stays absent, so a nested track can take its playlist's.
const explicitType = attrs.type as string | undefined;
const typeValue = explicitType ?? 'song';
const titleNodes = renderNodes(resolved.title, config);
let nameText = '';
const headingCursor = titleNodes.headings().limit(1);
if (headingCursor.count() > 0) {
nameText = textContent(headingCursor.next());
} else {
const pCursor = titleNodes.tag('p').limit(1);
if (pCursor.count() > 0) nameText = textContent(pCursor.next());
}
const bodyNodes = renderNodes(resolved.body, config);
const nameTag = new Tag('span', { 'data-name': 'track-name' }, [nameText]);
const children: any[] = [nameTag];
const typeMeta = new Tag('meta', { content: typeValue });
if (bodyNodes.count() > 0) {
children.push(bodyNodes.wrap('div', { 'data-name': 'track-description' }).next());
}
const rootAttrs: Record<string, any> = {};
if (src) rootAttrs['data-src'] = src;
const durationMeta = duration
? new Tag('meta', {
content: duration.startsWith('PT') ? duration : `PT${parseDuration(duration)}S`,
})
: undefined;
const artistMeta = artist ? new Tag('meta', { content: artist }) : undefined;
const urlMeta = url ? new Tag('meta', { content: url }) : undefined;
const numberMeta =
number !== undefined ? new Tag('meta', { content: String(number) }) : undefined;
const dateMeta = date ? new Tag('meta', { content: date }) : undefined;
const metaMeta = attrs.meta ? new Tag('meta', { content: attrs.meta as string }) : undefined;
const renderable = createComponentRenderable({
rune: 'track',
tag: 'li',
properties: {
name: nameTag,
artist: artistMeta,
duration: durationMeta,
url: urlMeta,
position: numberMeta,
date: dateMeta,
type: typeMeta,
meta: metaMeta,
},
children,
});
Object.assign((renderable as any).attributes, rootAttrs);
if (explicitType !== undefined) (renderable as any)[TYPE_IMPLICIT] = true;
return renderable;
},
});
A single song or podcast episode, with its artist, running time and date, on its own or inside a playlist. For a list of tracks, use playlist; to play a file, audio.
Basic usage
A single track with artist and duration.
{% track artist="Radiohead" duration="4:01" type="song" %}
# Everything in Its Right Place
{% /track %}<li data-rune="track" data-rune-fields="{"artist":"Radiohead","duration":"PT241S","type":"song"}" typeof="MusicRecording">
<span data-name="track-name" data-field="name" property="name">Everything in Its Right Place</span>
<meta property="duration" content="PT241S">
<meta property="byArtist" content="Radiohead">
</li><li class="rf-track" typeof="MusicRecording" data-meta="row" data-artist="Radiohead" data-duration="PT241S" data-elevation="flat" data-rune="track" data-density="full">
<span data-name="track-name" data-field="name" property="name" class="rf-track__track-name">Everything in Its Right Place</span>
<div data-name="details" data-zone="details" data-zone-layout="bar" class="rf-track__details">
<span data-field="artist">Radiohead</span>
<span data-meta-type="quantity" data-align="end" data-field="duration">4:01</span>
</div>
<meta property="duration" content="PT241S" />
<meta property="byArtist" content="Radiohead" />
</li>How Markdown is read
| You write | It becomes |
|---|---|
| A heading | The track's name |
| Everything after it | The track's description or show notes |
Byline
The artist, date and running time sit along the track's row by default. meta="byline" sets them beneath the name instead.
{% track artist="Radiohead" duration="4:01" date="2000" meta="byline" %}
# Everything in Its Right Place
{% /track %}<li data-rune="track" data-rune-fields="{"artist":"Radiohead","duration":"PT241S","date":"2000","type":"song","meta":"byline"}" typeof="MusicRecording">
<span data-name="track-name" data-field="name" property="name">Everything in Its Right Place</span>
<meta property="duration" content="PT241S">
<meta property="datePublished" content="2000">
<meta property="byArtist" content="Radiohead">
</li><li class="rf-track" typeof="MusicRecording" data-meta="byline" data-artist="Radiohead" data-duration="PT241S" data-date="2000" data-elevation="flat" data-rune="track" data-density="full">
<div data-name="heading" class="rf-track__heading">
<span data-name="track-name" data-field="name" property="name" class="rf-track__track-name">Everything in Its Right Place</span>
<div data-name="details" data-zone="details" data-zone-layout="bar" class="rf-track__details">
<span data-field="artist">Radiohead</span>
<span data-meta-type="temporal" data-field="date">2000</span>
<span data-meta-type="quantity" data-field="duration">4:01</span>
</div>
</div>
<meta property="duration" content="PT241S" />
<meta property="datePublished" content="2000" />
<meta property="byArtist" content="Radiohead" />
</li>Podcast episode
Use type="episode" for podcast episodes with a date.
{% track type="episode" artist="Tech Weekly" duration="42:30" date="March 2025" %}
# The Future of Web Standards
{% /track %}<li data-rune="track" data-rune-fields="{"artist":"Tech Weekly","duration":"PT2550S","date":"March 2025","type":"episode"}" typeof="PodcastEpisode">
<span data-name="track-name" data-field="name" property="name">The Future of Web Standards</span>
<meta property="duration" content="PT2550S">
<meta property="datePublished" content="March 2025">
</li><li class="rf-track" typeof="PodcastEpisode" data-meta="row" data-artist="Tech Weekly" data-duration="PT2550S" data-date="March 2025" data-elevation="flat" data-rune="track" data-density="full">
<span data-name="track-name" data-field="name" property="name" class="rf-track__track-name">The Future of Web Standards</span>
<div data-name="details" data-zone="details" data-zone-layout="bar" class="rf-track__details">
<span data-field="artist">Tech Weekly</span>
<span data-meta-type="quantity" data-align="end" data-field="duration">42:30</span>
<span data-meta-type="temporal" data-field="date">March 2025</span>
</div>
<meta property="duration" content="PT2550S" />
<meta property="datePublished" content="March 2025" />
</li>With body content
Tracks can include additional body content like descriptions or show notes.
{% track artist="Miles Davis" duration="9:22" type="song" %}
# So What
The opening track from *Kind of Blue*, featuring the iconic two-chord modal structure that changed jazz forever.
{% /track %}<li data-rune="track" data-rune-fields="{"artist":"Miles Davis","duration":"PT562S","type":"song"}" typeof="MusicRecording">
<span data-name="track-name" data-field="name" property="name">So What</span>
<div data-name="track-description">
<p>
The opening track from
<em marker="*">Kind of Blue</em>
, featuring the iconic two-chord modal structure that changed jazz forever.
</p>
</div>
<meta property="duration" content="PT562S">
<meta property="byArtist" content="Miles Davis">
</li>The opening track from Kind of Blue, featuring the iconic two-chord modal structure that changed jazz forever.
<li class="rf-track" typeof="MusicRecording" data-meta="row" data-artist="Miles Davis" data-duration="PT562S" data-elevation="flat" data-rune="track" data-density="full">
<span data-name="track-name" data-field="name" property="name" class="rf-track__track-name">So What</span>
<div data-name="details" data-zone="details" data-zone-layout="bar" class="rf-track__details">
<span data-field="artist">Miles Davis</span>
<span data-meta-type="quantity" data-align="end" data-field="duration">9:22</span>
</div>
<div data-name="track-description" class="rf-track__track-description">
<p>
The opening track from
<em marker="*">Kind of Blue</em>
, featuring the iconic two-chord modal structure that changed jazz forever.
</p>
</div>
<meta property="duration" content="PT562S" />
<meta property="byArtist" content="Miles Davis" />
</li>Inside a playlist
A {% track %} written inside a {% playlist %} becomes one of that playlist's tracks — in the listing, in the HTML, and in the structured data. Use it when the list format is too limited: body content, per-track links, or cue points with prose.
It costs nothing to switch. A nested track that states no type takes the playlist's kind, and inherits the playlist's artist the way a list item does, so the same track written either way produces the same structured data. The longer form may carry more; it never carries less.
{% playlist type="podcast" artist="Tech Weekly" %}
# Design Systems Weekly
- **Token Architecture** (38:15) — February 2025
{% track duration="45:30" date="March 2025" url="https://example.com/ep-12" %}
# Component Libraries at Scale
Why component libraries stall at the second team, and what to do about it.
{% /track %}
{% /playlist %}<section data-rune="playlist" data-rune-fields="{"type":"podcast","media-position":"top","artist":"Tech Weekly"}" typeof="PodcastSeries" data-schema-lists="["hasPart"]">
<h1 id="design-systems-weekly" data-name="headline" property="name">Design Systems Weekly</h1>
<ol data-name="tracks">
<li data-rune="track" data-rune-fields="{"artist":"Tech Weekly","duration":"PT2295S","date":"February 2025"}" elevation="flush" data-field="track" typeof="PodcastEpisode" property="hasPart">
<span data-name="track-name" property="name">Token Architecture</span>
<meta data-name="artist" content="Tech Weekly">
<meta data-name="duration" content="PT2295S" property="duration">
<meta data-name="date" content="February 2025" property="datePublished">
</li>
<li data-rune="track" data-rune-fields="{"duration":"PT2730S","url":"https://example.com/ep-12","date":"March 2025","type":"episode","artist":"Tech Weekly"}" typeof="PodcastEpisode" elevation="flush" data-field="track" property="hasPart">
<span data-name="track-name" data-field="name" property="name">Component Libraries at Scale</span>
<div data-name="track-description">
<p>Why component libraries stall at the second team, and what to do about it.</p>
</div>
<meta content="Tech Weekly" data-name="artist">
<meta property="duration" content="PT2730S">
<meta property="datePublished" content="March 2025">
<meta property="url" content="https://example.com/ep-12">
</li>
</ol>
</section>Design Systems Weekly
- 1Token ArchitectureTech Weekly38:15February 2025
- 2Component Libraries at ScaleTech Weekly45:30March 2025
Why component libraries stall at the second team, and what to do about it.
<section class="rf-playlist rf-playlist--podcast" typeof="PodcastSeries" data-schema-lists="["hasPart"]" data-type="podcast" data-media-position="top" data-artist="Tech Weekly" data-elevation="flat" data-rune="playlist" data-density="full">
<div data-name="content" class="rf-playlist__content">
<div data-name="eyebrow" data-zone="eyebrow" data-zone-layout="bar" class="rf-playlist__eyebrow">
<span data-meta-type="category" data-field="type">podcast</span>
</div>
<header data-name="preamble" class="rf-playlist__preamble" data-section="preamble">
<h1 id="design-systems-weekly" data-name="headline" property="name" class="rf-playlist__headline" data-section="title">Design Systems Weekly</h1>
</header>
<ol data-name="tracks" data-sequence="numbered" class="rf-playlist__tracks">
<li data-field="track" typeof="PodcastEpisode" property="hasPart" data-meta="row" data-artist="Tech Weekly" data-duration="PT2295S" data-date="February 2025" data-elevation="flush" class="rf-track" data-rune="track" data-density="full">
<span data-name="ordinal" data-meta-type="quantity" class="rf-track__ordinal">1</span>
<span data-name="track-name" property="name" class="rf-track__track-name">Token Architecture</span>
<div data-name="details" data-zone="details" data-zone-layout="bar" class="rf-track__details">
<span data-field="artist">Tech Weekly</span>
<span data-meta-type="quantity" data-align="end" data-field="duration">38:15</span>
<span data-meta-type="temporal" data-field="date">February 2025</span>
</div>
<meta data-name="artist" content="Tech Weekly" class="rf-track__artist" />
<meta data-name="duration" content="PT2295S" property="duration" class="rf-track__duration" />
<meta data-name="date" content="February 2025" property="datePublished" class="rf-track__date" />
</li>
<li class="rf-track" typeof="PodcastEpisode" data-field="track" property="hasPart" data-meta="row" data-artist="Tech Weekly" data-duration="PT2730S" data-date="March 2025" data-elevation="flush" data-rune="track" data-density="full">
<span data-name="ordinal" data-meta-type="quantity" class="rf-track__ordinal">2</span>
<span data-name="track-name" data-field="name" property="name" class="rf-track__track-name">Component Libraries at Scale</span>
<div data-name="details" data-zone="details" data-zone-layout="bar" class="rf-track__details">
<span data-field="artist">Tech Weekly</span>
<span data-meta-type="quantity" data-align="end" data-field="duration">45:30</span>
<span data-meta-type="temporal" data-field="date">March 2025</span>
</div>
<div data-name="track-description" class="rf-track__track-description">
<p>Why component libraries stall at the second team, and what to do about it.</p>
</div>
<meta content="Tech Weekly" data-name="artist" class="rf-track__artist" />
<meta property="duration" content="PT2730S" />
<meta property="datePublished" content="March 2025" />
<meta property="url" content="https://example.com/ep-12" />
</li>
</ol>
</div>
</section>Both forms can be mixed, and document order is preserved. Two things worth knowing:
- Tracks must be consecutive. The track listing is collected as one run, so prose written between two tracks ends it — anything after that becomes the playlist's body rather than another track.
- An explicit
typealways wins. A{% track type="song" %}inside a podcast stays a song. The attribute means what it says; the playlist only supplies a kind when the track states none.
Attributes
| Attribute | Type | Required | Description |
|---|---|---|---|
src | string | — | URL of the audio or video file for this track. |
artist | string | — | Performer or creator name for this track. |
duration | string | — | Track length in m:ss, h:mm:ss, or ISO 8601 duration format. |
number | number | — | Position number of the track in its parent listing. |
date | string | — | Publication or release date for the track. |
url | string | — | External link to the track on a streaming platform or website. |
type | "song" | "episode" | "chapter" | "talk" | "video" | — | Media category: song, episode, chapter, talk, or video. |
meta | "row" | "byline" | — | Where the artist, date and running time sit: in the row beside the name (`row`), or beneath it (`byline`). A playlist passes its own to its tracks. |
Universal attributes
bg
The background layer: image, video, gradient, flat overlay wash and legibility scrim, in a single injected layer behind the rune's content.
| Attribute | Type | Required | Description |
|---|---|---|---|
bg | string | — | Background preset applied to this block |
bg-from | string | — | Gradient start colour — a semantic token name (→ var(--rf-color-*)) |
bg-gradient | "to-t" | "to-b" | "to-l" | "to-r" | "to-tr" | "to-br" | "to-bl" | "to-tl" | — | Gradient direction (bounded named set) |
bg-gradient-type | "linear" | "radial" | "conic" | — | Gradient type |
bg-to | string | — | Gradient end colour — a semantic token name |
bg-via | string | — | Optional middle gradient stop — a semantic token name |
scrim | "top" | "bottom" | "left" | "right" | "none" | — | Scrim direction (heaviest edge); presence turns the scrim on, "none" opts out of the default cover scrim |
scrim-blur | "none" | "sm" | "md" | "lg" | — | Frost scrim blur amount |
scrim-strength | "sm" | "md" | "lg" | — | Gradient scrim strength |
scrim-tone | "dark" | "light" | — | Whether the scrim darkens (for light text) or lightens (for dark text) |
scrim-type | "gradient" | "frost" | — | Scrim treatment: gradient (default) or frost (backdrop blur) |
elevation
How far the rune sits off the page, from sunken to overlay. The theme decides what each step looks like.
| Attribute | Type | Required | Description |
|---|---|---|---|
elevation | "sunken" | "flush" | "flat" | "raised" | "floating" | "overlay" | "none" | "sm" | "md" | "lg" | — | Surface depth, from sunken to overlay. Deprecated: none, sm, md and lg (read as flat, raised, raised and floating) |
inset
Internal padding override.
| Attribute | Type | Required | Description |
|---|---|---|---|
inset | "flush" | "tight" | "default" | "loose" | "breathe" | — | Inner padding of this block |
motion
Scroll-reveal entrance. You choose its character; the theme decides how it moves.
| Attribute | Type | Required | Description |
|---|---|---|---|
reveal | "none" | "fade" | "slide" | "scale" | "blur" | — | Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography |
stagger | boolean | — | Cascade this block's items in as it reveals (no-op on single-child runes) |
spacing
Block-level rhythm override.
| Attribute | Type | Required | Description |
|---|---|---|---|
spacing | "flush" | "tight" | "default" | "loose" | "breathe" | — | Vertical spacing above and below this block |
substrate
Generated pattern fills behind the content, drawn by the theme.
| Attribute | Type | Required | Description |
|---|---|---|---|
substrate | "dots" | "grid" | "lines" | "cross" | "checker" | "none" | — | Generated surface pattern |
substrate-fill | "inherit" | "inset" | — | Surface fill the pattern sits on (full colour stays with tint) |
substrate-opacity | "sm" | "md" | "lg" | — | Pattern ink strength |
substrate-size | "sm" | "md" | "lg" | — | Pattern cell size |
substrate-target | "self" | "media" | — | Which surface the pattern fills (overrides the rune/theme default) |
tint
Per-rune colour override: a named tint from the theme registry, with inline per-token overrides layered on top.
| Attribute | Type | Required | Description |
|---|---|---|---|
tint | string | — | Color tint preset applied to this block |
tint-mode | "auto" | "dark" | "light" | — | Whether the tint adapts to auto, dark, or light mode |
width
The track a block rune occupies.
| Attribute | Type | Required | Description |
|---|---|---|---|
width | "compact" | "narrow" | "content" | "wide" | "full" | — | Maximum width constraint for this block |
| Not available | Why |
|---|---|
| dropcap, reading | this rune declares no prose body |
| frame | this rune declares neither a `frameTarget` nor a media section |
| prominence | this rune has no page-section header or featured quotation |