@anglefeint/astro-theme 0.1.32 → 0.1.34
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 +1 -1
- package/src/cli-new-post.mjs +35 -1
- package/src/config/theme.ts +0 -1
package/package.json
CHANGED
package/src/cli-new-post.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mkdir, writeFile, access } from 'node:fs/promises';
|
|
2
2
|
import { constants } from 'node:fs';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { SUPPORTED_LOCALES } from './i18n/locales.mjs';
|
|
5
6
|
import {
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
|
|
15
16
|
const CONTENT_ROOT = path.resolve(process.cwd(), 'src/content/blog');
|
|
16
17
|
const DEFAULT_COVERS_ROOT = path.resolve(process.cwd(), 'src/assets/blog/default-covers');
|
|
18
|
+
const SITE_CONFIG_PATH = path.resolve(process.cwd(), 'src/site.config.ts');
|
|
17
19
|
|
|
18
20
|
async function exists(filePath) {
|
|
19
21
|
try {
|
|
@@ -24,6 +26,37 @@ async function exists(filePath) {
|
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
|
|
29
|
+
function parseSupportedLocalesFromConfig(configSource) {
|
|
30
|
+
const localeArrayPattern = /supportedLocales\s*:\s*\[([\s\S]*?)\]/g;
|
|
31
|
+
let match = null;
|
|
32
|
+
let picked = '';
|
|
33
|
+
|
|
34
|
+
while (true) {
|
|
35
|
+
const next = localeArrayPattern.exec(configSource);
|
|
36
|
+
if (!next) break;
|
|
37
|
+
const body = next[1] ?? '';
|
|
38
|
+
if (body.includes("'") || body.includes('"')) {
|
|
39
|
+
match = next;
|
|
40
|
+
picked = body;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!match || !picked) return [];
|
|
45
|
+
const localeMatches = picked.match(/['"]([a-z]{2,3}(?:-[a-z0-9]+)?)['"]/gi) || [];
|
|
46
|
+
return localeMatches.map((token) => token.slice(1, -1).toLowerCase());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function resolveProjectLocales() {
|
|
50
|
+
try {
|
|
51
|
+
const configSource = await readFile(SITE_CONFIG_PATH, 'utf8');
|
|
52
|
+
const locales = parseSupportedLocalesFromConfig(configSource);
|
|
53
|
+
if (locales.length === 0) return [];
|
|
54
|
+
return Array.from(new Set(locales));
|
|
55
|
+
} catch {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
27
60
|
async function main() {
|
|
28
61
|
const { slug, locales: cliLocales } = parseNewPostArgs(process.argv);
|
|
29
62
|
if (!slug) {
|
|
@@ -38,10 +71,11 @@ async function main() {
|
|
|
38
71
|
|
|
39
72
|
const pubDate = new Date().toISOString().slice(0, 10);
|
|
40
73
|
const defaultCovers = await loadDefaultCovers(DEFAULT_COVERS_ROOT);
|
|
74
|
+
const projectLocales = await resolveProjectLocales();
|
|
41
75
|
const locales = resolveLocales({
|
|
42
76
|
cliLocales,
|
|
43
77
|
envLocales: process.env.ANGLEFEINT_LOCALES ?? '',
|
|
44
|
-
defaultLocales: SUPPORTED_LOCALES,
|
|
78
|
+
defaultLocales: projectLocales.length > 0 ? projectLocales : SUPPORTED_LOCALES,
|
|
45
79
|
});
|
|
46
80
|
const created = [];
|
|
47
81
|
const skipped = [];
|