astro-accelerator 7.1.14 → 7.1.15

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.
@@ -0,0 +1,118 @@
1
+ :root,
2
+ body.mode-light {
3
+ --fore: #233;
4
+ --aft: #DFF;
5
+ --aft-image: #DFF;
6
+
7
+ --fore-link: #355;
8
+ --fore-link-alt: #699;
9
+ --aft-link-alt: #e6e6eC;
10
+
11
+ --fore-input: var(--fore);
12
+ --aft-input: var(--aft);
13
+
14
+ --fore-block: #333;
15
+ --aft-block: #BEE;
16
+ --icon-block: #FF0;
17
+ --icon-block-alpha: rgba(from var(--icon-block) r g b / 0.4);
18
+
19
+ --fore-table-head: #DFF;
20
+ --aft-table-head: #233;
21
+ --fore-table-row-odd: #333;
22
+ --aft-table-row-odd: #DFF;
23
+ --fore-table-row-even: #333;
24
+ --aft-table-row-even: #CFF;
25
+ }
26
+
27
+ body.mode-dark {
28
+ --fore: #DFF;
29
+ --aft: #233;
30
+ --aft-image: #DDD;
31
+
32
+ --fore-link: #AFF;
33
+ --fore-link-alt: #FF0;
34
+ --aft-link-alt: #232323;
35
+
36
+ --fore-input: var(--fore);
37
+ --aft-input: var(--aft);
38
+
39
+ --fore-block: #DFF;
40
+ --aft-block: #011;
41
+ --icon-block: #FF0;
42
+ --icon-block-alpha: rgba(from var(--icon-block) r g b / 0.4);
43
+
44
+ --fore-table-head: #DFF;
45
+ --aft-table-head: #244;
46
+ --fore-table-row-odd: #DFF;
47
+ --aft-table-row-odd: #355;
48
+ --fore-table-row-even: #DFF;
49
+ --aft-table-row-even: #466;
50
+ }
51
+
52
+
53
+ @font-face {
54
+ font-family: "hyper-reg";
55
+ font-weight: normal;
56
+ font-style: normal;
57
+ src: url("AtkinsonHyperlegibleNext-Regular.otf");
58
+ font-display: block;
59
+ }
60
+
61
+ @font-face {
62
+ font-family: "hyper-bold";
63
+ font-weight: bold;
64
+ font-style: normal;
65
+ src: url("AtkinsonHyperlegibleNext-Bold.otf");
66
+ font-display: block;
67
+ }
68
+
69
+ @font-face {
70
+ font-family: "hyper-mono";
71
+ font-weight: bold;
72
+ font-style: normal;
73
+ src: url("AtkinsonHyperlegibleMono-Regular.otf");
74
+ font-display: block;
75
+ }
76
+
77
+ :root {
78
+ --heading-font: 'hyper-bold', sans-serif;
79
+ --content-font: 'hyper-reg', Verdana, Geneva, sans-serif;
80
+ --code-font: 'hyper-mono', Consolas, 'Courier New', Courier, monospace;
81
+ --unicode-font: font-family: "Segoe UI Symbol", "Arial Unicode MS", "DejaVu Sans", "Meiryo UI", "MS UI Gothic", "Everson Mono Unicode", Meiryo, "MS Gothic", "MS Mincho", "MS PGothic", "MS PMincho", "Meslo LG L", "Meslo LG L DZ", "Meslo M L", "Meslo M L DZ", "Meslo S L", "Meslo S L DZ", "Symbola", "DejaVu Sans Condensed", "DejaVu Sans Mono", Code2000, "Everson Mono", Quivira, sans-serif;
82
+
83
+ --font-size-meta: 0.9rem;
84
+ --font-size-h1: 3rem;
85
+ --font-size-h2: 2.3rem;
86
+ --font-size-h3: 2rem;
87
+ --font-size-h4: 1.7rem;
88
+ --font-size-h5: 1.7rem;
89
+ --font-size-h6: 1.7rem;
90
+
91
+ --paragraph-margin: 1.2rem;
92
+ --block-gap: 2rem;
93
+ --block-gap-l: 3rem;
94
+ --block-radius: 0.3rem;
95
+ --block-radius-round: 20px;
96
+
97
+ --marker-size: 1.2rem;
98
+
99
+ --box-shadow: 0 12px 24px -12px rgb(0 0 0 / 50%);
100
+ --box-shadow-slight: 0 6px 12px -6px rgb(0 0 0 / 40%);
101
+ --box-glow: 0 0 12px 0 var(--icon-block-alpha);
102
+
103
+ --box-shadow-unselected: rgb(0 0 0 / 6%) 0px 2px 4px, rgb(0 0 0 / 5%) 0px 0.5px 1px;
104
+ --transform-selected: translate3d(0px, -1px, 0px);
105
+
106
+ --content-width: 50rem;
107
+ --navigation-width: 300px;
108
+ --grid-gap: 1rem;
109
+ --grid-gap-s: 0.4rem;
110
+
111
+ /* Calculate the mobile width by removing l/r columns */
112
+ --content-width-mobile: calc(100vw - 1rem);
113
+
114
+ /* Search variables */
115
+ --search-height: 2rem;
116
+ --search-dropdown-height: 65vh;
117
+ --search-dropdown-duration: 0.2s;
118
+ }
package/src/config.ts CHANGED
@@ -7,7 +7,7 @@ const SITE: Site = {
7
7
  url: 'https://astro.stevefenton.co.uk',
8
8
  useTrailingUrlSlash: true,
9
9
  captureStatistics: true,
10
- feedUrl: '/articles/feed.xml',
10
+ feedUrl: '/rss.xml',
11
11
  title: 'Astro Accelerator',
12
12
  description: 'An Astro quick start project.',
13
13
  startYear: '2022',
@@ -10,6 +10,15 @@ import {
10
10
  PostOrdering,
11
11
  } from 'astro-accelerator-utils';
12
12
 
13
+ function escapeXml(text: string): string {
14
+ return text
15
+ .replace(/&/g, '&')
16
+ .replace(/</g, '&lt;')
17
+ .replace(/>/g, '&gt;')
18
+ .replace(/"/g, '&quot;')
19
+ .replace(/'/g, '&apos;');
20
+ }
21
+
13
22
  async function getData() {
14
23
  //@ts-ignore
15
24
  const allArticles = import.meta.glob(['./**/*.md', './**/*.mdx']);
@@ -41,12 +50,12 @@ async function getData() {
41
50
  const items = articles.slice(0, limit).map(
42
51
  (a) => `
43
52
  <entry>
44
- <title>${a.frontmatter.title ?? ''}</title>
53
+ <title>${escapeXml(a.frontmatter.title ?? '')}</title>
45
54
  <link href="${SITE.url + a.url}" />
46
55
  <id>${SITE.url + accelerator.urlFormatter.formatAddress(a.url)}</id>
47
56
  <published>${a.frontmatter.pubDate}</published>
48
57
  <updated>${a.frontmatter.modDate ?? a.frontmatter.pubDate}</updated>
49
- <summary>${a.frontmatter.description ?? ''}</summary>
58
+ <summary>${escapeXml(a.frontmatter.description ?? '')}</summary>
50
59
  </entry>`
51
60
  );
52
61
 
@@ -55,8 +64,8 @@ async function getData() {
55
64
  return new Response(
56
65
  `<?xml version="1.0" encoding="utf-8"?>
57
66
  <feed xmlns="http://www.w3.org/2005/Atom">
58
- <title>${SITE.title}</title>
59
- <subtitle>${SITE.description}</subtitle>
67
+ <title>${escapeXml(SITE.title)}</title>
68
+ <subtitle>${escapeXml(SITE.description)}</subtitle>
60
69
  <link href="${SITE.url}${SITE.feedUrl}" rel="self" />
61
70
  <link href="${SITE.url}" />
62
71
  <id>${SITE.url}${SITE.feedUrl}</id>
@@ -13,6 +13,15 @@ import type { MarkdownInstance } from 'astro-accelerator-utils/types/Astro';
13
13
 
14
14
  type Frontmatter = MarkdownInstance['frontmatter'];
15
15
 
16
+ function escapeXml(text: string): string {
17
+ return text
18
+ .replace(/&/g, '&amp;')
19
+ .replace(/</g, '&lt;')
20
+ .replace(/>/g, '&gt;')
21
+ .replace(/"/g, '&quot;')
22
+ .replace(/'/g, '&apos;');
23
+ }
24
+
16
25
  async function getData() {
17
26
  //@ts-ignore
18
27
  const allArticles = import.meta.glob(['./**/*.md', './**/*.mdx']);
@@ -75,14 +84,14 @@ async function getData() {
75
84
  .map(
76
85
  (a) => `
77
86
  <entry>
78
- <title>${a.frontmatter.title ?? ''}</title>
87
+ <title>${escapeXml(a.frontmatter.title ?? '')}</title>
79
88
  <link href="${SITE.url + a.url}" />
80
89
  <id>${SITE.url + accelerator.urlFormatter.formatAddress(a.url)}</id>
81
90
  <published>${a.frontmatter.pubDate}</published>
82
91
  <updated>${a.frontmatter.modDate ?? a.frontmatter.pubDate}</updated>
83
- <summary>${a.frontmatter.description ?? ''}</summary>
92
+ <summary>${escapeXml(a.frontmatter.description ?? '')}</summary>
84
93
  <author>
85
- <name>${getAuthorName(a.frontmatter)}</name>
94
+ <name>${escapeXml(getAuthorName(a.frontmatter))}</name>
86
95
  </author>
87
96
  <content type="html"><![CDATA[${contentItems[a.url] ?? ''}]]></content>
88
97
  </entry>`
@@ -93,8 +102,8 @@ async function getData() {
93
102
  return new Response(
94
103
  `<?xml version="1.0" encoding="utf-8"?>
95
104
  <feed xmlns="http://www.w3.org/2005/Atom">
96
- <title>${SITE.title}</title>
97
- <subtitle>${SITE.description}</subtitle>
105
+ <title>${escapeXml(SITE.title)}</title>
106
+ <subtitle>${escapeXml(SITE.description)}</subtitle>
98
107
  <link href="${SITE.url}${SITE.feedUrl}" rel="self" />
99
108
  <link href="${SITE.url}" />
100
109
  <id>${SITE.url}${SITE.feedUrl}</id>
@@ -1,6 +1,9 @@
1
1
  ---
2
2
  // warning: This file is overwritten by Astro Accelerator
3
3
 
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+
4
7
  import { Accelerator } from "astro-accelerator-utils";
5
8
  import type { Frontmatter } from "astro-accelerator-utils/types/Frontmatter";
6
9
  import { SITE, OPEN_GRAPH, HEADER_SCRIPTS } from "@config";
@@ -43,6 +46,22 @@ const autoMeta = (name: string) => {
43
46
  return pageMeta.filter((m) => m.name.toLowerCase() === name).length === 0;
44
47
  };
45
48
 
49
+ const pkg = JSON.parse(
50
+ fs.readFileSync(path.join(process.cwd(), "package.json"), "utf8"),
51
+ );
52
+ const cssDir = path.join(process.cwd(), "public", SITE.subfolder, "css");
53
+
54
+ const cssHref = (baseName: string) => {
55
+ const baseWithoutExt = baseName.slice(0, -".css".length);
56
+ const versionedName = `${baseWithoutExt}.${pkg.version}.css`;
57
+ const versionedPath = path.join(cssDir, versionedName);
58
+ const fileName = fs.existsSync(versionedPath) ? versionedName : baseName;
59
+ return SITE.subfolder + `/css/${fileName}`;
60
+ };
61
+
62
+ const varsCss = cssHref("vars.css");
63
+ const mainCss = cssHref("main.css");
64
+
46
65
  stats.stop();
47
66
  ---
48
67
 
@@ -52,16 +71,8 @@ stats.stop();
52
71
  <meta name="robots" content={"max-image-preview:large, " + robots} />
53
72
  <meta name="keywords" content={frontmatter.keywords} />
54
73
  <meta name="description" content={frontmatter.description} />
55
- <link
56
- rel="stylesheet"
57
- href={SITE.subfolder + `/css/vars.7.1.14.css`}
58
- data-versioned
59
- />
60
- <link
61
- rel="stylesheet"
62
- href={SITE.subfolder + `/css/main.7.1.14.css`}
63
- data-versioned
64
- />
74
+ <link rel="stylesheet" href={varsCss} />
75
+ <link rel="stylesheet" href={mainCss} />
65
76
  {
66
77
  autoMeta("viewport") && (
67
78
  <meta
@@ -2,7 +2,7 @@
2
2
  * This javascript file comes from Astro Accelerator
3
3
  * Edits will be overwritten if you change the file locally
4
4
  *
5
- * Copies versioned CSS files and rewrites data-versioned links in HtmlHead.
5
+ * Copies versioned CSS files from unversioned sources.
6
6
  *
7
7
  * @format
8
8
  */
@@ -11,19 +11,7 @@ import fs from 'fs';
11
11
  import path from 'path';
12
12
 
13
13
  const workingDirectory = process.cwd();
14
- const defaultHtmlHead = path.join(
15
- 'src',
16
- 'themes',
17
- 'accelerator',
18
- 'components',
19
- 'HtmlHead.astro'
20
- );
21
-
22
- const htmlHeadArg = process.argv[2];
23
- const htmlHeadPath = path.resolve(
24
- workingDirectory,
25
- htmlHeadArg ?? defaultHtmlHead
26
- );
14
+ const baseCssFiles = ['vars.css', 'main.css'];
27
15
 
28
16
  const packageJsonPath = path.join(workingDirectory, 'package.json');
29
17
  const pkg = JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf8'));
@@ -42,39 +30,6 @@ const subfolder = configSource.match(/subfolder:\s*'([^']*)'/)?.[1] ?? '';
42
30
 
43
31
  const cssDir = path.join(workingDirectory, 'public', subfolder, 'css');
44
32
  const previousVersionLimit = 5;
45
- const linkRegex = /<link\b[^>]*?\bdata-versioned\b[^>]*?\/>/g;
46
- const hrefCssRegex = /(['"`])(\/css\/[^'"`]+)\1/;
47
-
48
- /**
49
- * Derive the unversioned base filename from a CSS path in an href.
50
- * e.g. /css/vars.7.1.11.css → vars.css
51
- * /css/main.css → main.css
52
- */
53
- function getBaseCssName(cssPath) {
54
- const withoutQuery = cssPath.split('?')[0];
55
- const fileName = path.basename(withoutQuery);
56
-
57
- if (!fileName.endsWith('.css')) {
58
- return null;
59
- }
60
-
61
- const withoutExt = fileName.slice(0, -'.css'.length);
62
- const versionSuffix = `.${version}`;
63
-
64
- if (withoutExt.endsWith(versionSuffix)) {
65
- return withoutExt.slice(0, -versionSuffix.length) + '.css';
66
- }
67
-
68
- // Strip a semver-like suffix if present (e.g. main.7.1.10.css)
69
- const semverMatch = withoutExt.match(
70
- /^(.+)\.(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/
71
- );
72
- if (semverMatch) {
73
- return semverMatch[1] + '.css';
74
- }
75
-
76
- return fileName;
77
- }
78
33
 
79
34
  async function cleanStaleVersions(baseName) {
80
35
  const baseWithoutExt = baseName.slice(0, -'.css'.length);
@@ -116,59 +71,8 @@ async function copyVersionedCss(baseName) {
116
71
  await fs.promises.copyFile(sourcePath, destPath);
117
72
  console.log(`Copied ${baseName} → ${versionedName}`);
118
73
  await cleanStaleVersions(baseName);
119
-
120
- return versionedName;
121
74
  }
122
75
 
123
- function rewriteLinkHref(linkTag, versionedName) {
124
- return linkTag.replace(
125
- hrefCssRegex,
126
- (_match, quote) => `${quote}/css/${versionedName}${quote}`
127
- );
76
+ for (const baseName of baseCssFiles) {
77
+ await copyVersionedCss(baseName);
128
78
  }
129
-
130
- let content = await fs.promises.readFile(htmlHeadPath, 'utf8');
131
- const links = [...content.matchAll(linkRegex)];
132
-
133
- if (links.length === 0) {
134
- console.error(
135
- `No data-versioned <link> tags found in ${htmlHeadPath}`
136
- );
137
- process.exit(1);
138
- }
139
-
140
- const processedBases = new Set();
141
-
142
- for (const match of links) {
143
- const linkTag = match[0];
144
- const hrefMatch = linkTag.match(hrefCssRegex);
145
-
146
- if (!hrefMatch) {
147
- console.error(
148
- 'data-versioned link is missing a `/css/...` href template:',
149
- linkTag
150
- );
151
- process.exit(1);
152
- }
153
-
154
- const baseName = getBaseCssName(hrefMatch[2]);
155
- if (!baseName) {
156
- console.error(`Could not derive base CSS name from ${hrefMatch[2]}`);
157
- process.exit(1);
158
- }
159
-
160
- let versionedName;
161
- if (processedBases.has(baseName)) {
162
- const baseWithoutExt = baseName.slice(0, -'.css'.length);
163
- versionedName = `${baseWithoutExt}.${version}.css`;
164
- } else {
165
- versionedName = await copyVersionedCss(baseName);
166
- processedBases.add(baseName);
167
- }
168
-
169
- const updatedLink = rewriteLinkHref(linkTag, versionedName);
170
- content = content.replace(linkTag, updatedLink);
171
- }
172
-
173
- await fs.promises.writeFile(htmlHeadPath, content, 'utf8');
174
- console.log(`Updated ${htmlHeadPath}`);