Skip to content

Commit 8527296

Browse files
authored
Merge pull request #29 from PureStackStudio/rename-ts-ssg-context
Rename ts ssg context
2 parents 6fa737d + de97003 commit 8527296

63 files changed

Lines changed: 477 additions & 264 deletions

Some content is hidden

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

‎frontend/components/studioBrand.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
type LogoConfig,
33
type LogoSize,
4-
resolveTsSsgContext,
4+
resolvePageContext,
55
} from '@purestack/ts-common'
66
import { defineComponent, html, type RefOrValue } from 'regor'
77

@@ -17,7 +17,7 @@ export function defineStudioBrandComponent() {
1717
props: ['size'],
1818
context: (head) => ({
1919
...head.props,
20-
config: resolveTsSsgContext(head).site.logo,
20+
config: resolvePageContext(head).site.logo,
2121
}),
2222
})
2323
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Panel :context="pageContext.pageInfo" tone="accent" variant="surface" bodyClass="p-3" class="mb-4">
2+
<p class="text-eyebrow mt-0">From this page's frontmatter</p>
3+
<strong>{{ frontmatter.title }}</strong>
4+
<ul class="mb-0">
5+
<li r-for="item in frontmatter.highlights">
6+
{{ item }}
7+
</li>
8+
</ul>
9+
</Panel>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<RegorApp id="launch-checklist" src="./regor-launch-checklist.ts"/>

frontend/purestack.studio/guides/extending/regor-launch-checklist.ts renamed to frontend/purestack.studio/guides/extending/regor/regor-launch-checklist.ts

File renamed without changes.

frontend/purestack.studio/guides/extending/regor.mdx renamed to frontend/purestack.studio/guides/extending/regor/regor.mdx

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ highlights:
1717

1818
# Regor
1919

20-
<a href="https://github.com/PureStackStudio/Regor" target="_blank" rel="noopener">Regor</a> is the component framework PureStack is built on. It runs in two places:
20+
<a
21+
href="https://github.com/PureStackStudio/Regor"
22+
target="_blank"
23+
rel="noopener"
24+
>Regor</a
25+
>
26+
is the component framework PureStack is built on. It runs in two places:
2127

2228
<Grid columns="1" columnsSm="2" class="gap-3 mb-4">
2329
<Panel tone="neutral" bodyClass="p-3">
@@ -153,7 +159,7 @@ Every page goes through the same four steps:
153159
| Where it runs | Your build, once per page | The visitor's browser |
154160
| What it produces | Static HTML | A live, interactive interface |
155161
| Event handlers, `r-model`, timers | Not kept | Run normally |
156-
| Page data (`tsSsgContext`) | Available | Not available |
162+
| Page data (`pageContext`) | Available | Not available |
157163
| Components | All built-in and registered components | The component families you register |
158164

159165
## Regor at build time
@@ -185,45 +191,22 @@ A plain attribute passes a string. An attribute that starts with a colon is a Re
185191

186192
### Expressions and page data
187193

188-
Text in double braces is a Regor expression, anywhere in a page. Inside markup, expressions can read `tsSsgContext`, which holds the page and site data that PureStack provides during the build:
194+
Text in double braces is a Regor expression, anywhere in a page. Inside markup, expressions can read `pageContext`, which holds the page and site data that PureStack provides during the build:
189195

190196
| Field | Contents |
191197
| --- | --- |
192-
| `tsSsgContext.pageInfo.frontmatter` | The page's frontmatter, including any custom fields you add |
193-
| `tsSsgContext.pageInfo.urlPath` | The page's URL, such as `/guides/extending/regor/` |
194-
| `tsSsgContext.pageInfo.relPath` | The source file path inside the content folder |
195-
| `tsSsgContext.site` | The resolved site configuration |
196-
| `tsSsgContext.navigation`, `tsSsgContext.outline` | The page's navigation and heading outline |
197-
| `tsSsgContext.locale`, `tsSsgContext.locales` | The page's language and the site's languages |
198-
199-
This page lists three highlights in its frontmatter. The panel below reads them during the build:
200-
201-
<Panel tone="accent" variant="surface" bodyClass="p-3" class="mb-4">
202-
<p class="text-eyebrow mt-0">From this page's frontmatter</p>
203-
<strong>{{ tsSsgContext.pageInfo.frontmatter.title }}</strong>
204-
<ul class="mb-0">
205-
<li r-for="item in tsSsgContext.pageInfo.frontmatter.highlights">
206-
{{ item }}
207-
</li>
208-
</ul>
209-
</Panel>
198+
| `pageContext.pageInfo.frontmatter` | The page's frontmatter, including any custom fields you add |
199+
| `pageContext.pageInfo.urlPath` | The page's URL, such as `/guides/extending/regor/` |
200+
| `pageContext.pageInfo.relPath` | The source file path inside the content folder |
201+
| `pageContext.site` | The resolved site configuration |
202+
| `pageContext.navigation`, `pageContext.outline` | The page's navigation and heading outline |
203+
| `pageContext.locale`, `pageContext.locales` | The page's language and the site's languages |
210204

