astro-accelerator 5.9.17 → 5.9.19

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.9.17",
2
+ "version": "5.9.19",
3
3
  "author": "Steve Fenton",
4
4
  "name": "astro-accelerator",
5
5
  "description": "A super-lightweight, accessible, SEO-friendly starter project for Astro",
@@ -33,9 +33,10 @@
33
33
  "dts": "tsc ./tests/locate-content.js ./tests/locate-navigation.js ./tests/locate-search.js --allowJs --declaration --emitDeclarationOnly"
34
34
  },
35
35
  "dependencies": {
36
- "@astrojs/mdx": "^4.3.3",
37
- "astro": "^5.12.8",
38
- "astro-accelerator-utils": "^0.3.49",
36
+ "@astrojs/mdx": "^4.3.4",
37
+ "@img/sharp-linux-x64": "^0.34.3",
38
+ "astro": "^5.13.3",
39
+ "astro-accelerator-utils": "^0.3.51",
39
40
  "cspell": "^8.19.4",
40
41
  "csv": "^6.4.1",
41
42
  "glob": "^11.0.3",
@@ -48,7 +49,7 @@
48
49
  "sharp": "^0.33.5"
49
50
  },
50
51
  "devDependencies": {
51
- "@playwright/test": "^1.54.2"
52
+ "@playwright/test": "^1.55.0"
52
53
  },
