@chassis-ui/docs 0.6.3 → 0.8.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.
Files changed (32) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +50 -7
  3. package/UPGRADING.md +140 -0
  4. package/package.json +11 -3
  5. package/src/cli/assets.js +57 -9
  6. package/src/cli/main.js +32 -5
  7. package/src/components/DocsSidebar.astro +100 -102
  8. package/src/components/FeatureCard.astro +5 -7
  9. package/src/components/NavLink.astro +1 -1
  10. package/src/components/TableOfContents.astro +10 -12
  11. package/src/components/ThemeToggler.astro +5 -2
  12. package/src/components/shortcodes/Blockquote.astro +11 -13
  13. package/src/components/shortcodes/CSSOnly.astro +3 -3
  14. package/src/components/shortcodes/Code.astro +104 -108
  15. package/src/components/shortcodes/DeprecatedIn.astro +1 -3
  16. package/src/components/shortcodes/Example.astro +29 -33
  17. package/src/components/shortcodes/Icon.astro +19 -21
  18. package/src/components/shortcodes/InFigma.astro +3 -3
  19. package/src/components/shortcodes/Placeholder.astro +14 -16
  20. package/src/components/shortcodes/ResizableExample.astro +3 -5
  21. package/src/js/search.js +2 -2
  22. package/src/layouts/BaseLayout.astro +14 -20
  23. package/src/layouts/DocsLayout.astro +51 -52
  24. package/src/layouts/SingleLayout.astro +2 -2
  25. package/src/layouts/footer/Consent.astro +18 -20
  26. package/src/layouts/footer/Footer.astro +62 -26
  27. package/src/layouts/head/Head.astro +7 -10
  28. package/src/layouts/header/Navigation.astro +73 -58
  29. package/src/layouts/header/SearchDialog.astro +10 -4
  30. package/src/layouts/header/SearchTrigger.astro +2 -4
  31. package/src/layouts/header/Skippy.astro +8 -8
  32. package/src/scss/_layout.scss +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @chassis-ui/docs
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - **Breaking.** The pages load their fonts from the site's own static files, no longer from Google Fonts. `Head.astro` links `fonts/text.css`, `fonts/display.css` and `fonts/code.css` under the static path, `/static/` by default, in place of the Google Fonts stylesheet and the `preconnect` links to `fonts.googleapis.com` and `fonts.gstatic.com`. The three stylesheets and the font files they load are in the docs build of `chassis-assets`, which a site copies into `static/` already. A site moves its `vendor/assets` submodule to `acb5d2e` of `app/docs` or later, with `pnpm sync-submodules`: there the stylesheets declare Inter, Archivo Narrow and Fira Code as variable fonts, with every weight the styles use. With a commit before `77912ed` they declare four weights of each family. The Inter of the assets has an optical size axis, which the font of Google Fonts had not, and a browser follows it: text above 14 pixels is narrower, 7% at 57 pixels. A site keeps the look it had by building the assets with `--subset` of `chassis-docs vendor`, which fixes the axis at 14 from `acb5d2e` on, or by setting `font-optical-sizing: none` in its styles. A site that does not copy the docs build provides the three stylesheets itself.
8
+ - `chassis-docs vendor` and `chassis-docs sync-submodules` take `--subset <range>`, repeatable, and `--split` or `--no-split` with it. With `--subset` the fonts of the docs build of `chassis-assets` are written with the characters of the ranges only, such as `--subset latin --subset latin-ext`, and the optical size axis of Inter is fixed at 14, as `chassis-assets` sets it for the `chassis` brand. With `--split` each font is also written in a file per range, and its stylesheet names them with a `unicode-range`, so a page loads a range only when it has a character of it; without `--split` and `--no-split` the setting of `chassis-assets` decides, which is one file. With the two ranges and the split, a page in English loads `text-latin.woff2`, 69 KB, where the whole `text.woff2` is 349 KB, and `code-latin.woff2`, 43 KB, where `code.woff2` is 109 KB. A character outside the ranges is drawn with the next font of the font stack. With `--subset` the commands run `pnpm install --filter ./packages/assets --prod` in the submodule, in place of `pnpm install --ignore-workspace`, since the build loads a package to subset a font. The options need `vendor/assets` at `acb5d2e` of `app/docs` or later. Without them nothing changes.
9
+
10
+ ## 0.7.0
11
+
12
+ ### Minor Changes
13
+
14
+ - **Breaking.** The package needs `@chassis-ui/css` 0.6.0 or later: the peer range is `>=0.6.0`, it was `^0.5.0-0`. The layouts use the CSS grid of css 0.6, `.grid` with `col-span-*`, in place of the flexbox grid, `.row` with `.col-*`, which css 0.6 deprecates and css 0.7 removes. The header of `SingleLayout`, the sections list of `DocsLayout`, the footer and the lists of the header are grids. `NavLink` no longer sets a width: the lists of the header are two columns below `lg` by themselves. The loading rows of the search use the fraction widths, `w-4/12`. `.cxd-gutter` sets `--cx-container-padding` in place of `--cx-gutter-x`, with the same page margin of 1rem. The pages look as before, except that the footer columns are separated by the gutter of the breakpoint and move by a few pixels. See [UPGRADING.md](https://github.com/chassis-ui/website/blob/main/packages/docs/UPGRADING.md#from-06-to-07) for the classes to replace in a site's own pages.
15
+
3
16
  ## 0.6.3
4
17
 
5
18
  ### Patch Changes
package/README.md CHANGED
@@ -10,7 +10,7 @@
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).
13
+ Coming from an earlier version? See [UPGRADING.md](UPGRADING.md).
14
14
 
15
15
  ## Installation
16
16
 
@@ -23,7 +23,7 @@ pnpm add @chassis-ui/docs
23
23
  ```json
24
24
  {
25
25
  "@astrojs/markdown-remark": "^7.0.0",
26
- "@chassis-ui/css": "^0.5.0-0",
26
+ "@chassis-ui/css": ">=0.6.0",
27
27
  "@pagefind/component-ui": "^1.0.0",
28
28
  "@shikijs/transformers": "^4.3.1",
29
29
  "astro": "^7.0.0",
@@ -184,18 +184,43 @@ export const collections = {
184
184
 
185
185
  The layouts link to files under `/static/`, which the site puts into `static/` of its `public` directory:
186
186
 
187
- | URL | From |
188
- | -------------------------------------------------------------------- | ----------------------------------------- |
189
- | `/static/css/chassis.css`, `/static/css/chassis.min.css` | the `dist` folder of `@chassis-ui/css` |
190
- | `/static/icons/chassis-icons.svg`, `/static/icons/chassis-icons.css` | the `icons` folder of `@chassis-ui/icons` |
191
- | `/static/images/*`: logo, favicons, social image | the docs build of `chassis-assets` |
187
+ | URL | From |
188
+ | ---------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
189
+ | `/static/css/chassis.css`, `/static/css/chassis.min.css` | the `dist` folder of `@chassis-ui/css` |
190
+ | `/static/icons/chassis-icons.svg`, `/static/icons/chassis-icons.css` | the `icons` folder of `@chassis-ui/icons` |
191
+ | `/static/images/site-logo.svg`, the logo of the navigation bar and the footer | the docs build of `chassis-assets` |
192
+ | `/static/images/favicon.png`, `favicon-16x16.png`, `favicon-32x32.png` and `apple-touch-icon.png` | the docs build of `chassis-assets` |
193
+ | `/static/images/social-image.png`, the image of a page without a `thumbnail`. The build reads its size, and fails without the file | the docs build of `chassis-assets` |
194
+ | `/static/fonts/text.css`, `/static/fonts/display.css`, `/static/fonts/code.css`, and the font files they load | the docs build of `chassis-assets` |
195
+ | `/static/images/manifest.json`, the web app manifest | the site itself. The starter has one in `static/images/` |
192
196
 
193
197
  `chassis-docs vendor` builds the docs build of `chassis-assets` in the `vendor/assets` submodule. See [Commands](#commands).
194
198
 
199
+ Nothing else of the docs build is read by the package. A site copies the whole build into `static/`, and its own pages may read more of it.
200
+
195
201
  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 }`.
196
202
 
197
203
  A site that type-checks with `astro check` declares the `@chassis-ui/css` module, which has no types: `declare module '@chassis-ui/css'`.
198
204
 
205
+ #### What the Chassis sites read from the docs build
206
+
207
+ The sites of the Chassis projects read these files besides, by name, from the docs build of the `chassis` brand:
208
+
209
+ | File of the docs build | Read by |
210
+ | ------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
211
+ | `icons/cx-sprite.svg` | The home page of each of the seven sites, which imports it. The build fails without it |
212
+ | `images/apple-touch-icon.png`, `images/favicon.png` | Each of the seven sites, which copies them to `/apple-touch-icon.png` and `/favicon.ico` |
213
+ | `images/android-chrome-192x192.png`, `images/android-chrome-512x512.png` | The `manifest.json` of each of the seven sites |
214
+ | `images/home/` | The home page of the website. The home page of chassis-tokens reads `comp-gallery-*` of it |
215
+ | `images/logo/chassis-{logo,icon}-{brand,white}-banner.svg` | The about page of the website |
216
+ | `images/social-image.png` | The blog of the website, for a post without an image |
217
+ | `images/site-logo.svg` | The examples of the navbar page of chassis-css. The README of `@chassis-ui/react`, by its URL on chassis-ui.com |
218
+ | `images/figma/components/` | The component pages of chassis-figma |
219
+
220
+ The vanilla HTML example, in the `vanilla-example` repository, builds the assets itself from a `vendor/assets` submodule of its own, for the brand of each of its sites, and takes `fonts/text.css`, `fonts/display.css` and `fonts/code.css`, the font files they load, the license of each font and `images/logo/chassis-icon-brand.svg`.
221
+
222
+ `contracts` in `chassis.checks.json` of `chassis-assets` names the files that a site reads, with the code that reads each, and `pnpm assets:contract` there checks a build against it.
223
+
199
224
  #### A site under a prefix
200
225
 
201
226
  A site that is served under a path of another host, such as `chassis-ui.com/css`, cannot use `/static/` there: that path belongs to the host's own site. It loads its static files under a path of its own instead:
@@ -292,6 +317,22 @@ The package installs a `chassis-docs` command with the build steps that every Ch
292
317
 
293
318
  `vendor` and `sync-submodules` work from any folder of the repository. They need Git, Git LFS and pnpm. `sync-submodules --branch <name>`, or the `SUBMODULE_BRANCH` variable, follows another branch.
294
319
 
320
+ Both take `--subset <range>`, which writes the fonts of the build with the characters of the range only, so that a page downloads smaller font files. A range is a name that `chassis-assets` knows, such as `latin` or `latin-ext`, or a range written as `U+0370-03FF`, and the option is repeatable:
321
+
322
+ ```json
323
+ {
324
+ "scripts": {
325
+ "vendor": "chassis-docs vendor --subset latin --subset latin-ext --split"
326
+ }
327
+ }
328
+ ```
329
+
330
+ A character outside the ranges is drawn with the next font of the font stack. With the option, the commands install the package of the build in the submodule, `pnpm install --filter ./packages/assets --prod`, in place of `pnpm install --ignore-workspace`: it holds the package that subsets a font.
331
+
332
+ `--subset` also fixes the axes of a variable font that `chassis-assets` names for the brand: the optical size of Inter at 14, so that text has the width it had with Google Fonts. A site that builds without `--subset` sets `font-optical-sizing: none` in its styles for the same look.
333
+
334
+ `--split`, with `--subset`, writes each font in a file per range as well, such as `text-latin.woff2` and `text-latin-ext.woff2`, and the stylesheets name them with a `unicode-range`: a page loads the file of a range only when it has a character of it. `--no-split` writes one file per font. Without either, the setting of `chassis-assets` decides, which is one file.
335
+
295
336
  Each command exits with 1 when it fails, so a script or CI job stops there.
296
337
 
297
338
  ### Validating HTML
@@ -376,6 +417,8 @@ The integration provides five modules: `virtual:chassis-docs/config`, `virtual:c
376
417
 
377
418
  | `@chassis-ui/docs` | Requires Astro | Requires `@chassis-ui/css` | Requires Node | Built with |
378
419
  | ------------------ | -------------------------- | -------------------------- | ------------- | ------------------------------------ |
420
+ | 0.8.0 | `^7.0.0` | `>=0.6.0` | `>=22.12.0` | Astro 7.3.5, css 0.7.1, tokens 0.7.0 |
421
+ | 0.7.0 | `^7.0.0` | `>=0.6.0` | `>=22.12.0` | Astro 7.3.5, css 0.6.0, tokens 0.6.0 |
379
422
  | 0.6.3 | `^7.0.0` | `^0.5.0-0` | `>=22.12.0` | Astro 7.3.5, css 0.5.2, tokens 0.6.0 |
380
423
  | 0.6.2 | `^7.0.0` | `^0.5.0-0` | `>=22.12.0` | Astro 7.3.5, css 0.5.2, tokens 0.6.0 |
381
424
  | 0.6.1 | `^7.0.0` | `^0.5.0-0` | `>=22.12.0` | Astro 7.3.5, css 0.5.2, tokens 0.6.0 |
package/UPGRADING.md CHANGED
@@ -1,5 +1,145 @@
1
1
  # Upgrading @chassis-ui/docs
2
2
 
3
+ ## From 0.7 to 0.8
4
+
5
+ 0.8.0 loads the fonts from the site's own static files, no longer from Google Fonts. The
6
+ head of every page links `fonts/text.css`, `fonts/display.css` and `fonts/code.css` under
7
+ the static path, `/static/` by default. The three stylesheets and the font files they load
8
+ are in the docs build of `chassis-assets`, which a site copies into `static/` already.
9
+
10
+ ### 1. Update the dependency
11
+
12
+ ```sh
13
+ pnpm add -D @chassis-ui/docs@^0.8.0
14
+ ```
15
+
16
+ ### 2. Move the `vendor/assets` submodule
17
+
18
+ ```sh
19
+ pnpm sync-submodules
20
+ ```
21
+
22
+ The pages need `vendor/assets` at `acb5d2e` of `app/docs` or later: there the stylesheets
23
+ declare Inter, Archivo Narrow and Fira Code as variable fonts, with every weight the styles
24
+ use. With a commit before `77912ed` they declare four weights of each family. Commit the
25
+ new pointer.
26
+
27
+ A site that does not copy the docs build provides the three stylesheets itself, at the
28
+ same paths.
29
+
30
+ ### 3. Subset the fonts
31
+
32
+ Add `--subset` and `--split` to the `vendor` and `sync-submodules` scripts:
33
+
34
+ ```json
35
+ {
36
+ "scripts": {
37
+ "vendor": "chassis-docs vendor --subset latin --subset latin-ext --split",
38
+ "sync-submodules": "chassis-docs sync-submodules --subset latin --subset latin-ext --split"
39
+ }
40
+ }
41
+ ```
42
+
43
+ The step is optional, and it does two things:
44
+
45
+ - The fonts hold the characters of the ranges only, each range in a file of its own that a
46
+ page loads when it has a character of it. A page in English loads `text-latin.woff2`,
47
+ 69 KB, where the whole `text.woff2` is 349 KB. A character outside the ranges is drawn
48
+ with the next font of the font stack, so name the range of every script your pages use:
49
+ a name that `chassis-assets` knows, or a range written as `U+0370-03FF`. See
50
+ [Commands](README.md#commands) in the README.
51
+ - The optical size axis of Inter is fixed at 14. See "What changes on the pages" below.
52
+
53
+ With `--subset` the commands install the package of the build in the submodule, which
54
+ holds the package that subsets a font.
55
+
56
+ ### 4. Remove Google Fonts from your policy and your privacy page
57
+
58
+ No page requests `fonts.googleapis.com` or `fonts.gstatic.com` any more. Remove the two
59
+ hosts from a content security policy of your own, and a sentence about Google Fonts from a
60
+ privacy page. The sites under chassis-ui.com have the policy of the website, which no
61
+ longer allows the two hosts.
62
+
63
+ ### What changes on the pages
64
+
65
+ - **Inter follows its optical size axis.** The Inter of the assets has the axis, which the
66
+ font of Google Fonts had not, and a browser follows it: text above 14 pixels is narrower,
67
+ 7% at 57 pixels. Step 3 fixes the axis at 14, so text has the width it had. A site that
68
+ builds without `--subset` sets `font-optical-sizing: none` in its styles for the same
69
+ look.
70
+ - **Inter has an italic file.** Italic text was drawn by slanting the upright font.
71
+ - **The head has no `preconnect` links** to the two hosts of Google Fonts.
72
+
73
+ ### Check the result
74
+
75
+ Build the site before and after the upgrade and compare the pages in a browser. With
76
+ step 3 the text keeps its width, so nothing moves. Check in the network panel that no
77
+ request goes to `fonts.googleapis.com` or `fonts.gstatic.com`.
78
+
79
+ ## From 0.6 to 0.7
80
+
81
+ 0.7.0 needs `@chassis-ui/css` 0.6.0 or later. The layouts use the CSS grid of that version,
82
+ `.grid` with `col-span-*`, in place of the flexbox grid, `.row` with `.col-*`. css 0.6
83
+ deprecates the flexbox grid and css 0.7 removes it.
84
+
85
+ ### 1. Update the dependencies
86
+
87
+ ```sh
88
+ pnpm add -D @chassis-ui/docs@^0.7.0 @chassis-ui/css@^0.6.0
89
+ ```
90
+
91
+ css 0.6.0 has changes of its own. Read its
92
+ [changelog](https://github.com/chassis-ui/css/blob/main/packages/css/CHANGELOG.md) first:
93
+ among them, the default gap of `.grid` is now the gutter token of the breakpoint.
94
+
95
+ ### 2. Move your own pages off the flexbox grid
96
+
97
+ css 0.6 still has the flexbox grid, so the site builds and looks as before without this
98
+ step. css 0.7 removes it. Replace the classes in your own components, pages and content:
99
+
100
+ | Flexbox grid | CSS grid |
101
+ | ---------------------------------------- | -------------------------------------------------- |
102
+ | `row` | `grid` |
103
+ | `col-6`, `md:col-6` | `col-span-6`, `col-span-full md:col-span-6` |
104
+ | `col-12` | `col-span-full` |
105
+ | `row row-cols-1 md:row-cols-3` and `col` | `grid grid-cols-1 md:grid-cols-3`, no class inside |
106
+ | `offset-1` | `col-start-2` |
107
+ | `col lg:col-10 mx-auto` | `col-span-full lg:col-span-10 lg:col-start-2` |
108
+ | `g-md`, `gx-md`, `gy-md` | `gap-md`, `column-gap-md`, `row-gap-md` |
109
+ | `col-auto` | `d-flex` with `gap-*` on the parent |
110
+ | `col-6` outside a `row` | `w-6/12` |
111
+ | `col` outside a `row` | `flex-fill` |
112
+
113
+ - An item without a span is one column wide. A column that was full width below its
114
+ breakpoint, such as `md:col-6`, needs `col-span-full` too.
115
+ - A `row` without a gutter class had a gutter of 1.5rem between columns and none between
116
+ rows. A `grid` has the gutter of the breakpoint in both directions, from 0.5rem to 3rem.
117
+ Add `row-gap-0` where the items have margins of their own.
118
+ - A grid beside the sidebar, or in a card, is narrower than the viewport that the gutter
119
+ follows. Give it a `gap-*` class, and `grid-cols-{n}` in place of twelve columns.
120
+ - An auto margin shrinks a grid item to its content. Center an item with `col-start-*`.
121
+
122
+ The [grid page](https://chassis-ui.com/css/docs/layout/grid/) of Chassis CSS has the full
123
+ table.
124
+
125
+ ### What changes in the package
126
+
127
+ - **`NavLink` sets no width.** Its item was `nav-item col-6 lg:col-auto`, half of the list
128
+ below `lg`. It is `nav-item` now, and the lists of the header are a grid of two columns
129
+ below `lg`. A list of your own that relied on the two columns takes
130
+ `d-grid grid-cols-2 lg:d-flex`.
131
+ - **`.cxd-gutter` sets `--cx-container-padding`.** It set `--cx-gutter-x`, which the
132
+ container stops reading in css 0.7. The page margin of the docs layout is 1rem, as
133
+ before. A rule of your own that set `--cx-gutter-x` on that element sets
134
+ `--cx-container-padding` to half of it.
135
+ - **The footer and the header of `SingleLayout` take the gutter of the breakpoint.** The
136
+ footer columns move by a few pixels, 20 at most on the widest screens.
137
+
138
+ ### Check the result
139
+
140
+ Build the site before and after the upgrade and compare the pages in a browser, at a phone
141
+ width and a desktop width. Apart from the footer columns, nothing of the package moves.
142
+
3
143
  ## From 0.5 to 0.6
4
144
 
5
145
  0.6.0 is a breaking release. In 0.5 a site had to supply five modules behind a `@libs/*`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chassis-ui/docs",
3
3
  "description": "Shared Astro components and layouts for Chassis documentation sites.",
4
- "version": "0.6.3",
4
+ "version": "0.8.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -70,7 +70,7 @@
70
70
  },
71
71
  "peerDependencies": {
72
72
  "@astrojs/markdown-remark": "^7.0.0",
73
- "@chassis-ui/css": "^0.5.0-0",
73
+ "@chassis-ui/css": ">=0.6.0",
74
74
  "@pagefind/component-ui": "^1.0.0",
75
75
  "@shikijs/transformers": "^4.3.1",
76
76
  "astro": "^7.0.0",
@@ -106,8 +106,16 @@
106
106
  "unist-util-visit": "^5.1.0"
107
107
  },
108
108
  "devDependencies": {
109
+ "@astrojs/markdown-remark": "^7.3.1",
110
+ "@chassis-ui/css": "^0.7.1",
111
+ "@pagefind/component-ui": "^1.5.2",
112
+ "@shikijs/transformers": "^4.5.0",
109
113
  "astro": "^7.3.5",
114
+ "html-validate": "^11.16.1",
115
+ "rehype-autolink-headings": "^7.1.0",
110
116
  "remark-mdx": "^3.1.1",
111
- "vfile": "^6.0.3"
117
+ "sass": "^1.105.1",
118
+ "vfile": "^6.0.3",
119
+ "vnu-jar": "^26.10.2"
112
120
  }
113
121
  }
package/src/cli/assets.js CHANGED
@@ -11,6 +11,9 @@ export const ASSETS_OUTPUT = 'dist/web/docs/chassis'
11
11
  /** The branch of chassis-assets that the docs sites follow. */
