Skip to content

Commit 581ff28

Browse files
committed
Extract ts-highlight, ts-pagefind plugins.
1 parent c27f3fc commit 581ff28

71 files changed

Lines changed: 1049 additions & 408 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎frontend/purestack.studio/guides/extending/plugins.mdx‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@ The badge appears on the page. Change its `tone` in `plugins/site.ts` while the
9191

9292
## Standard plugins
9393

94-
PureStack includes three plugins automatically in `build`, `serve`, and `publish`:
94+
PureStack includes five plugins automatically in `build`, `serve`, and `publish`:
9595

9696
| Package | Factory | Provides |
9797
| --- | --- | --- |
9898
| `@purestack/ts-components` | `componentsPlugin()` | Standard components, icons, and component styles |
99-
| `@purestack/ts-theme` | `themePlugin()` | The `doc` and `splash` templates, generated theme CSS, and theme switching |
100-
| `@purestack/ts-page-scripts` | `pageScriptsPlugin()` | Auth hint, consent and analytics, menus, navigation, code copying, search, and TOC runtimes |
99+
| `@purestack/ts-theme` | `themePlugin()` | The `doc` and `splash` templates, generated theme CSS, favicons, and theme switching |
100+
| `@purestack/ts-page-scripts` | `pageScriptsPlugin()` | Auth hint, consent and analytics, menus, navigation, code copying, search, TOC, Tabs, and Modal runtimes |
101+
| `@purestack/ts-highlight` | `highlightPlugin()` | Shiki or highlight.js code highlighting |
102+
| `@purestack/ts-pagefind` | `pagefindPlugin()` | Full-build and lazy development search indexing |
101103

102104
The stylesheet provider initializes before component factories, then all config hooks run in plugin order. Names do not affect initialization. Components belong to each build, so hooks can override them through `context.components`. The theme and page runtime plugins supply head templates that run before the selected page template, preserving its ability to inspect or change the completed head. The lifecycle hook set is unchanged.
103105

@@ -112,10 +114,14 @@ export default defineConfig({
112114
})
113115
```
114116

115-
This keeps the layouts and components while omitting the page runtimes. Theme switching belongs to the theme plugin; component-specific Tabs and Modal embeds still follow the page's `embed` settings. Without the theme plugin, another plugin must supply your page templates and any CSS output you need.
117+
This keeps the layouts and components while omitting page runtimes, code highlighting, and search indexing. Theme switching and favicon generation belong to the theme plugin. Tabs and Modal scripts belong to the page scripts plugin, including automatic component embeds and explicit frontmatter settings. Without the theme plugin, another plugin must supply your page templates and any CSS output you need.
116118

117119
An explicitly listed standard plugin replaces the automatic instance by name and keeps its initialization position. You can also use `createDefaultPlugins()` to obtain the complete set. In programmatic builds, use `options.defaultPlugins` alongside `options.plugins`.
118120

121+
The highlighting plugin selects the configured backend. Configure native backend factories through `highlightPlugin({ createShiki, createHighlightJs })`, or supply `markdown.createHighlighter(config)` for a different engine. The generic provider returns `{ codeToHtml(code, lang?) }`. Ordinary providers override the default without constructing it; per-language `markdown.resolveHighlighter` callbacks retain precedence.
122+
123+
The Pagefind plugin supplies a `search` provider. To use another engine, replace `purestack:pagefind` or disable the default set and install your own provider. The builder supplies excluded output paths and the rendered-page list for lazy requests, and manages invalidation on edits and deletions. Sitemap and robots generation remain built in.
124+
119125
## How the config loads
120126

121127
- **Where it lives.** The CLI looks for `purestack.config.ts` in the folder passed to `--content`. It must default-export `defineConfig({ plugins: [...] })`.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "purestack-repo",
4-
"version": "1.1.14",
4+
"version": "1.1.15",
55
"packageManager": "yarn@4.18.1",
66
"type": "module",
77
"sideEffects": false,

‎packages/purestack/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "purestack",
3-
"version": "1.1.14",
3+
"version": "1.1.15",
44
"packageManager": "yarn@4.9.2",
55
"module": "./dist/purestack.mjs",
66
"types": "./dist/purestack.d.mts",

‎packages/purestack/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const version: string = '1.1.14'
1+
export const version: string = '1.1.15'
22

33
export * from '@purestack/ts-ssg'

‎packages/ts-common/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@purestack/ts-common",
3-
"version": "1.1.14",
3+
"version": "1.1.15",
44
"packageManager": "yarn@4.9.2",
55
"module": "./dist/ts-common.mjs",
66
"types": "./dist/ts-common.d.mts",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** Converts source code to highlighted pre/code HTML. */
2+
export interface MdxCodeHighlighter {
3+
codeToHtml: (code: string, lang?: string) => string | Promise<string>
4+
}

‎packages/ts-common/src/index.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
export type { MdxCodeHighlighter } from './code-highlighter'
2+
export {
3+
DEFAULT_CODE_LANGUAGES,
4+
LANGUAGE_BY_EXTENSION,
5+
normalizeCodeLanguage,
6+
} from './codeLanguages'
17
export type {
28
ConsentCategory,
39
ConsentConfig,
@@ -64,9 +70,12 @@ export type {
6470
SiteStyleConfig,
6571
SiteStyleConfigInput,
6672
} from './site-config-types'
73+
export type { SiteSearch } from './site-search'
6774
export type { SiteStyles, WriteStylesResult } from './site-styles'
6875
export type {
6976
PageContext,
7077
PageOutlineItem,
78+
RuntimeEmbedPosition,
79+
RuntimeEmbeds,
7180
TsSsgNavigation,
7281
} from './ts-ssg-context'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** Search output owned by a plugin; the builder manages output invalidation. */
2+
export interface SiteSearch {
3+
/** Whether a decoded, base-path-relative URL belongs to this search provider. */
4+
ownsPath(pathname: string): boolean
5+
write(input: {
6+
outDir: string
7+
excludeFiles: Iterable<string>
8+
/** Only these rendered pages are available during lazy development. */
9+
onlyFiles?: Iterable<string>
10+
}): Promise<void>
11+
}

‎packages/ts-common/src/ts-ssg-context.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export interface PageOutlineItem {
1313
children?: PageOutlineItem[]
1414
}
1515

16+
export type RuntimeEmbedPosition = 'body' | 'head'
17+
export type RuntimeEmbeds = ReadonlyMap<string, RuntimeEmbedPosition>
18+
1619
export interface TsSsgNavigation {
1720
folder?: string
1821
root?: string
@@ -35,5 +38,5 @@ export interface PageContext {
3538
resolvePublicHref: (href: string) => string
3639
recordScriptEntrypoint: (sourceRelPath: string) => void
3740
resolveScriptPublicPath?: (sourceRelPath: string) => string
38-
recordRuntimeEmbed: (name: string, position: 'body' | 'head') => void
41+
recordRuntimeEmbed: (name: string, position: RuntimeEmbedPosition) => void
3942
}

0 commit comments

Comments
 (0)