53
54
  "files": [
54
55
  ".npmrc",
@@ -6,28 +6,46 @@ import { Accelerator } from 'astro-accelerator-utils';
6
6
  import { SITE } from '@config';
7
7
 
8
8
  const accelerator = new Accelerator(SITE);
9
- const stats = new accelerator.statistics('accelerator/components/FooterItem.astro');
9
+ const stats = new accelerator.statistics(
10
+ 'accelerator/components/FooterItem.astro'
11
+ );
10
12
  stats.start();
11
13
 
12
14
  // Properties
13
15
  type Props = {
14
- lang: string;
15
- page: NavPage
16
+ lang: string;
17
+ page: NavPage;
16
18
  };
17
19
  const { lang, page } = Astro.props satisfies Props;
18
20
 
19
21
  // Logic
20
22
  stats.stop();
21
23
  ---
22
- {page.children.length > 0 && (
23
- <div class="footer-column">
24
- <h2><Fragment set:html={page.title} /></h2>
25
- <ul>
26
- { page.children.sort((a, b) => a.order - b.order).map((child) => (
27
- <li>
28
- <a href={ child.url } aria-current={ child.ariaCurrent ? child.ariaCurrent : null } rel={ child.rel }>{ child.title }</a>
29
- </li>
30
- ))}
31
- </ul>
32
- </div>
33
- )}
24
+
25
+ {
26
+ page.children.length > 0 && (
27
+ <div class="footer-column">
28
+ <h2>
29
+ <Fragment set:html={page.title} />
30
+ </h2>
31
+ <ul>
32
+ {page.children
33
+ .sort((a, b) => a.order - b.order)
34
+ .map((child) => (
35
+ <li>
36
+ <a
37
+ href={accelerator.urlFormatter.formatAddress(
38
+ child.url
39
+ )}
40
+ aria-current={
41
+ child.ariaCurrent ? child.ariaCurrent : null
42
+ }
43
+ rel={child.rel}>
44
+ {child.title}
45
+ </a>
46
+ </li>
47
+ ))}
48
+ </ul>
49
+ </div>
50
+ )
51
+ }
@@ -7,12 +7,14 @@ import { SITE } from '@config';
7
7
  import { menu } from '@data/navigation';
8
8
 
9
9
  const accelerator = new Accelerator(SITE);
10
- const stats = new accelerator.statistics('accelerator/components/NavigationBar.astro');
10
+ const stats = new accelerator.statistics(
11
+ 'accelerator/components/NavigationBar.astro'
12
+ );
11
13
  stats.start();
12
14
 
13
15
  // Properties
14
16
  type Props = {
15
- lang: string;
17
+ lang: string;
16
18
  };
17
19
  const { lang } = Astro.props satisfies Props;
18
20
 
@@ -25,11 +27,26 @@ const pages = accelerator.navigation.menu(currentUrl, SITE.subfolder, menu);
25
27
 
26
28
  stats.stop();
27
29
  ---
28
- <nav class="site-nav-bar" id="site-nav" aria-label={ _(Translations.aria.site_navigation) }>
29
- <h2 class="site-nav-title">{ _(Translations.navigation.title) }</h2>
30
- <ul>
31
- {pages.sort((a, b) => a.order - b.order).map((page) => (
32
- <li><a href={ page.url }>{ page.title }</a></li>
33
- ))}
34
- </ul>
35
- </nav>
30
+
31
+ <nav
32
+ class="site-nav-bar"
33
+ id="site-nav"
34
+ aria-label={_(Translations.aria.site_navigation)}>
35
+ <h2 class="site-nav-title">{_(Translations.navigation.title)}</h2>
36
+ <ul>
37
+ {
38
+ pages
39
+ .sort((a, b) => a.order - b.order)
40
+ .map((page) => (
41
+ <li>
42
+ <a
43
+ href={accelerator.urlFormatter.formatAddress(
44
+ page.url
45
+ )}>
46
+ {page.title}
47
+ </a>
48
+ </li>
49
+ ))
50
+ }
51
+ </ul>
52
+ </nav>
@@ -0,0 +1,135 @@
1
+ /**
2
+ * This javascript file comes from Astro Accelerator
3
+ * Edits will be overwritten if you change the file locally
4
+ *
5
+ * @format
6
+ */
7
+
8
+ import fs from 'fs';
9
+ import path from 'path';
10
+
11
+ const workingDirectory = process.cwd();
12
+
13
+ const imageSize = await import(
14
+ 'file://' + path.join(workingDirectory, 'src/data/image-size.mjs')
15
+ );
16
+ const imageModule = await import(
17
+ 'file://' + path.join(workingDirectory, 'src/data/images.mjs')
18
+ );
19
+ const size = imageSize.size;
20
+ const imagePaths = imageModule.imagePaths;
21
+
22
+ const imagePath = path.join('dist', imagePaths.src);
23
+ const outputPath = path.join('dist', imagePaths.dest);
24
+ const imageDirectory = path.join(workingDirectory, imagePath);
25
+
26
+ const filesToProcess = [];
27
+
28
+ function getDestinationFilePathless(source, s) {
29
+ let destination = path.join(
30
+ workingDirectory,
31
+ outputPath,
32
+ s.toString(),
33
+ source
34
+ );
35
+ destination = destination.replace(path.parse(destination).ext, '');
36
+ return destination;
37
+ }
38
+
39
+ async function recurseFiles(directory) {
40
+ const f = await fs.promises.readdir(path.join(imageDirectory, directory), {
41
+ withFileTypes: true,
42
+ });
43
+
44
+ for (const file of f) {
45
+ if (file.isDirectory()) {
46
+ const nextDirectory = path.join(directory, file.name);
47
+ await recurseFiles(nextDirectory);
48
+ } else {
49
+ const ext = path.parse(file.name).ext;
50
+
51
+ switch (ext) {
52
+ case '.jpg':
53
+ case '.jpeg':
54
+ case '.png':
55
+ case '.webp':
56
+ const sourcePath = path.join(directory, file.name);
57
+
58
+ const webP = sourcePath.replace(
59
+ /.jpg$|.jpeg$|.png$/,
60
+ '.webp'
61
+ );
62
+ const info = {
63
+ path: sourcePath,
64
+ webP: webP,
65
+ };
66
+
67
+ // Only processes images where there is no json metadata file
68
+ const metaPath = path.join(
69
+ workingDirectory,
70
+ imagePath,
71
+ sourcePath + '.json'
72
+ );
73
+
74
+
75
+ if (fs.existsSync(metaPath)) {
76
+ const data = fs.readFileSync(metaPath, 'utf8');
77
+ const jsonData = JSON.parse(data);
78
+ const date90DaysAgo = new Date(
79
+ Date.now() - 14 /* <- days */ * 24 * 60 * 60 * 1000
80
+ );
81
+
82
+ //console.log('Checking:', metaPath);
83
+
84
+ if (jsonData.updated && new Date(jsonData.updated) < date90DaysAgo) {
85
+ console.log('Processing:', metaPath);
86
+ filesToProcess.push(info);
87
+ }
88
+ }
89
+
90
+ break;
91
+ }
92
+ }
93
+ }
94
+ }
95
+
96
+ await recurseFiles('');
97
+
98
+ for (const file of filesToProcess) {
99
+ const source = path.join(imageDirectory, file.path);
100
+ const destination = getDestinationFilePathless(file.path, 'x');
101
+
102
+ const ext = path.parse(source).ext;
103
+
104
+ // Delete original file
105
+ fs.unlinkSync(source);
106
+
107
+ // Delete the fallback file
108
+ switch (ext) {
109
+ case '.png':
110
+ fs.unlinkSync(destination + '.png');
111
+ break;
112
+ case '.jpg':
113
+ case '.jpeg':
114
+ fs.unlinkSync(destination + '.jpg');
115
+ break;
116
+ case '.webp':
117
+ fs.unlinkSync(destination + '.webp');
118
+ break;
119
+ }
120
+
121
+ const metaFile = source + '.json';
122
+
123
+ // Delete metadata file
124
+ fs.unlinkSync(metaFile);
125
+
126
+ // Delete resized images
127
+ for (const key in size) {
128
+ const resizeDestination = getDestinationFilePathless(
129
+ file.path,
130
+ size[key]
131
+ );
132
+
133
+ fs.unlinkSync(resizeDestination + '.webp');
134
+ }
135
+ }