@mark1russell7/site-pages 0.2.13 → 0.2.18
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/README.md +14 -2
- package/build/chunks/build.js +79 -8
- package/build/chunks/build.js.map +1 -1
- package/build/chunks/freshness.d.ts +2 -0
- package/build/chunks/freshness.d.ts.map +1 -1
- package/build/chunks/freshness.js +14 -4
- package/build/chunks/freshness.js.map +1 -1
- package/build/index.d.ts +47 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -3
- package/build/vite.d.ts +13 -0
- package/build/vite.d.ts.map +1 -1
- package/build/vite.js +23 -1
- package/build/vite.js.map +1 -1
- package/package.json +1 -1
package/build/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["/**\n * The build side of the shell of a site: a Vite plugin and its parts. Import this module from\n * `@mark1russell7/site-pages/vite`. It is for `vite.config.ts`, not for a browser.\n *\n * This module does not import Vite. The types of the plugin are the small part that it uses, so the\n * package keeps no dependency. A test examines that Vite accepts the plugin.\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { BuildInfo } from \"./chrome.ts\";\nimport { parseDataStamps, type DataStamps } from \"./check/freshness.ts\";\nimport { git, headCommit } from \"./data/git.ts\";\nimport { KPI_FILE, kpiFile, kpiText, type KpiInput } from \"./data/kpi.ts\";\nimport { renderDataStamp } from \"./render/data-stamp.ts\";\n\nexport type { BuildInfo } from \"./chrome.ts\";\n\n/** The environment variables that this module reads. */\nexport type SiteEnv = Readonly<Record<string, string | undefined>>;\n\n/** The options of `siteShell`. */\nexport interface SiteShellOptions {\n /** The `localStorage` key of the theme. Give the same key to `setupTheme` in the page. */\n readonly themeKey: string;\n /**\n * The file with the version for `__BUILD__`, relative to the folder of the site. The default is\n * `../package.json`. The value `false` gives a build with no version.\n */\n readonly packageFile?: string | false | undefined;\n}\n\n/** The value of `build.target` in a Vite config. */\nexport type SiteTarget = string | string[] | false;\n\n/** The part of the Vite config that `siteShell` reads. */\nexport interface SiteShellConfigInput {\n readonly root?: string | undefined;\n readonly base?: string | undefined;\n readonly build?: { readonly target?: SiteTarget | undefined } | null | undefined;\n}\n\n/** The part of the Vite config that `siteShell` sets. Vite merges it into the config of the site. */\nexport interface SiteShellConfig {\n readonly base: string;\n readonly build: { readonly target: SiteTarget };\n readonly define: Readonly<Record<string, string>>;\n}\n\n/** A tag for the `head` of each HTML page. */\nexport interface SiteShellTag {\n readonly tag: \"script\";\n readonly children: string;\n readonly injectTo: \"head\";\n}\n\n/** The Vite plugin that `siteShell` gives. */\nexport interface SiteShellPlugin {\n readonly name: string;\n config(config: SiteShellConfigInput): SiteShellConfig;\n transformIndexHtml(): SiteShellTag[];\n}\n\n/** The input of `siteKpi`. Without a commit, the plugin takes `GITHUB_SHA`, else the head of the repository. */\nexport type SiteKpiInput = Omit<KpiInput, \"commit\"> & { readonly commit?: string | undefined };\n\n/** The part of the context of a Rollup hook that `siteKpi` uses. */\nexport interface SiteKpiContext {\n emitFile(file: { type: \"asset\"; fileName: string; source: string }): string;\n}\n\n/** The Vite plugin that `siteKpi` gives. */\nexport interface SiteKpiPlugin {\n readonly name: string;\n readonly apply: \"build\";\n generateBundle(this: SiteKpiContext): void;\n}\n\n/**\n * This function gives the Vite plugin that adds `kpi.json` to the root of a built site. A fault in the data stops the build.\n *\n * @param input - The data, or a function that reads it at the time of the build.\n * @param env - The environment variables. A test gives its own.\n */\nexport function siteKpi(input: SiteKpiInput | (() => SiteKpiInput), env: SiteEnv = process.env): SiteKpiPlugin {\n return {\n name: \"site-pages-kpi\",\n apply: \"build\",\n generateBundle() {\n const data = typeof input === \"function\" ? input() : input;\n const commit = data.commit ?? env[\"GITHUB_SHA\"] ?? headCommit(process.cwd()) ?? \"\";\n this.emitFile({ type: \"asset\", fileName: KPI_FILE, source: kpiText(kpiFile({ ...data, commit })) });\n },\n };\n}\n\n/** The file that `siteStamps` adds to the root of a built site. The input `data-stamps` of `reusable-pages.yml` names it. */\nexport const STAMPS_FILE = \"data-stamps.json\";\n\n/** The mark in the HTML of a measured page. `siteStamps` replaces it with the stamp line of the page. */\nexport const STAMP_MARK = \"<!-- data-stamp -->\";\n\n/** The part of the context of a page that `siteStamps` uses. */\nexport interface SiteStampsPage {\n /** The path of the page from the root of the site, with a `/` at the start. */\n readonly path: string;\n}\n\n/** The Vite plugin that `siteStamps` gives. */\nexport interface SiteStampsPlugin {\n readonly name: string;\n readonly apply: \"build\";\n readonly transformIndexHtml: { readonly order: \"pre\"; handler(html: string, page: SiteStampsPage): string };\n generateBundle(this: SiteKpiContext): void;\n}\n\n/**\n * This function gives the Vite plugin of the data stamps of a site. The plugin puts the stamp line in each measured page.\n * It also adds `data-stamps.json` to the root of the site. So the page and the freshness gate read one record.\n *\n * A fault stops the build. A fault is a bad stamp, a mark with no stamp or a stamp with no mark. A stamp of a page that the build does not hold is also a fault.\n *\n * @param input - The stamps, or a function that reads them at the time of the build.\n */\nexport function siteStamps(input: DataStamps | (() => DataStamps)): SiteStampsPlugin {\n let stamps: DataStamps | undefined;\n const read = (): DataStamps => {\n if (stamps !== undefined) return stamps;\n const parsed = parseDataStamps(typeof input === \"function\" ? input() : input);\n if (!parsed.ok) throw new Error(`The data stamps are not good:\\n- ${parsed.faults.join(\"\\n- \")}`);\n stamps = parsed.stamps;\n return stamps;\n };\n const seen = new Set<string>();\n return {\n name: \"site-pages-stamps\",\n apply: \"build\",\n transformIndexHtml: {\n order: \"pre\",\n handler(html, { path }) {\n const name = path.replace(/^\\//, \"\");\n const stamp = read().pages.find((page) => page.page === name);\n const marked = html.includes(STAMP_MARK);\n if (stamp === undefined && marked) throw new Error(`The page ${name} has the mark of a data stamp, and the stamps have no page ${name}.`);\n if (stamp === undefined) return html;\n if (!marked) throw new Error(`The stamps have the page ${name}, and the page has no mark ${STAMP_MARK}.`);\n seen.add(name);\n return html.replace(STAMP_MARK, renderDataStamp(stamp));\n },\n },\n generateBundle() {\n const missing = read()\n .pages.map((page) => page.page)\n .filter((page) => !seen.has(page));\n if (missing.length > 0) throw new Error(`The stamps have pages that the build does not hold: ${missing.join(\", \")}.`);\n this.emitFile({ type: \"asset\", fileName: STAMPS_FILE, source: `${JSON.stringify(read(), null, 2)}\\n` });\n },\n };\n}\n\n/**\n * This function gives the script that sets the saved theme before the first paint, so a dark page\n * does not show white for a moment. The script reads `storageKey`, as `applyTheme` writes it.\n *\n * @remarks The text goes in an inline `script` element. Thus the function escapes each `<` of the\n * key, so a key cannot close the element.\n */\nexport function themeScript(storageKey: string): string {\n const key = JSON.stringify(storageKey).replaceAll(\"<\", \"\\\\u003c\");\n return `try{const t=localStorage.getItem(${key});if(t===\"light\"||t===\"dark\")document.documentElement.dataset.theme=t}catch{}`;\n}\n\n/**\n * This function gives the `base` of Vite from `SITE_BASE`, with one `/` at the end. The Pages\n * workflow sets that variable to `/<name>`. A local build has no such variable, and gets `/`.\n */\nexport function siteBase(env: SiteEnv = process.env): string {\n const base = env[\"SITE_BASE\"];\n return base ? `${base.replace(/\\/$/, \"\")}/` : \"/\";\n}\n\n/**\n * This function gives the ISO time in UTC of the commit of a build. A count that a build reads from the source is\n * true at that commit, so this time is the time of its data. It is not the time of the build.\n *\n * @param env - The environment variables. The function takes `GITHUB_SHA`, else `HEAD`.\n * @param repoDir - The folder of the repository.\n * @throws When git cannot read the commit. A file with no time of its data is a fault.\n */\nexport function commitTime(env: SiteEnv = process.env, repoDir: string = process.cwd()): string {\n const ref = env[\"GITHUB_SHA\"] ?? \"HEAD\";\n const time = git(repoDir, \"show\", \"-s\", \"--format=%cI\", ref)?.trim();\n if (!time) throw new Error(`git cannot read the commit ${ref}, so the data has no time.`);\n return new Date(time).toISOString();\n}\n\n/** This function gives the data of a build. Outside CI, `GITHUB_SHA` is not set, and `sha` is `local`. */\nexport function buildInfo(version?: string, env: SiteEnv = process.env, now: Date = new Date()): BuildInfo {\n return { sha: (env[\"GITHUB_SHA\"] ?? \"local\").slice(0, 7), date: now.toISOString().slice(0, 10), version };\n}\n\n/** This function reads the field `version` of a `package.json` file. */\nfunction versionIn(file: string): string | undefined {\n return (JSON.parse(readFileSync(file, \"utf8\")) as { version?: string }).version;\n}\n\n/**\n * This function makes the Vite plugin of a site. The plugin does these four operations:\n *\n * - It sets `base` from `SITE_BASE`.\n * - It sets `build.target` to `es2022`.\n * - It defines `__BUILD__`, the value that `showBuild` shows.\n * - It adds `themeScript` to the `head` of each HTML page.\n *\n * A `base` or a `build.target` in the config of the site has priority. The other values of `build`\n * and `define` in that config stay, because Vite merges them.\n */\nexport function siteShell(options: SiteShellOptions): SiteShellPlugin {\n return {\n name: \"site-pages-shell\",\n config(config) {\n const packageFile = options.packageFile ?? \"../package.json\";\n const version = packageFile === false ? undefined : versionIn(resolve(config.root ?? \".\", packageFile));\n return {\n base: config.base ?? siteBase(),\n build: { target: config.build?.target ?? \"es2022\" },\n define: { __BUILD__: JSON.stringify(buildInfo(version)) },\n };\n },\n transformIndexHtml() {\n return [{ tag: \"script\", children: themeScript(options.themeKey), injectTo: \"head\" }];\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoFA,SAAgB,QAAQ,OAA4C,MAAe,QAAQ,KAAoB;CAC7G,OAAO;EACL,MAAM;EACN,OAAO;EACP,iBAAiB;GACf,MAAM,OAAO,OAAO,UAAU,aAAa,MAAM,IAAI;GACrD,MAAM,SAAS,KAAK,UAAU,IAAI,iBAAiB,WAAW,QAAQ,IAAI,CAAC,KAAK;GAChF,KAAK,SAAS;IAAE,MAAM;IAAS,UAAU;IAAU,QAAQ,QAAQ,QAAQ;KAAE,GAAG;KAAM;IAAO,CAAC,CAAC;GAAE,CAAC;EACpG;CACF;AACF;;AAGA,MAAa,cAAc;;AAG3B,MAAa,aAAa;;;;;;;;;AAwB1B,SAAgB,WAAW,OAA0D;CACnF,IAAI;CACJ,MAAM,aAAyB;EAC7B,IAAI,WAAW,KAAA,GAA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
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["/**\n * The build side of the shell of a site: a Vite plugin and its parts. Import this module from\n * `@mark1russell7/site-pages/vite`. It is for `vite.config.ts`, not for a browser.\n *\n * This module does not import Vite. The types of the plugin are the small part that it uses, so the\n * package keeps no dependency. A test examines that Vite accepts the plugin.\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { BuildInfo } from \"./chrome.ts\";\nimport { parseDataStamps, type DataStamps } from \"./check/freshness.ts\";\nimport { git, headCommit } from \"./data/git.ts\";\nimport { KPI_FILE, kpiFile, kpiText, type KpiInput } from \"./data/kpi.ts\";\nimport { renderDataStamp } from \"./render/data-stamp.ts\";\n\nexport type { BuildInfo } from \"./chrome.ts\";\n\n/** The environment variables that this module reads. */\nexport type SiteEnv = Readonly<Record<string, string | undefined>>;\n\n/** The options of `siteShell`. */\nexport interface SiteShellOptions {\n /** The `localStorage` key of the theme. Give the same key to `setupTheme` in the page. */\n readonly themeKey: string;\n /**\n * The file with the version for `__BUILD__`, relative to the folder of the site. The default is\n * `../package.json`. The value `false` gives a build with no version.\n */\n readonly packageFile?: string | false | undefined;\n}\n\n/** The value of `build.target` in a Vite config. */\nexport type SiteTarget = string | string[] | false;\n\n/** The part of the Vite config that `siteShell` reads. */\nexport interface SiteShellConfigInput {\n readonly root?: string | undefined;\n readonly base?: string | undefined;\n readonly build?: { readonly target?: SiteTarget | undefined } | null | undefined;\n}\n\n/** The part of the Vite config that `siteShell` sets. Vite merges it into the config of the site. */\nexport interface SiteShellConfig {\n readonly base: string;\n readonly build: { readonly target: SiteTarget };\n readonly define: Readonly<Record<string, string>>;\n}\n\n/** A tag for the `head` of each HTML page. */\nexport interface SiteShellTag {\n readonly tag: \"script\";\n readonly children: string;\n readonly injectTo: \"head\";\n}\n\n/** The Vite plugin that `siteShell` gives. */\nexport interface SiteShellPlugin {\n readonly name: string;\n config(config: SiteShellConfigInput): SiteShellConfig;\n transformIndexHtml(): SiteShellTag[];\n}\n\n/** The input of `siteKpi`. Without a commit, the plugin takes `GITHUB_SHA`, else the head of the repository. */\nexport type SiteKpiInput = Omit<KpiInput, \"commit\"> & { readonly commit?: string | undefined };\n\n/** The part of the context of a Rollup hook that `siteKpi` uses. */\nexport interface SiteKpiContext {\n emitFile(file: { type: \"asset\"; fileName: string; source: string }): string;\n}\n\n/** The Vite plugin that `siteKpi` gives. */\nexport interface SiteKpiPlugin {\n readonly name: string;\n readonly apply: \"build\";\n generateBundle(this: SiteKpiContext): void;\n}\n\n/**\n * This function gives the Vite plugin that adds `kpi.json` to the root of a built site. A fault in the data stops the build.\n *\n * @param input - The data, or a function that reads it at the time of the build.\n * @param env - The environment variables. A test gives its own.\n */\nexport function siteKpi(input: SiteKpiInput | (() => SiteKpiInput), env: SiteEnv = process.env): SiteKpiPlugin {\n return {\n name: \"site-pages-kpi\",\n apply: \"build\",\n generateBundle() {\n const data = typeof input === \"function\" ? input() : input;\n const commit = data.commit ?? env[\"GITHUB_SHA\"] ?? headCommit(process.cwd()) ?? \"\";\n this.emitFile({ type: \"asset\", fileName: KPI_FILE, source: kpiText(kpiFile({ ...data, commit })) });\n },\n };\n}\n\n/** The file that `siteStamps` adds to the root of a built site. The input `data-stamps` of `reusable-pages.yml` names it. */\nexport const STAMPS_FILE = \"data-stamps.json\";\n\n/** The mark in the HTML of a measured page. `siteStamps` replaces it with the stamp line of the page. */\nexport const STAMP_MARK = \"<!-- data-stamp -->\";\n\n/** The part of the context of a page that `siteStamps` uses. */\nexport interface SiteStampsPage {\n /** The path of the page from the root of the site, with a `/` at the start. */\n readonly path: string;\n}\n\n/** The Vite plugin that `siteStamps` gives. */\nexport interface SiteStampsPlugin {\n readonly name: string;\n readonly apply: \"build\";\n readonly transformIndexHtml: { readonly order: \"pre\"; handler(html: string, page: SiteStampsPage): string };\n generateBundle(this: SiteKpiContext): void;\n}\n\n/**\n * This function gives the Vite plugin of the data stamps of a site. The plugin puts the stamp line in each measured page.\n * It also adds `data-stamps.json` to the root of the site. So the page and the freshness gate read one record.\n *\n * A fault stops the build. A fault is a bad stamp, a mark with no stamp or a stamp with no mark. A stamp of a page that the build does not hold is also a fault.\n *\n * @param input - The stamps, or a function that reads them at the time of the build.\n */\nexport function siteStamps(input: DataStamps | (() => DataStamps)): SiteStampsPlugin {\n let stamps: DataStamps | undefined;\n const read = (): DataStamps => {\n if (stamps !== undefined) return stamps;\n const parsed = parseDataStamps(typeof input === \"function\" ? input() : input);\n if (!parsed.ok) throw new Error(`The data stamps are not good:\\n- ${parsed.faults.join(\"\\n- \")}`);\n stamps = parsed.stamps;\n return stamps;\n };\n const seen = new Set<string>();\n return {\n name: \"site-pages-stamps\",\n apply: \"build\",\n transformIndexHtml: {\n order: \"pre\",\n handler(html, { path }) {\n const name = path.replace(/^\\//, \"\");\n const stamp = read().pages.find((page) => page.page === name);\n const marked = html.includes(STAMP_MARK);\n if (stamp === undefined && marked) throw new Error(`The page ${name} has the mark of a data stamp, and the stamps have no page ${name}.`);\n if (stamp === undefined) return html;\n if (!marked) throw new Error(`The stamps have the page ${name}, and the page has no mark ${STAMP_MARK}.`);\n seen.add(name);\n return html.replace(STAMP_MARK, renderDataStamp(stamp));\n },\n },\n generateBundle() {\n const missing = read()\n .pages.map((page) => page.page)\n .filter((page) => !seen.has(page));\n if (missing.length > 0) throw new Error(`The stamps have pages that the build does not hold: ${missing.join(\", \")}.`);\n this.emitFile({ type: \"asset\", fileName: STAMPS_FILE, source: `${JSON.stringify(read(), null, 2)}\\n` });\n },\n };\n}\n\n/**\n * This function gives the script that sets the saved theme before the first paint, so a dark page\n * does not show white for a moment. The script reads `storageKey`, as `applyTheme` writes it.\n *\n * @remarks The text goes in an inline `script` element. Thus the function escapes each `<` of the\n * key, so a key cannot close the element.\n */\nexport function themeScript(storageKey: string): string {\n const key = JSON.stringify(storageKey).replaceAll(\"<\", \"\\\\u003c\");\n return `try{const t=localStorage.getItem(${key});if(t===\"light\"||t===\"dark\")document.documentElement.dataset.theme=t}catch{}`;\n}\n\n/**\n * This function gives the `base` of Vite from `SITE_BASE`, with one `/` at the end. The Pages\n * workflow sets that variable to `/<name>`. A local build has no such variable, and gets `/`.\n */\nexport function siteBase(env: SiteEnv = process.env): string {\n const base = env[\"SITE_BASE\"];\n return base ? `${base.replace(/\\/$/, \"\")}/` : \"/\";\n}\n\n/**\n * This function gives the ISO time in UTC of the commit of a build. A count that a build reads from the source is\n * true at that commit, so this time is the time of its data. It is not the time of the build.\n *\n * @param env - The environment variables. The function takes `GITHUB_SHA`, else `HEAD`.\n * @param repoDir - The folder of the repository.\n * @throws When git cannot read the commit. A file with no time of its data is a fault.\n */\nexport function commitTime(env: SiteEnv = process.env, repoDir: string = process.cwd()): string {\n const ref = env[\"GITHUB_SHA\"] ?? \"HEAD\";\n const time = git(repoDir, \"show\", \"-s\", \"--format=%cI\", ref)?.trim();\n if (!time) throw new Error(`git cannot read the commit ${ref}, so the data has no time.`);\n return new Date(time).toISOString();\n}\n\n/** A node of an HTML tree, with only the fields that `rehypeScrollCue` reads. */\nexport interface RehypeNode {\n readonly type: string;\n readonly tagName?: string;\n properties?: Record<string, unknown>;\n readonly children?: readonly RehypeNode[];\n}\n\n/**\n * This function gives the transformer of a rehype plugin. The transformer gives the class `scroll-cue` to each table of a Markdown page.\n * The table also gets a place in the tab order and a label, so a keyboard can scroll it. A site that uses this plugin imports `scroll-cue.css`.\n * Markdown has no way to set the class of a table, so a page of a docs theme needs this plugin.\n */\nexport function rehypeScrollCue(): (tree: RehypeNode) => void {\n const visit = (node: RehypeNode): void => {\n if (node.type === \"element\" && node.tagName === \"table\") {\n const properties = node.properties ?? {};\n const names = properties[\"className\"];\n const list = Array.isArray(names) ? names : typeof names === \"string\" ? [names] : [];\n node.properties = { ...properties, className: [...list, \"scroll-cue\"], tabIndex: 0, ariaLabel: \"Table. It scrolls sideways on a narrow screen.\" };\n }\n for (const child of node.children ?? []) visit(child);\n };\n return visit;\n}\n\n/** This function gives the data of a build. Outside CI, `GITHUB_SHA` is not set, and `sha` is `local`. */\nexport function buildInfo(version?: string, env: SiteEnv = process.env, now: Date = new Date()): BuildInfo {\n return { sha: (env[\"GITHUB_SHA\"] ?? \"local\").slice(0, 7), date: now.toISOString().slice(0, 10), version };\n}\n\n/** This function reads the field `version` of a `package.json` file. */\nfunction versionIn(file: string): string | undefined {\n return (JSON.parse(readFileSync(file, \"utf8\")) as { version?: string }).version;\n}\n\n/**\n * This function makes the Vite plugin of a site. The plugin does these four operations:\n *\n * - It sets `base` from `SITE_BASE`.\n * - It sets `build.target` to `es2022`.\n * - It defines `__BUILD__`, the value that `showBuild` shows.\n * - It adds `themeScript` to the `head` of each HTML page.\n *\n * A `base` or a `build.target` in the config of the site has priority. The other values of `build`\n * and `define` in that config stay, because Vite merges them.\n */\nexport function siteShell(options: SiteShellOptions): SiteShellPlugin {\n return {\n name: \"site-pages-shell\",\n config(config) {\n const packageFile = options.packageFile ?? \"../package.json\";\n const version = packageFile === false ? undefined : versionIn(resolve(config.root ?? \".\", packageFile));\n return {\n base: config.base ?? siteBase(),\n build: { target: config.build?.target ?? \"es2022\" },\n define: { __BUILD__: JSON.stringify(buildInfo(version)) },\n };\n },\n transformIndexHtml() {\n return [{ tag: \"script\", children: themeScript(options.themeKey), injectTo: \"head\" }];\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoFA,SAAgB,QAAQ,OAA4C,MAAe,QAAQ,KAAoB;CAC7G,OAAO;EACL,MAAM;EACN,OAAO;EACP,iBAAiB;GACf,MAAM,OAAO,OAAO,UAAU,aAAa,MAAM,IAAI;GACrD,MAAM,SAAS,KAAK,UAAU,IAAI,iBAAiB,WAAW,QAAQ,IAAI,CAAC,KAAK;GAChF,KAAK,SAAS;IAAE,MAAM;IAAS,UAAU;IAAU,QAAQ,QAAQ,QAAQ;KAAE,GAAG;KAAM;IAAO,CAAC,CAAC;GAAE,CAAC;EACpG;CACF;AACF;;AAGA,MAAa,cAAc;;AAG3B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OAAQ,KAAK,MAAM,aAAa,MAAM,MAAM,CAAC,CAAC,CAA0B;AAC1E;;;;;;;;;;;;AAaA,SAAgB,UAAU,SAA4C;CACpE,OAAO;EACL,MAAM;EACN,OAAO,QAAQ;GACb,MAAM,cAAc,QAAQ,eAAe;GAC3C,MAAM,UAAU,gBAAgB,QAAQ,KAAA,IAAY,UAAU,QAAQ,OAAO,QAAQ,KAAK,WAAW,CAAC;GACtG,OAAO;IACL,MAAM,OAAO,QAAQ,SAAS;IAC9B,OAAO,EAAE,QAAQ,OAAO,OAAO,UAAU,SAAS;IAClD,QAAQ,EAAE,WAAW,KAAK,UAAU,UAAU,OAAO,CAAC,EAAE;GAC1D;EACF;EACA,qBAAqB;GACnB,OAAO,CAAC;IAAE,KAAK;IAAU,UAAU,YAAY,QAAQ,QAAQ;IAAG,UAAU;GAAO,CAAC;EACtF;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/site-pages",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.18",
|
|
5
5
|
"description": "A release timeline page and a live status page for the site of a GitHub repository: JSON data and standalone HTML, made at deploy time.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"github-pages",
|