Skip to content

Import code blocks and shared content into pages. - #12

Merged
koculu merged 1 commit into
mainfrom
shared-content-and-codeblocks
Oct 5, 2026
Merged

koculu merged 1 commit into
mainfrom
shared-content-and-codeblocks

Conversation

@koculu

@koculu koculu commented Oct 5, 2026

Copy link
Copy Markdown
Member

Import code blocks and shared content into pages

Adds two source-level include tags, so content doesn't have to be duplicated across pages.

<import-codeblock src="./playground.ts"/>

  • Expands into a fenced code block holding the file, before compilation, exactly as if pasted by hand.
  • Works in Markdown, inside component markup (e.g. TabPane), and in headers and footers.
  • The language comes from the extension; lang overrides it.
  • Tags inside code blocks and inline code stay as written.
  • src resolves from the file the tag is in, must stay inside the content folder, and must match case exactly on every OS.

<import-content src="./_shared.mdx"/>

  • Inserts a shared file's Markdown into the page. Headings join the table of contents, and components and {{ }} work.
  • The _ convention: a Markdown/MDX file whose name, or a folder above it, starts with _ is shared content. It is never published as a page; generated pages can't use such paths either.
  • Shared files have no frontmatter. Their own import tags resolve from the shared file, and an import cycle fails the build with the full chain.
  • Links inside shared content resolve from the page that shows it.

Dev server

Pages record the files they import, directly or through shared content. Editing an imported file re-renders those pages and refreshes any header or footer that imports it. Creating a missing file recovers its error page.

Studio docs

The 56 playground sources copied into component pages now use <import-codeblock>. All copies matched their files exactly, the rendered output is identical, and 8,356 duplicated lines are removed.

Docs

New Code blocks and Shared content guides. Also updated: the CLI guide (content folder rules), the ts-ssg README, and the incremental build notes.

Other

ts-ssg now declares its existing @purestack/ts-minidom dependency, which adds one line to yarn.lock.

Verification

  • Unit tests cover both tags.
  • Dev-server tests cover edits, missing files, headers, and shared files never being published.
  • All 735 tests pass; TS7 type-check and biome are clean.

@koculu
koculu merged commit 1e52bf1 into main Oct 5, 2026
2 checks passed
@koculu
koculu deleted the shared-content-and-codeblocks branch October 5, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant