From 6ac2da115d847d8d110d905f7d2f0a9eb4901a60 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Sun, 30 Jan 2022 15:04:20 +0100 Subject: [PATCH] Refactored build process --- docs/creating-your-site.md | 4 +- docs/schema/assets/fonts.json | 7 +++ tools/build/index.ts | 90 ++++++++++++++++++----------------- 3 files changed, 56 insertions(+), 45 deletions(-) diff --git a/docs/creating-your-site.md b/docs/creating-your-site.md index 1256da3f4..be041e9fe 100644 --- a/docs/creating-your-site.md +++ b/docs/creating-your-site.md @@ -92,7 +92,7 @@ slightly different: [mkdocs_theme.yml]: https://github.com/squidfunk/mkdocs-material/blob/master/src/mkdocs_theme.yml [custom theme guide]: https://www.mkdocs.org/user-guide/custom-themes/#creating-a-custom-theme -???+ tip "Recommended: configuration validation and auto-complete" +???+ tip "Recommended: [configuration validation and auto-complete]" In order to minimize friction and maximize productivity, Material for MkDocs provides its own [schema.json] for `mkdocs.yml`. If your editor supports @@ -121,7 +121,7 @@ slightly different: # yaml-language-server: $schema=https://squidfunk.github.io/mkdocs-material/schema.json ``` - + [configuration validation and auto-complete]: https://twitter.com/squidfunk/status/1487746003692400642 [schema.json]: schema.json [vscode-yaml]: https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml [settings.json]: https://code.visualstudio.com/docs/getstarted/settings diff --git a/docs/schema/assets/fonts.json b/docs/schema/assets/fonts.json index 7953c29bb..5cd66a8db 100644 --- a/docs/schema/assets/fonts.json +++ b/docs/schema/assets/fonts.json @@ -7045,6 +7045,13 @@ "enum": [ "Zilla Slab Highlight" ] + }, + { + "title": "default", + "markdownDescription": "https://fonts.google.com/specimen/default", + "enum": [ + "default" + ] } ] } \ No newline at end of file diff --git a/tools/build/index.ts b/tools/build/index.ts index cd1ce1dc5..edb11d820 100644 --- a/tools/build/index.ts +++ b/tools/build/index.ts @@ -20,7 +20,6 @@ * IN THE SOFTWARE. */ -import fonts from "google-fonts-complete" import { minify as minhtml } from "html-minifier" import * as path from "path" import { @@ -290,49 +289,54 @@ const index$ = zip(icons$, emojis$) /* ------------------------------------------------------------------------- */ -/* Compute font schema */ -const fonts$ = of(Object.keys(fonts)) - .pipe( - map(items => ({ - "$schema": "https://json-schema.org/draft-07/schema", - "title": "Google Fonts", - "markdownDescription": "https://fonts.google.com/", - "type": "string", - "oneOf": items.map(item => ({ - "title": item, - "markdownDescription": `https://fonts.google.com/specimen/${ - item.replace(/\s+/g, "+") - }`, - "enum": [ - item - ], - })) - })), - switchMap(data => write( - "docs/schema/assets/fonts.json", - JSON.stringify(data, undefined, 2) - )) - ) - -const icons2$ = icons$ - .pipe( - map(icons => ({ - "$schema": "https://json-schema.org/draft-07/schema", - "title": "Icon", - "markdownDescription": "https://squidfunk.github.io/mkdocs-material/reference/icons-emojis/#search", - "type": "string", - "enum": [...icons.values()].map(item => item.replace(".svg", "")) - })), - switchMap(data => write( - "docs/schema/assets/icons.json", - JSON.stringify(data, undefined, 2) - )) - ) - - - /* Build schema */ -const schema$ = merge(fonts$, icons2$) +const schema$ = merge( + + /* Compute fonts schema */ + defer(() => import("google-fonts-complete")) + .pipe( + map(Object.keys), + map(fonts => ({ + "$schema": "https://json-schema.org/draft-07/schema", + "title": "Google Fonts", + "markdownDescription": "https://fonts.google.com/", + "type": "string", + "oneOf": fonts.map(font => ({ + "title": font, + "markdownDescription": `https://fonts.google.com/specimen/${ + font.replace(/\s+/g, "+") + }`, + "enum": [ + font + ], + })) + })), + switchMap(data => write( + "docs/schema/assets/fonts.json", + JSON.stringify(data, undefined, 2) + )) + ), + + /* Compute icons schema */ + icons$ + .pipe( + map(icons => [...icons.values()]), + map(icons => ({ + "$schema": "https://json-schema.org/draft-07/schema", + "title": "Icon", + "markdownDescription": [ + "https://squidfunk.github.io/mkdocs-material", + "reference/icons-emojis/#search" + ].join("/"), + "type": "string", + "enum": icons.map(icon => icon.replace(".svg", "")) + })), + switchMap(data => write( + "docs/schema/assets/icons.json", + JSON.stringify(data, undefined, 2) + )) + ) +) /* ---------------------------------------------------------------------------- * Program