12
12
  export const DEFAULT_BRANCH = 'app/docs'
13
13
 
14
+ /** The package of the build inside the submodule, which names the packages its options load. */
15
+ export const ASSETS_PACKAGE = './packages/assets'
16
+
14
17
  /**
15
18
  * The root of the repository that contains the working directory, so that the commands
16
19
  * work from a site's folder too.
@@ -22,24 +25,34 @@ function repositoryRoot(run) {
22
25
 
23
26
  /**
24
27
  * Checks out `vendor/assets` at the commit that the repository pins, and builds it.
25
- * @param {{ root?: string, run?: typeof defaultRun }} [options]
28
+ * @param {{ root?: string, subset?: string[], split?: boolean, run?: typeof defaultRun }} [options]
26
29
  */
27
- export function buildAssets({ run = defaultRun, root = repositoryRoot(run) } = {}) {
30
+ export function buildAssets({
31
+ run = defaultRun,
32
+ root = repositoryRoot(run),
33
+ subset = [],
34
+ split
35
+ } = {}) {
36
+ const fonts = fontOptions(subset, split)
37
+
28
38
  log(`Building ${ASSETS_PATH} at the pinned commit`)
29
39
  run('git', ['submodule', 'update', '--init', ASSETS_PATH], { cwd: root })
30
- buildCheckout(root, run)
40
+ buildCheckout(root, run, fonts)
31
41
  }
32
42
 
33
43
  /**
34
44
  * Moves `vendor/assets` to the latest commit of `branch`, and builds it. The repository
35
45
  * then has a changed submodule pointer to commit.
36
- * @param {{ root?: string, branch?: string, run?: typeof defaultRun }} [options]
46
+ * @param {{ root?: string, branch?: string, subset?: string[], split?: boolean, run?: typeof defaultRun }} [options]
37
47
  */
38
48
  export function syncAssets({
39
49
  run = defaultRun,
40
50
  root = repositoryRoot(run),
41
- branch = DEFAULT_BRANCH
51
+ branch = DEFAULT_BRANCH,
52
+ subset = [],
53
+ split
42
54
  } = {}) {
55
+ const fonts = fontOptions(subset, split)
43
56
  const dir = path.join(root, ASSETS_PATH)
44
57
  const git = (args, quiet = true) => run('git', args, { cwd: dir, quiet })
45
58
 
@@ -68,7 +81,7 @@ export function syncAssets({
68
81
  }
69
82
 
70
83
  git(['pull', '--ff-only', 'origin', branch])
71
- buildCheckout(root, run)
84
+ buildCheckout(root, run, fonts)
72
85
 
73
86
  const commit = git(['rev-parse', '--short', 'HEAD']).trim()
74
87
  const moved = run('git', ['status', '--porcelain', '--', ASSETS_PATH], {
@@ -92,14 +105,49 @@ function hasLocalBranch(git, branch) {
92
105
  }
93
106
  }
94
107
 
95
- function buildCheckout(root, run) {
108
+ /**
109
+ * The options of the build for the fonts: the ranges of `--subset`, then `--split` or
110
+ * `--no-split` when the site decides it, and nothing when the fonts stay whole. Without
111
+ * either of the two, the build takes `split` of `chassis.subset` of chassis-assets.
112
+ * @param {string[]} subset
113
+ * @param {boolean} [split]
114
+ * @returns {string[]}
115
+ */
116
+ function fontOptions(subset, split) {
117
+ if (subset.length === 0) {
118
+ if (split !== undefined) {
119
+ throw new CommandError('--split and --no-split need --subset: a font is split by its ranges.')
120
+ }
121
+
122
+ return []
123
+ }
124
+
125
+ const decided = split === undefined ? [] : [split ? '--split' : '--no-split']
126
+
127
+ return ['--subset', ...subset, ...decided]
128
+ }
129
+
130
+ function buildCheckout(root, run, fonts = []) {
96
131
  const dir = path.join(root, ASSETS_PATH)
97
132
 
98
133
  // The images are stored with Git LFS. Without it they are pointer files.
99
134
  run('git', ['lfs', 'install', '--local'], { cwd: dir, quiet: true })
100
135
  run('git', ['lfs', 'pull'], { cwd: dir })
101
- run('pnpm', ['install', '--ignore-workspace'], { cwd: dir })
102
- run('pnpm', ['assets:site'], { cwd: dir })
136
+
137
+ if (fonts.length > 0) {
138
+ // The subsetter is a package that the build loads, so the package of the build is
139
+ // installed, without the tools of its tests. Where an install without the workspace
140
+ // ran before, pnpm removes its modules first, and would ask.
141
+ run(
142
+ 'pnpm',
143
+ ['install', '--filter', ASSETS_PACKAGE, '--prod', '--config.confirmModulesPurge=false'],
144
+ { cwd: dir }
145
+ )
146
+ run('pnpm', ['assets:site', ...fonts], { cwd: dir })
147
+ } else {
148
+ run('pnpm', ['install', '--ignore-workspace'], { cwd: dir })
149
+ run('pnpm', ['assets:site'], { cwd: dir })
150
+ }
103
151
 
104
152
  const output = path.join(dir, ASSETS_OUTPUT)
105
153
 
package/src/cli/main.js CHANGED
@@ -14,6 +14,14 @@ Commands:
14
14
  vendor Build vendor/assets at the commit that the repository pins
15
15
  sync-submodules Move vendor/assets to the latest commit of a branch, and build it
16
16
  --branch <name> The branch of chassis-assets (default: $SUBMODULE_BRANCH or ${DEFAULT_BRANCH})
17
+
18
+ Both builds:
19
+ --subset <range> Write the web fonts with the characters of a range only, such as
20
+ latin or U+0370-03FF. Repeatable
21
+ --split With --subset, write a font in a file per range, which a page
22
+ loads when it has a character of the range
23
+ --no-split With --subset, write a font in one file (default: the setting
24
+ of chassis-assets)
17
25
  html-validate [paths] Validate the HTML files in paths (default: _site) with html-validate
18
26
  --config <file> A JSON config of html-validate, added to the defaults
19
27
  vnu [paths] Validate paths (default: _site) with the Nu Html Checker. Needs Java
@@ -27,6 +35,21 @@ Commands:
27
35
 
28
36
  html-validate and vnu need the html-validate and vnu-jar packages in the site's devDependencies.`
29
37
 
38
+ const fontOptions = {
39
+ subset: { type: 'string', multiple: true },
40
+ split: { type: 'boolean' },
41
+ 'no-split': { type: 'boolean' }
42
+ }
43
+
44
+ // `--split` is true and `--no-split` is false. Neither leaves the decision to chassis-assets.
45
+ function splitOf(values) {
46
+ if (values.split && values['no-split']) {
47
+ throw new CommandError('Give --split or --no-split, not both.')
48
+ }
49
+
50
+ return values.split ? true : values['no-split'] ? false : undefined
51
+ }
52
+
30
53
  const ignoreOptions = {
31
54
  ignore: { type: 'string', multiple: true },
32
55
  'no-default-ignore': { type: 'boolean' }
@@ -39,16 +62,20 @@ function ignoresOf(values, paths) {
39
62
 
40
63
  const commands = {
41
64
  vendor: {
42
- options: {},
43
- run: () => {
44
- buildAssets()
65
+ options: { ...fontOptions },
66
+ run: ({ values }) => {
67
+ buildAssets({ subset: values.subset, split: splitOf(values) })
45
68
  return 0
46
69
  }
47
70
  },
48
71
  'sync-submodules': {
49
- options: { branch: { type: 'string' } },
72
+ options: { branch: { type: 'string' }, ...fontOptions },
50
73
  run: ({ values }) => {
51
- syncAssets({ branch: values.branch ?? process.env.SUBMODULE_BRANCH ?? DEFAULT_BRANCH })
74
+ syncAssets({
75
+ branch: values.branch ?? process.env.SUBMODULE_BRANCH ?? DEFAULT_BRANCH,
76
+ subset: values.subset,
77
+ split: splitOf(values)
78
+ })
52
79
  return 0
53
80
  }
54
81
  },