211-
```mdx
212-
---
213-
title: Regor
214-
highlights:
215-
- One component model for pages and apps
216-
- Plain TypeScript, no compiler plugin
217-
- Built-in components and theme styles in both places
218-
---
205+
This page lists three highlights in its frontmatter. The panel below reads them during the build. `:context="pageContext.pageInfo"` makes `frontmatter` available directly inside the panel:
219206

220-
<Panel tone="accent" variant="surface" bodyClass="p-3">
221-
<strong>{{ tsSsgContext.pageInfo.frontmatter.title }}</strong>
222-
<ul>
223-
<li r-for="item in tsSsgContext.pageInfo.frontmatter.highlights">{{ item }}</li>
224-
</ul>
225-
</Panel>
226-
```
207+
<import-content src="./_regor-frontmatter.mdx"/>
208+
209+
<import-codeblock src="./_regor-frontmatter.mdx"/>
227210

228211
`r-if`, `r-else-if`, and `r-else` choose what to render. `r-for` repeats an element for each item. Loop over data from frontmatter, the page context, or component state.
229212

@@ -294,9 +277,10 @@ export default defineConfig({
294277
>
295278
Export the interface that types a component, as <code>ReleaseNote</code> is
296279
exported here. The
297-
<a href="/guides/getting-started/vscode-extension/">VS Code extension</a> finds components
298-
through their exported interfaces. Without the export, it can't complete the
299-
component's props or jump from a tag in your markup to the component's source.
280+
<a href="/guides/getting-started/vscode-extension/">VS Code extension</a>
281+
finds components through their exported interfaces. Without the export, it
282+
can't complete the component's props or jump from a tag in your markup to the
283+
component's source.
300284
</AlertBox>
301285

302286
Then use it in any page. Content between the tags fills the `<slot>`:
@@ -307,19 +291,17 @@ Then use it in any page. Content between the tags fills the `<slot>`:
307291
</ReleaseNote>
308292
```
309293

310-
Tag names match registered keys regardless of case, so `<ReleaseNote>` finds `releaseNote`. The kebab-case form `<release-note>` works too. Components can also read page data. Pass the component head to `resolveTsSsgContext` from `@purestack/ts-common`, as the built-in navigation and page-link components do.
294+
Tag names match registered keys regardless of case, so `<ReleaseNote>` finds `releaseNote`. The kebab-case form `<release-note>` works too. Components can also read page data. Pass the component head to `resolvePageContext` from `@purestack/ts-common`, as the built-in navigation and page-link components do.
311295

312296
## Regor in the browser
313297

314298
### Mount an app
315299

316300
Place a `RegorApp` in a page and point it at a TypeScript file next to the page. It renders an `app` element with the `id` you give it and loads the script. The script calls `createApp` with the matching selector:
317301

318-
<RegorApp id="launch-checklist" src="./regor-launch-checklist.ts"/>
302+
<import-content src="./_regor-launch-checklist.mdx"/>
319303

320-
```mdx
321-
<RegorApp id="launch-checklist" src="./regor-launch-checklist.ts"/>
322-
```
304+
<import-codeblock src="./_regor-launch-checklist.mdx"/>
323305

324306
<import-codeblock src="./regor-launch-checklist.ts"/>
325307

@@ -332,8 +314,8 @@ Browser apps do not get the build's component list. Each app registers the compo
332314
<AlertBox tone="info" icon="tabler:info-circle" title="Register icons too">
333315
Register each icon your app shows, including the defaults that components draw
334316
themselves, such as the arrow in a select field. The
335-
<a href="/guides/styling/icons/#icons-in-browser-apps">Icons guide</a> lists those
336-
defaults.
317+
<a href="/guides/styling/icons/#icons-in-browser-apps">Icons guide</a> lists
318+
those defaults.
337319
</AlertBox>
338320

339321
### Template syntax
@@ -483,7 +465,7 @@ These patterns scale from a single widget to a multi-page admin tool with tables
483465

484466
## Use other libraries
485467

486-
A [PageScript](/components/runtime/page-script/) loads a browser entry point. Use it to enhance existing HTML or mount a browser-compatible library. PureStack bundles local TypeScript and its imports with esbuild; framework-specific source formats may need an additional compilation step. Start with a plain TypeScript module, as shown in [runtime scripts](../../components/runtime).
468+
A [PageScript](/components/runtime/page-script/) loads a browser entry point. Use it to enhance existing HTML or mount a browser-compatible library. PureStack bundles local TypeScript and its imports with esbuild; framework-specific source formats may need an additional compilation step. Start with a plain TypeScript module, as shown in [runtime scripts](../../../components/runtime).
487469

488470
<AlertBox tone="warning" icon="tabler:alert-triangle" title="What you give up">
489471
Other frameworks can't use the built-in components, and they don't inherit the

‎package.json‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
{
22
"private": true,
33
"name": "purestack-repo",
4-
"version": "1.1.8",
4+
"version": "1.1.9",
55
"packageManager": "yarn@4.18.1",
66
"type": "module",
77
"sideEffects": false,
88
"workspaces": [
99
"packages/*"
1010
],
11+
"dependencyConsistency": {
12+
"exceptions": {
13+
"typescript": "The repository uses TypeScript 7 for tsc; the VS Code extension needs TypeScript 6's JavaScript compiler API."
14+
}
15+
},
1116
"license": "MIT",
1217
"repository": {
1318
"type": "git",
@@ -43,6 +48,7 @@
4348
"lint": "yarn workspaces foreach --no-private --all --verbose --topological -- run lint",
4449
"lint:ci": "yarn workspaces foreach --no-private --all --verbose --topological -- exec biome check ./src --formatter-enabled=false",
4550
"check-eol": "yarn tsx scripts/check-eol.ts",
51+
"check-dependencies": "yarn tsx scripts/check-dependencies.ts",
4652
"bump-version": "yarn tsx --no-warnings scripts/bump-version.ts",
4753
"bundle": "yarn tsx --no-warnings scripts/bundle.ts",
4854
"cleanup": "yarn tsx --no-warnings scripts/cleanup.ts",
@@ -53,6 +59,6 @@
5359
"pack-vscode-ext": "yarn --cwd packages/ts-ssg-vscode build && yarn --cwd packages/ts-ssg-vscode package",
5460
"longest": "yarn tsx ./scripts/longest-functions.ts",
5561
"format": "biome format --write",
56-
"pre-commit": "yarn check-eol && yarn regor-components && yarn embed && yarn format && yarn lint && yarn build && yarn test run"
62+
"pre-commit": "yarn check-dependencies && yarn check-eol && yarn regor-components && yarn embed && yarn format && yarn lint && yarn build && yarn test run"
5763
}
5864
}

‎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.8",
3+
"version": "1.1.9",
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.8'
1+
export const version: string = '1.1.9'
22

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

‎packages/ts-common/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ scripts. This package defines site configuration, page frontmatter, navigation,
55
logos, templates, and the rendering context so those packages agree on the same
66
shapes.
77

8-
Import types such as `SiteConfig`, `PageFrontmatter`, and `TsSsgContext` when
9-
building a custom integration. The runtime exports `resolveTsSsgContext` and
10-
`tryResolveTsSsgContext` find the site context in a Regor component.
8+
Import types such as `SiteConfig`, `PageFrontmatter`, and `PageContext` when
9+
building a custom integration. The runtime exports `resolvePageContext` and
10+
`tryResolvePageContext` find the site context in a Regor component.

‎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.8",
3+
"version": "1.1.9",
44
"packageManager": "yarn@4.9.2",
55
"module": "./dist/ts-common.mjs",
66
"types": "./dist/ts-common.d.mts",

0 commit comments

Comments
 (0)