@chassis-ui/docs 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +286 -0
- package/README.md +227 -71
- package/UPGRADING.md +243 -0
- package/index.ts +7 -1
- package/package.json +31 -8
- package/src/components/DocsSidebar.astro +9 -9
- package/src/components/shortcodes/Callout.astro +4 -4
- package/src/components/shortcodes/Code.astro +3 -3
- package/src/components/shortcodes/JsDocs.astro +6 -7
- package/src/components/shortcodes/ScssDocs.astro +7 -9
- package/src/components/shortcodes/ScssDocsSimple.astro +6 -7
- package/src/integration.ts +271 -0
- package/src/js/clipboard.ts +65 -0
- package/src/layouts/BaseLayout.astro +7 -9
- package/src/layouts/DocsLayout.astro +11 -13
- package/src/layouts/RedirectLayout.astro +1 -1
- package/src/layouts/head/Analytics.astro +6 -4
- package/src/layouts/head/Head.astro +2 -2
- package/src/layouts/head/Social.astro +5 -6
- package/src/layouts/header/Navigation.astro +28 -19
- package/src/libs/config.ts +138 -0
- package/src/libs/docs-path.ts +12 -0
- package/src/libs/highlight.ts +4 -44
- package/src/libs/paths.ts +160 -0
- package/src/libs/remark.ts +184 -0
- package/src/libs/schema.ts +211 -0
- package/src/libs/shortcodes.ts +86 -71
- package/src/libs/snippet.ts +21 -0
- package/src/libs/source.ts +17 -40
- package/src/libs/toc.ts +3 -1
- package/src/scss/_vars.scss +4 -1
- package/src/site.ts +150 -0
- package/virtual.d.ts +25 -0
package/README.md
CHANGED
|
@@ -2,26 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
> Shared Astro layouts, components, and utilities for Chassis documentation sites.
|
|
4
4
|
|
|
5
|
-
[](https://opensource.org/licenses/MIT) [](https://opensource.org/licenses/MIT) [](https://www.npmjs.com/package/@chassis-ui/docs)
|
|
6
6
|
|
|
7
7
|
## Overview
|
|
8
8
|
|
|
9
|
-
`@chassis-ui/docs` powers every documentation site in the Chassis ecosystem
|
|
9
|
+
`@chassis-ui/docs` powers every documentation site in the Chassis ecosystem: the main `chassis-ui.com` website and the docs of `chassis-css`, `chassis-tokens`, `chassis-icons`, `chassis-figma`, `chassis-assets` and `chassis-react`. It ships layouts, navigation components, shortcodes for MDX, content-processing utilities and SCSS, so each site stays consistent without copying code.
|
|
10
10
|
|
|
11
11
|
> [!NOTE] This package is developed inside the [`chassis-website`](https://github.com/chassis-ui/website) monorepo at `packages/docs/` and published to npm. Source, issues, and pull requests live in that repository.
|
|
12
12
|
|
|
13
|
+
Coming from 0.5? See [UPGRADING.md](UPGRADING.md).
|
|
14
|
+
|
|
13
15
|
## Installation
|
|
14
16
|
|
|
15
17
|
```sh
|
|
16
18
|
pnpm add @chassis-ui/docs
|
|
17
19
|
```
|
|
18
20
|
|
|
19
|
-
or:
|
|
20
|
-
|
|
21
|
-
```sh
|
|
22
|
-
npm install @chassis-ui/docs
|
|
23
|
-
```
|
|
24
|
-
|
|
25
21
|
### Peer Dependencies
|
|
26
22
|
|
|
27
23
|
```json
|
|
@@ -38,96 +34,255 @@ npm install @chassis-ui/docs
|
|
|
38
34
|
}
|
|
39
35
|
```
|
|
40
36
|
|
|
41
|
-
|
|
37
|
+
A site also installs `@astrojs/mdx` and the rest of the Chassis stack, `@chassis-ui/tokens` and `@chassis-ui/icons`.
|
|
38
|
+
|
|
39
|
+
## Setup
|
|
42
40
|
|
|
43
|
-
|
|
41
|
+
A site needs four things before it can use the layouts: the integration, a `config.yml`, two content collections and the static files that the layouts link to.
|
|
42
|
+
|
|
43
|
+
The [starter site](starter/) has all four. Copy it to start a new site, and follow its README. CI builds it from the packed package on every push, so it works with the version of the package next to it.
|
|
44
|
+
|
|
45
|
+
### 1. Add the integration
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
// astro.config.ts
|
|
49
|
+
import { defineConfig } from 'astro/config'
|
|
50
|
+
import mdx from '@astrojs/mdx'
|
|
51
|
+
import { chassisDocs } from '@chassis-ui/docs/integration'
|
|
52
|
+
|
|
53
|
+
export default defineConfig({
|
|
54
|
+
integrations: [chassisDocs(), mdx()]
|
|
55
|
+
})
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The integration:
|
|
59
|
+
|
|
60
|
+
- reads and validates `config.yml` and `data/sidebar.yml`, and gives them to the layouts and components
|
|
61
|
+
- sets `site` from `baseURL`, unless the Astro config sets `site` itself
|
|
62
|
+
- sets `markdown`: heading anchors, Shiki themes, and the `[[config:key]]` and `[[docsref:/path]]` replacements
|
|
63
|
+
- imports the shortcodes into every MDX file
|
|
64
|
+
- fails the build when a `[[docsref:]]` link points to a page that was not built
|
|
65
|
+
- makes the scripts of the package and of the site share one copy of `@chassis-ui/css`, so that no listener is registered twice
|
|
66
|
+
- puts the default design tokens of `@chassis-ui/css` on the Sass load path, which the styles need
|
|
67
|
+
|
|
68
|
+
It finds every file from the Astro root, the directory that holds `astro.config.ts`. The working directory of the build does not matter.
|
|
69
|
+
|
|
70
|
+
| Option | Default | Meaning |
|
|
71
|
+
| ---------------- | ---------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
72
|
+
| `config` | none | The config, when the site has loaded it itself with `loadConfig()` |
|
|
73
|
+
| `configFile` | `'config.yml'` | Path of the config file, from the site's root |
|
|
74
|
+
| `configSchema` | `configSchema` | Schema of the config file. See [keys of your own](#keys-of-your-own) |
|
|
75
|
+
| `sidebarFile` | `'data/sidebar.yml'`, when it exists | Path of the sidebar data, or `false` for no sidebar |
|
|
76
|
+
| `styles` | `['src/scss/docs.scss']`, when it exists | Stylesheets that every page loads. Without one, the package's own styles are loaded |
|
|
77
|
+
| `shortcodes` | all | `{ dir, include, exclude }`. See [shortcodes](#shortcodes) |
|
|
78
|
+
| `markdown` | none | `{ remarkPlugins, rehypePlugins, remarkRehype }` of the site. They run after the package's plugins |
|
|
79
|
+
| `brokenDocsrefs` | `'error'` | `'error'`, `'warn'` or `'ignore'` |
|
|
80
|
+
|
|
81
|
+
#### Tokens of your own
|
|
82
|
+
|
|
83
|
+
The styles of `@chassis-ui/css` load the design tokens as `chassis-tokens`. The integration adds the folder with the default one, `scss/vendor` of `@chassis-ui/css`, as the last Sass load path. A site with tokens of its own adds the folder of its `_chassis-tokens.scss` in its Astro config, which comes first:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
// astro.config.ts
|
|
87
|
+
export default defineConfig({
|
|
88
|
+
vite: {
|
|
89
|
+
css: { preprocessorOptions: { scss: { loadPaths: ['src/scss/tokens'] } } }
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 2. Write `config.yml`
|
|
95
|
+
|
|
96
|
+
```yaml
|
|
97
|
+
title: 'Chassis - CSS'
|
|
98
|
+
subtitle: 'A Tokenized CSS Framework'
|
|
99
|
+
description: 'An open-source, tokenized CSS framework.'
|
|
100
|
+
authors: 'Ozgur Gunes'
|
|
101
|
+
baseURL: 'https://chassis-ui.com/css'
|
|
102
|
+
docsPath: '/css/docs'
|
|
103
|
+
repo: 'https://github.com/chassis-ui/css'
|
|
104
|
+
currentVersion: '0.5.2'
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
| Key | Required | Meaning |
|
|
108
|
+
| --------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------- |
|
|
109
|
+
| `title`, `subtitle`, `description`, `authors` | yes | Used in the page title and the meta tags |
|
|
110
|
+
| `baseURL` | yes | Canonical URL of the site |
|
|
111
|
+
| `docsPath` | yes | URL path of the docs pages. Starts with `/` |
|
|
112
|
+
| `repo` | yes | URL of the repository |
|
|
113
|
+
| `currentVersion` | yes | Version that the site documents. Links to source files use the tag `v<currentVersion>` |
|
|
114
|
+
| `githubOrg` | no | GitHub organisation name, not a URL. The header links to it |
|
|
115
|
+
| `figmaHandle` | no | Figma Community handle. The header links to it |
|
|
116
|
+
| `xUsername` | no | X handle. Used in the social meta tags |
|
|
117
|
+
| `analytics.googleId` | no | Google Analytics ID. Loaded in production builds only |
|
|
118
|
+
| `anchors.min`, `anchors.max` | no | Heading levels that get an anchor link. Default 2 to 5 |
|
|
119
|
+
| `toc.min`, `toc.max` | no | Heading levels in the table of contents. Default 2 to 6 |
|
|
120
|
+
| `sourceDir` | no | Directory that `file` props are relative to, from the site's root, e.g. `"../css"`. Default `"."` |
|
|
121
|
+
| `sourcePath` | no | The same directory from the root of the repository, e.g. `"packages/css"` |
|
|
122
|
+
| `sitePath` | no | The site's root from the root of the repository, e.g. `"packages/site"` |
|
|
123
|
+
| `siteBranch` | no | The branch that "View on GitHub" links to. Default `main` |
|
|
124
|
+
|
|
125
|
+
`file` props are those of `<ScssDocs>`, `<ScssDocsSimple>`, `<JsDocs>` and `<Code filePath>`.
|
|
126
|
+
|
|
127
|
+
The schema is strict. A key that it does not know fails the build, so a typing error cannot go unnoticed.
|
|
128
|
+
|
|
129
|
+
#### Keys of your own
|
|
130
|
+
|
|
131
|
+
Extend the schema and pass it to the integration. Use the `z` that the package exports, so that the site and the package share one copy of Zod.
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
// src/libs/config.ts
|
|
135
|
+
import { configSchema, z } from '@chassis-ui/docs/schema'
|
|
136
|
+
|
|
137
|
+
export const siteConfigSchema = configSchema.extend({
|
|
138
|
+
download: z.object({ dist: z.url(), source: z.url() })
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
export type SiteConfig = z.infer<typeof siteConfigSchema>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
// astro.config.ts
|
|
146
|
+
integrations: [chassisDocs({ configSchema: siteConfigSchema })]
|
|
147
|
+
```
|
|
44
148
|
|
|
45
149
|
```astro
|
|
46
150
|
---
|
|
47
|
-
import
|
|
48
|
-
import
|
|
49
|
-
|
|
151
|
+
import { getConfig } from '@chassis-ui/docs/site'
|
|
152
|
+
import type { SiteConfig } from '@libs/config'
|
|
153
|
+
|
|
154
|
+
const { download } = getConfig<SiteConfig>()
|
|
155
|
+
---
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 3. Define the content collections
|
|
159
|
+
|
|
160
|
+
The layouts read the `docs` collection, and `<Callout name>` reads the `callouts` collection.
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
// src/content.config.ts
|
|
164
|
+
import { defineCollection } from 'astro:content'
|
|
165
|
+
import { glob } from 'astro/loaders'
|
|
166
|
+
import { calloutsSchema, docsSchema } from '@chassis-ui/docs/schema'
|
|
167
|
+
|
|
168
|
+
export const collections = {
|
|
169
|
+
docs: defineCollection({
|
|
170
|
+
loader: glob({ pattern: '**/*.{md,mdx}', base: './content/docs' }),
|
|
171
|
+
schema: docsSchema
|
|
172
|
+
}),
|
|
173
|
+
callouts: defineCollection({
|
|
174
|
+
loader: glob({ pattern: '**/*.md', base: './content/callouts' }),
|
|
175
|
+
schema: calloutsSchema
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 4. Provide the static files
|
|
50
181
|
|
|
51
|
-
|
|
52
|
-
import ThemeToggler from '@chassis-ui/docs/components/ThemeToggler.astro'
|
|
182
|
+
The layouts link to files under `/static/`, which the site puts into its `public` directory:
|
|
53
183
|
|
|
54
|
-
|
|
184
|
+
| URL | From |
|
|
185
|
+
| -------------------------------------------------------------------- | ----------------------------------------- |
|
|
186
|
+
| `/static/css/chassis.css`, `/static/css/chassis.min.css` | the `dist` folder of `@chassis-ui/css` |
|
|
187
|
+
| `/static/icons/chassis-icons.svg`, `/static/icons/chassis-icons.css` | the `icons` folder of `@chassis-ui/icons` |
|
|
188
|
+
| `/static/images/*`: logo, favicons, social image | the docs build of `chassis-assets` |
|
|
189
|
+
|
|
190
|
+
These helpers find the folders, whether `node_modules` is in the site's root or in the root of the repository: `getChassisCSSFsPath()`, `getChassisIconsFsPath()`, `getChassisAssetsFsPath()` and `getChassisTokensFsPath()`. Each takes `{ root, dir }`.
|
|
191
|
+
|
|
192
|
+
A site that type-checks with `astro check` declares the `@chassis-ui/css` module, which has no types: `declare module '@chassis-ui/css'`.
|
|
193
|
+
|
|
194
|
+
### 5. Use the layouts
|
|
195
|
+
|
|
196
|
+
```astro
|
|
197
|
+
---
|
|
198
|
+
import SingleLayout from '@chassis-ui/docs/layouts/SingleLayout.astro'
|
|
55
199
|
---
|
|
56
200
|
|
|
57
|
-
<SingleLayout title="About" description="
|
|
58
|
-
<
|
|
201
|
+
<SingleLayout title="About" description="What Chassis is and who makes it.">
|
|
202
|
+
<p>Page content.</p>
|
|
59
203
|
</SingleLayout>
|
|
60
204
|
```
|
|
61
205
|
|
|
62
|
-
##
|
|
206
|
+
## Shortcodes
|
|
63
207
|
|
|
64
|
-
|
|
65
|
-
following, or the build fails.
|
|
208
|
+
Every component in `@chassis-ui/docs/shortcodes/` is available in MDX files without an import. So is every component in the site's `src/components/shortcodes/`. A component of the site replaces the package's component of the same name.
|
|
66
209
|
|
|
67
|
-
|
|
210
|
+
```ts
|
|
211
|
+
chassisDocs({
|
|
212
|
+
shortcodes: {
|
|
213
|
+
// Leave out shortcodes whose names the site uses for something else
|
|
214
|
+
exclude: ['Icon']
|
|
215
|
+
}
|
|
216
|
+
})
|
|
217
|
+
```
|
|
68
218
|
|
|
69
|
-
|
|
70
|
-
exports:
|
|
219
|
+
## What pages read from the site
|
|
71
220
|
|
|
72
|
-
|
|
73
|
-
| ----------------- | ------------------------------------------------------------------------------- | -------------------------------------- |
|
|
74
|
-
| `@libs/config` | `getConfig()`, returning the parsed `config.yml` | most layouts and components |
|
|
75
|
-
| `@libs/content` | `docsPages`, the `docs` collection. `getCalloutByName(name)` and `CalloutName`. | `DocsLayout`, `DocsSidebar`, `Callout` |
|
|
76
|
-
| `@libs/data` | `getData('sidebar')`, and the types `SidebarItem` and `SidebarSubItem` | `DocsSidebar` |
|
|
77
|
-
| `@libs/path` | `getChassisDocsPath(path)` and `getDocsPublicFsPath()` | `DocsLayout`, `Social` |
|
|
78
|
-
| `@libs/clipboard` | `initCopyButtons(selector, getText)` | `Code` |
|
|
221
|
+
`@chassis-ui/docs/site` is for pages and components. It does not work in `astro.config.ts` or in the browser.
|
|
79
222
|
|
|
80
|
-
|
|
81
|
-
|
|
223
|
+
| Function | Returns |
|
|
224
|
+
| -------------------------------------------------- | ------------------------------------------------------------------- |
|
|
225
|
+
| `getConfig()` | The parsed `config.yml` |
|
|
226
|
+
| `getSidebar()` | The parsed `data/sidebar.yml` |
|
|
227
|
+
| `getDocsPath(path)` | URL path of a docs page |
|
|
228
|
+
| `getDocsPages()` | The entries of the `docs` collection |
|
|
229
|
+
| `getCallout(name)` | An entry of the `callouts` collection |
|
|
230
|
+
| `getSiteRoot()`, `getSiteFsPath(file)` | Absolute path of the site's root, or of a file in it |
|
|
231
|
+
| `getPublicFsPath(file)` | Absolute path of a file in the `public` directory |
|
|
232
|
+
| `getSourceFsPath(file)` | Absolute path of a file that a `file` prop names |
|
|
233
|
+
| `getSourceUrl(file)` | URL of a source file on GitHub, at the tag of the current version |
|
|
234
|
+
| `getSiteFileUrl(filePath)` | URL of a file of the site on GitHub, on the site's branch |
|
|
235
|
+
| `getPackageFilePath(file)` | Absolute path of a file of this package, e.g. `'js/color-modes.js'` |
|
|
236
|
+
| `resolveConfigRefs(text)`, `resolveDocsrefs(text)` | `text` with `[[config:]]` or `[[docsref:]]` replaced |
|
|
237
|
+
| `createDataLoader(definitions)` | A `getData(name)` function for the site's own YAML files in `data/` |
|
|
82
238
|
|
|
83
|
-
|
|
239
|
+
Code that runs while Astro loads its configuration uses the library functions of the root entry instead: `loadConfig()`, `loadData()`, `loadSidebar()` and the path helpers.
|
|
84
240
|
|
|
85
|
-
|
|
241
|
+
## Exports
|
|
86
242
|
|
|
87
|
-
|
|
88
|
-
- `repo`, `current_version`, `docsPath`
|
|
89
|
-
- `github_org`, `figma_handle`, `x_username`
|
|
90
|
-
- `anchors.min`, `anchors.max`
|
|
91
|
-
- `analytics.google_id`
|
|
243
|
+
These import paths are the public API.
|
|
92
244
|
|
|
93
|
-
|
|
94
|
-
|
|
245
|
+
| Path | Contents |
|
|
246
|
+
| ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
247
|
+
| `@chassis-ui/docs` | Library functions that work anywhere: config and data loaders, path helpers, `getSiteUrl`, `getDocsMarkdownConfig`, the remark and rehype plugins, `chassisAutoImport`, `generateToc`, `highlightCode`, image and string utilities |
|
|
248
|
+
| `@chassis-ui/docs/integration` | `chassisDocs()` and the type of its options |
|
|
249
|
+
| `@chassis-ui/docs/schema` | `z`, `configSchema`, `sidebarSchema`, `docsSchema`, `calloutsSchema`, the version validators, and the types `ChassisConfig`, `Sidebar`, `SidebarItem`, `DocsFrontmatter`, `DocsPage` |
|
|
250
|
+
| `@chassis-ui/docs/site` | What pages read from the site. See above |
|
|
251
|
+
| `@chassis-ui/docs/layouts/*` | `BaseLayout.astro`, `DocsLayout.astro`, `RedirectLayout.astro`, `SingleLayout.astro` |
|
|
252
|
+
| `@chassis-ui/docs/components/*` | `DocsSidebar.astro`, `FeatureCard.astro`, `NavLink.astro`, `ResponsiveImage.astro`, `TableOfContents.astro`, `ThemeToggler.astro` |
|
|
253
|
+
| `@chassis-ui/docs/shortcodes/*` | The MDX shortcodes |
|
|
254
|
+
| `@chassis-ui/docs/js/*` | Client-side scripts: `example-mode.js`, `clipboard.ts`, `color-modes.js` and others |
|
|
255
|
+
| `@chassis-ui/docs/scss/main` | The styles of the package. The integration loads them when the site has no stylesheet of its own |
|
|
256
|
+
| `@chassis-ui/docs/scss/vars` | The Sass variables and custom properties of the docs, for a site's own stylesheets |
|
|
95
257
|
|
|
96
|
-
|
|
97
|
-
| ------------ | ----------------------------------------------------------------------------------------------------------------- | ----------------- |
|
|
98
|
-
| `sourceDir` | Directory that the `file` props of the source-file shortcodes are relative to, from the build's working directory | `"../css"` |
|
|
99
|
-
| `sourcePath` | The same directory, from the root of the repository | `"packages/css"` |
|
|
100
|
-
| `sitePath` | The site's root, from the root of the repository | `"packages/site"` |
|
|
101
|
-
| `siteBranch` | The branch that "View on GitHub" links to. Defaults to `main`. | `"main"` |
|
|
258
|
+
No other path resolves: `exports` in `package.json` lists these and nothing else. The layouts and components are listed by name, so the folders inside `layouts/` and `components/` are not reachable.
|
|
102
259
|
|
|
103
|
-
The
|
|
104
|
-
`<Code filePath>`. They link to their files at the tag `v<current_version>`.
|
|
260
|
+
The integration provides four modules: `virtual:chassis-docs/config`, `virtual:chassis-docs/sidebar`, `virtual:chassis-docs/paths` and `virtual:chassis-docs/styles`. Use the functions of `@chassis-ui/docs/site` instead of importing them.
|
|
105
261
|
|
|
106
|
-
|
|
107
|
-
schema. Otherwise they are dropped silently.
|
|
262
|
+
## Versioning
|
|
108
263
|
|
|
109
|
-
|
|
264
|
+
The package follows [Semantic Versioning](https://semver.org/). Before 1.0 that means:
|
|
110
265
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
| `@chassis-ui/docs` | Library functions: `highlight`, `image`, `layout`, `markdown`, `placeholder`, `rehype`, `shortcodes`, `site`, `toc`, `utils` |
|
|
114
|
-
| `@chassis-ui/docs/layouts/*` | `BaseLayout`, `DocsLayout`, `RedirectLayout`, `SingleLayout` |
|
|
115
|
-
| `@chassis-ui/docs/components/*` | `DocsSidebar`, `FeatureCard`, `NavLink`, `ResponsiveImage`, `TableOfContents`, `ThemeToggler` |
|
|
116
|
-
| `@chassis-ui/docs/shortcodes/*` | MDX shortcode components |
|
|
117
|
-
| `@chassis-ui/docs/libs/*` | Direct access to individual library modules |
|
|
118
|
-
| `@chassis-ui/docs/js/*` | Client-side scripts |
|
|
119
|
-
| `@chassis-ui/docs/scss/*` | SCSS utilities and partials |
|
|
266
|
+
- A minor release, 0.x.0, may contain breaking changes. Each one is listed in [CHANGELOG.md](CHANGELOG.md) and has a step in [UPGRADING.md](UPGRADING.md).
|
|
267
|
+
- A patch release, 0.x.y, contains none.
|
|
120
268
|
|
|
121
|
-
|
|
269
|
+
A change is breaking when it changes something that this README documents:
|
|
122
270
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
271
|
+
- the import paths listed under [Exports](#exports), and what they export
|
|
272
|
+
- the options of the integration
|
|
273
|
+
- the keys of `config.yml`, and the schemas of the sidebar and the content collections
|
|
274
|
+
- the props and slots of the layouts, components and shortcodes
|
|
275
|
+
- the `[[config:]]` and `[[docsref:]]` syntax
|
|
276
|
+
- the URLs under `/static/` that the layouts link to
|
|
277
|
+
- the supported versions of Node, Astro and `@chassis-ui/css`
|
|
278
|
+
|
|
279
|
+
Everything else may change in a patch release: the rendered HTML, class names, the content of the styles, and every file that is not reachable through a documented import path.
|
|
280
|
+
|
|
281
|
+
1.0 is released when all three hold:
|
|
282
|
+
|
|
283
|
+
1. Every Chassis site uses the integration and carries no copy of code that the package provides.
|
|
284
|
+
2. Unit tests and builds of a fixture site run before every release.
|
|
285
|
+
3. Releases are automated and published with provenance.
|
|
131
286
|
|
|
132
287
|
## Chassis Ecosystem
|
|
133
288
|
|
|
@@ -141,6 +296,7 @@ This package is part of the Chassis Design System's multi-repository architectur
|
|
|
141
296
|
| [chassis-icons](https://github.com/chassis-ui/icons) | Icon library and build toolkit |
|
|
142
297
|
| [chassis-assets](https://github.com/chassis-ui/assets) | Multi-platform asset management |
|
|
143
298
|
| [chassis-figma](https://github.com/chassis-ui/figma) | Figma component documentation |
|
|
299
|
+
| [chassis-react](https://github.com/chassis-ui/react) | React component library |
|
|
144
300
|
|
|
145
301
|
All documentation sites in the ecosystem share this package for consistent layouts, components, and styling.
|
|
146
302
|
|
package/UPGRADING.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# Upgrading @chassis-ui/docs
|
|
2
|
+
|
|
3
|
+
## From 0.5 to 0.6
|
|
4
|
+
|
|
5
|
+
0.6.0 is a breaking release. In 0.5 a site had to supply five modules behind a `@libs/*`
|
|
6
|
+
path alias, and every site carried its own copy of them. In 0.6 the package owns that code.
|
|
7
|
+
A site adds one integration and deletes its copies.
|
|
8
|
+
|
|
9
|
+
Do the steps in order. The build fails with a message that names the step you missed.
|
|
10
|
+
|
|
11
|
+
### 1. Update the dependency
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pnpm add -D @chassis-ui/docs@^0.6.0
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The package now brings these itself. Remove each one that your own code does not import:
|
|
18
|
+
`js-yaml`, `zod`, `clipboard`, `unified`, `unist-util-visit`, `mdast-util-mdx-jsx`,
|
|
19
|
+
`@types/mdast` and `astro-auto-import`.
|
|
20
|
+
|
|
21
|
+
### 2. Rename the keys of `config.yml`
|
|
22
|
+
|
|
23
|
+
| 0.5 | 0.6 |
|
|
24
|
+
| --------------------- | ------------------------------------------- |
|
|
25
|
+
| `current_version` | `currentVersion` |
|
|
26
|
+
| `github_org` | `githubOrg` |
|
|
27
|
+
| `figma_handle` | `figmaHandle` |
|
|
28
|
+
| `x_username` | `xUsername` |
|
|
29
|
+
| `analytics.google_id` | `analytics.googleId` |
|
|
30
|
+
| `docsDir` | Delete it. The site root is the Astro root. |
|
|
31
|
+
|
|
32
|
+
- `githubOrg` is the name of the organisation, such as `chassis-ui`. A URL is rejected.
|
|
33
|
+
- `sourceDir` is now relative to the site's root, not to the working directory of the
|
|
34
|
+
build. For a site that is built from its own directory, the value stays the same.
|
|
35
|
+
- The schema is strict. A key that the package does not know fails the build. See step 4
|
|
36
|
+
for the keys of your own, such as `blog`, `download` or `cdn`.
|
|
37
|
+
|
|
38
|
+
Write your own keys in camelCase too, for example `docsVersion` and `exampleIcon`.
|
|
39
|
+
|
|
40
|
+
Replace the old names in the content as well:
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
grep -rl '\[\[config:current_version\]\]' content src \
|
|
44
|
+
| xargs sed -i '' 's/\[\[config:current_version\]\]/[[config:currentVersion]]/g'
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Three keys outside `config.yml` were renamed as well. An old name fails the build.
|
|
48
|
+
|
|
49
|
+
| File | 0.5 | 0.6 |
|
|
50
|
+
| -------------------------- | ------------------ | ----------------- |
|
|
51
|
+
| `data/sidebar.yml` | `icon_color` | `iconColor` |
|
|
52
|
+
| Frontmatter of a docs page | `added.show_badge` | `added.showBadge` |
|
|
53
|
+
| Frontmatter of a docs page | `extra_js` | `extraJs` |
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
sed -i '' 's/icon_color:/iconColor:/' data/sidebar.yml
|
|
57
|
+
grep -rlE '^ *(show_badge|extra_js):' content \
|
|
58
|
+
| xargs sed -i '' -E 's/^( *)show_badge:/\1showBadge:/; s/^( *)extra_js:/\1extraJs:/'
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Rename them in your own components and collection schemas too, where they read
|
|
62
|
+
`icon_color`, `show_badge` or `extra_js`.
|
|
63
|
+
|
|
64
|
+
### 3. Replace the Astro configuration
|
|
65
|
+
|
|
66
|
+
Before:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { chassis } from './src/libs/astro'
|
|
70
|
+
import { getConfig } from './src/libs/config'
|
|
71
|
+
import { remarkCxConfig, remarkCxDocsref } from './src/libs/remark'
|
|
72
|
+
import { chassisAutoImportPlugin } from './src/libs/shortcode'
|
|
73
|
+
import { getSiteUrl, getDocsMarkdownConfig } from '@chassis-ui/docs'
|
|
74
|
+
|
|
75
|
+
export default defineConfig({
|
|
76
|
+
site: getSiteUrl(getConfig()),
|
|
77
|
+
integrations: [chassis()],
|
|
78
|
+
markdown: getDocsMarkdownConfig({
|
|
79
|
+
anchors: getConfig().anchors,
|
|
80
|
+
remarkPlugins: [chassisAutoImportPlugin(), remarkCxConfig, remarkCxDocsref, myPlugin]
|
|
81
|
+
})
|
|
82
|
+
// ...
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
After:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { loadConfig } from '@chassis-ui/docs'
|
|
90
|
+
import { chassisDocs } from '@chassis-ui/docs/integration'
|
|
91
|
+
import { chassis } from './src/libs/astro'
|
|
92
|
+
import { siteConfigSchema } from './src/libs/config'
|
|
93
|
+
|
|
94
|
+
const root = import.meta.dirname
|
|
95
|
+
const config = loadConfig({ root, schema: siteConfigSchema })
|
|
96
|
+
|
|
97
|
+
export default defineConfig({
|
|
98
|
+
integrations: [
|
|
99
|
+
chassisDocs({ config, markdown: { remarkPlugins: [myPlugin] } }),
|
|
100
|
+
chassis({ config, root })
|
|
101
|
+
]
|
|
102
|
+
// ...
|
|
103
|
+
})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- Remove `site` and `markdown`. The integration sets both.
|
|
107
|
+
- Pass only your own remark and rehype plugins. `rehypeCxTable` is already included.
|
|
108
|
+
- A site that does not need the config in `astro.config.ts` calls `chassisDocs()` with
|
|
109
|
+
`configSchema` and does not call `loadConfig()`.
|
|
110
|
+
- Remove the Sass load path that points to `@chassis-ui/css/scss/vendor`, the folder of the
|
|
111
|
+
default `_chassis-tokens.scss`. The integration adds it, after the site's own load paths.
|
|
112
|
+
Keep a load path that points to tokens of your own.
|
|
113
|
+
|
|
114
|
+
### 4. Replace the files in `src/libs`
|
|
115
|
+
|
|
116
|
+
| File | What to do |
|
|
117
|
+
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
118
|
+
| `config.ts` | Replace the content with the schema of your own keys. See below. Delete the file if you have none. |
|
|
119
|
+
| `validation.ts` | Delete. `zVersionSemver`, `zVersionMajorMinor`, `zPrefixedVersionSemver` and `zLanguageCode` are in `@chassis-ui/docs/schema`. Keep validators of your own. |
|
|
120
|
+
| `clipboard.ts` | Delete. Import `initCopyButtons` from `@chassis-ui/docs/js/clipboard.ts` if your own code calls it. |
|
|
121
|
+
| `shortcode.ts` | Delete. See step 6. |
|
|
122
|
+
| `path.ts` | Delete. See step 5 for the replacements. |
|
|
123
|
+
| `remark.ts` | Delete `remarkCxConfig`, `remarkCxDocsref` and their helpers. Keep plugins of your own. |
|
|
124
|
+
| `data.ts` | Delete if `sidebar` was the only data you read. Otherwise replace the loader with `createDataLoader()`. See below. |
|
|
125
|
+
| `content.ts` | Delete `callouts`, `getCalloutByName` and `CalloutName`. Keep the collections that your own pages read. |
|
|
126
|
+
| `astro.ts` | Keep. It copies the static files and adds `mdx()` and `sitemap()`. Change it as described below. |
|
|
127
|
+
|
|
128
|
+
`src/libs/config.ts`:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { configSchema, z } from '@chassis-ui/docs/schema'
|
|
132
|
+
|
|
133
|
+
export const siteConfigSchema = configSchema.extend({
|
|
134
|
+
blog: z.url()
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
export type SiteConfig = z.infer<typeof siteConfigSchema>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`src/libs/data.ts`, for a site with data files of its own:
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import { createDataLoader } from '@chassis-ui/docs/site'
|
|
144
|
+
import { z } from '@chassis-ui/docs/schema'
|
|
145
|
+
|
|
146
|
+
export const getData = createDataLoader({
|
|
147
|
+
breakpoints: z.object({ name: z.string() }).array()
|
|
148
|
+
})
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
`src/libs/astro.ts`:
|
|
152
|
+
|
|
153
|
+
- Take `{ config, root }` as the argument of `chassis()`, and stop calling `getConfig()`.
|
|
154
|
+
- Remove `chassisAutoImportIntegration()` from the list of integrations.
|
|
155
|
+
- Remove the `astro:build:done` hook that calls `validateChassisDocsPaths()`.
|
|
156
|
+
- Import `getChassisAssetsFsPath`, `getChassisCSSFsPath`, `getChassisIconsFsPath` and
|
|
157
|
+
`getChassisTokensFsPath` from `@chassis-ui/docs` and call them with `{ root }`. Pass
|
|
158
|
+
`dir` when the folder is not the installed package, as in `chassis-css`, which copies
|
|
159
|
+
from `../css/dist`.
|
|
160
|
+
- Replace `getDocsFsPath()` with `root`, `getDocsPublicFsPath()` with
|
|
161
|
+
`path.join(root, 'public')`, and `getDocsStaticFsPath()` with
|
|
162
|
+
`path.join(root, 'static')`.
|
|
163
|
+
- Remove the Vite alias for `@chassis-ui/css` and `optimizeDeps: { exclude:
|
|
164
|
+
['@chassis-ui/docs'] }`. The integration now makes every script use one copy of
|
|
165
|
+
`@chassis-ui/css`, in the dev server and in the build. It needs no alias.
|
|
166
|
+
|
|
167
|
+
### 5. Replace the imports in pages and components
|
|
168
|
+
|
|
169
|
+
| 0.5 | 0.6 |
|
|
170
|
+
| --------------------------------------------------- | -------------------------------------------------- |
|
|
171
|
+
| `getConfig` from `@libs/config` | `getConfig` from `@chassis-ui/docs/site` |
|
|
172
|
+
| `getData('sidebar')` from `@libs/data` | `getSidebar()` from `@chassis-ui/docs/site` |
|
|
173
|
+
| `getChassisDocsPath` from `@libs/path` | `getDocsPath` from `@chassis-ui/docs/site` |
|
|
174
|
+
| `getDocsFsPath` from `@libs/path` | `getSiteRoot` from `@chassis-ui/docs/site` |
|
|
175
|
+
| `getDocsPublicFsPath` from `@libs/path` | `getPublicFsPath` from `@chassis-ui/docs/site` |
|
|
176
|
+
| `getDocsRelativePath(file)` from `@libs/path` | `getSiteFsPath(file)` from `@chassis-ui/docs/site` |
|
|
177
|
+
| `replaceConfigInText` from `@libs/remark` | `resolveConfigRefs` from `@chassis-ui/docs/site` |
|
|
178
|
+
| `replaceDocsrefInText` from `@libs/remark` | `resolveDocsrefs` from `@chassis-ui/docs/site` |
|
|
179
|
+
| `getCalloutByName` from `@libs/content` | `getCallout` from `@chassis-ui/docs/site` |
|
|
180
|
+
| A path into `node_modules/@chassis-ui/docs/src/` | `getPackageFilePath('js/color-modes.js')` |
|
|
181
|
+
| `@chassis-ui/docs/components/shortcodes/Icon.astro` | `@chassis-ui/docs/shortcodes/Icon.astro` |
|
|
182
|
+
|
|
183
|
+
Only the paths that the README lists under "Exports" resolve. `@chassis-ui/docs/libs/*`, the
|
|
184
|
+
folders inside `layouts/` and `components/`, and the partials under `scss/` other than `main`
|
|
185
|
+
and `vars` fail with "not exported". Import a layout or component by its name, such as
|
|
186
|
+
`@chassis-ui/docs/layouts/DocsLayout.astro`.
|
|
187
|
+
|
|
188
|
+
`getConfig()` returns the keys of the package. For the keys of your own, name your type:
|
|
189
|
+
`getConfig<SiteConfig>()`.
|
|
190
|
+
|
|
191
|
+
Use the schemas of the package in `src/content.config.ts`:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import { calloutsSchema, docsSchema } from '@chassis-ui/docs/schema'
|
|
195
|
+
|
|
196
|
+
const docsCollection = defineCollection({
|
|
197
|
+
loader: glob({ pattern: '**/*.{md,mdx}', base: './content/docs' }),
|
|
198
|
+
schema: docsSchema
|
|
199
|
+
})
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
`docsSchema` is already partial. Do not call `.partial()` on it.
|
|
203
|
+
|
|
204
|
+
### 6. Shortcodes
|
|
205
|
+
|
|
206
|
+
- Delete `src/types/auto-import.d.ts`. The integration writes the declarations into
|
|
207
|
+
`.astro/`.
|
|
208
|
+
- A shortcode in `src/components/shortcodes/` replaces the package's shortcode of the same
|
|
209
|
+
name. No configuration is needed.
|
|
210
|
+
- To leave out a shortcode of the package, pass
|
|
211
|
+
`chassisDocs({ shortcodes: { exclude: ['Icon'] } })`.
|
|
212
|
+
|
|
213
|
+
### 7. Path aliases
|
|
214
|
+
|
|
215
|
+
The package no longer needs `@libs/*`, `@scss/*` or `@shortcodes/*` in `tsconfig.json`.
|
|
216
|
+
Keep the ones that your own code imports.
|
|
217
|
+
|
|
218
|
+
The stylesheet that every page loads was `@scss/docs.scss`. It is now `src/scss/docs.scss`
|
|
219
|
+
in the site's root, which is the same file. Pass `styles` to the integration to name
|
|
220
|
+
another one.
|
|
221
|
+
|
|
222
|
+
### What changes in behaviour
|
|
223
|
+
|
|
224
|
+
- **Broken `[[docsref:]]` links fail the build.** Five sites only logged them. Fix the
|
|
225
|
+
links, or pass `brokenDocsrefs: 'warn'` until they are fixed.
|
|
226
|
+
- **A page of the sidebar may have no `title`.** The schema of `data/sidebar.yml` now
|
|
227
|
+
allows groups, so the type of `title` is `string | undefined`. Code of your own that
|
|
228
|
+
reads the sidebar has to handle that.
|
|
229
|
+
- **The header shows the Figma and GitHub links only when `figmaHandle` and `githubOrg`
|
|
230
|
+
are set.** The same holds for the X meta tags and `xUsername`, and for Google Analytics
|
|
231
|
+
and `analytics.googleId`.
|
|
232
|
+
- **`@chassis-ui/docs` and `@chassis-ui/css` are not pre-bundled in the dev server.** Both
|
|
233
|
+
are served from source, so a script of the site and a script of the package import the
|
|
234
|
+
same copy of `@chassis-ui/css`. The dependency `clipboard` is still pre-bundled.
|
|
235
|
+
- **The working directory of the build does not matter.** `config.yml`, `data/` and the
|
|
236
|
+
`file` props are found from the Astro root. A site that is built with
|
|
237
|
+
`astro build --root site` no longer names `./site/` in its paths.
|
|
238
|
+
|
|
239
|
+
### Check the result
|
|
240
|
+
|
|
241
|
+
Build the site before and after the upgrade and compare the output. An upgrade from 0.5.1
|
|
242
|
+
changes nothing in the output. An upgrade from 0.5.0 or 0.5.0-0 changes the "View on
|
|
243
|
+
GitHub" links, as the changelog describes for 0.5.1.
|
package/index.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Library functions. They are safe to import anywhere: in `astro.config.ts`, in a site's own
|
|
2
|
+
// integrations, and in pages. What pages read from the site is in `@chassis-ui/docs/site`.
|
|
3
|
+
export * from './src/libs/config'
|
|
4
|
+
export * from './src/libs/docs-path'
|
|
2
5
|
export * from './src/libs/highlight'
|
|
3
6
|
export * from './src/libs/image'
|
|
4
7
|
export * from './src/libs/layout'
|
|
5
8
|
export * from './src/libs/markdown'
|
|
9
|
+
export * from './src/libs/paths'
|
|
6
10
|
export * from './src/libs/placeholder'
|
|
7
11
|
export * from './src/libs/rehype'
|
|
12
|
+
export * from './src/libs/remark'
|
|
8
13
|
export * from './src/libs/shortcodes'
|
|
9
14
|
export * from './src/libs/site'
|
|
15
|
+
export * from './src/libs/source'
|
|
10
16
|
export * from './src/libs/toc'
|
|
11
17
|
export * from './src/libs/utils'
|