@verbaly/compiler 0.45.0 → 0.47.0
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/dist/{claude-DAzXUvmS.js → claude-B-vethK9.js} +2 -2
- package/dist/{claude-DAzXUvmS.js.map → claude-B-vethK9.js.map} +1 -1
- package/dist/cli.js +638 -513
- package/dist/cli.js.map +1 -1
- package/dist/{config-ByO-vjIC.js → config-iLrfRYDB.js} +4 -2
- package/dist/config-iLrfRYDB.js.map +1 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +206 -95
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/config-ByO-vjIC.js.map +0 -1
|
@@ -7,14 +7,16 @@ function resolveConfig(config = {}) {
|
|
|
7
7
|
const root = resolve(config.root ?? process.cwd());
|
|
8
8
|
const dir = resolve(root, config.dir ?? "locales");
|
|
9
9
|
const sourceLocale = config.sourceLocale ?? "en";
|
|
10
|
+
const localesDeclared = config.locales !== void 0;
|
|
10
11
|
const locales = /* @__PURE__ */ new Set([sourceLocale, ...config.locales ?? []]);
|
|
11
|
-
if (existsSync(dir)) {
|
|
12
|
+
if (!localesDeclared && existsSync(dir)) {
|
|
12
13
|
for (const file of readdirSync(dir)) if (file.endsWith(".json") && !file.startsWith(".") && file !== `en-XA.json`) locales.add(file.slice(0, -5));
|
|
13
14
|
}
|
|
14
15
|
return {
|
|
15
16
|
root,
|
|
16
17
|
dir,
|
|
17
18
|
sourceLocale,
|
|
19
|
+
localesDeclared,
|
|
18
20
|
routing: config.routing ?? (config.render ? "prefix-except-source" : "no-prefix"),
|
|
19
21
|
icu: config.icu,
|
|
20
22
|
relative: config.relative,
|
|
@@ -79,4 +81,4 @@ function definedOnly(config) {
|
|
|
79
81
|
//#endregion
|
|
80
82
|
export { targetLocales as a, resolveConfig as i, isModuleNotFound as n, loadConfig as r, findConfigFile as t };
|
|
81
83
|
|
|
82
|
-
//# sourceMappingURL=config-
|
|
84
|
+
//# sourceMappingURL=config-iLrfRYDB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-iLrfRYDB.js","names":[],"sources":["../src/pseudo.ts","../src/config.ts"],"sourcesContent":["import type { Catalog, Catalogs } from './catalog';\nimport type { ResolvedConfig } from './config';\n\nexport const PSEUDO_LOCALE = 'en-XA';\n\nconst ACCENTS: Record<string, string> = {\n a: 'á',\n b: 'ƀ',\n c: 'ç',\n d: 'đ',\n e: 'é',\n f: 'ƒ',\n g: 'ğ',\n h: 'ĥ',\n i: 'í',\n j: 'ĵ',\n k: 'ķ',\n l: 'ĺ',\n m: 'ɱ',\n n: 'ñ',\n o: 'ó',\n p: 'þ',\n q: 'ǫ',\n r: 'ŕ',\n s: 'š',\n t: 'ţ',\n u: 'ú',\n v: 'ṽ',\n w: 'ŵ',\n x: 'ẋ',\n y: 'ý',\n z: 'ž',\n A: 'Á',\n B: 'Ɓ',\n C: 'Ç',\n D: 'Đ',\n E: 'É',\n F: 'Ƒ',\n G: 'Ğ',\n H: 'Ĥ',\n I: 'Í',\n J: 'Ĵ',\n K: 'Ķ',\n L: 'Ĺ',\n M: 'Ḿ',\n N: 'Ñ',\n O: 'Ó',\n P: 'Þ',\n Q: 'Ǫ',\n R: 'Ŕ',\n S: 'Š',\n T: 'Ţ',\n U: 'Ú',\n V: 'Ṽ',\n W: 'Ŵ',\n X: 'Ẍ',\n Y: 'Ý',\n Z: 'Ž',\n};\n\nconst TAG_AT = /<\\/?[a-zA-Z][\\w-]*\\/?>/y;\n\n// params, variant blocks, tags and escapes survive verbatim\nexport function pseudoLocalize(message: string): string {\n let out = '';\n let letters = 0;\n let i = 0;\n while (i < message.length) {\n const two = message.slice(i, i + 2);\n if (two === '{{' || two === '}}' || two === '||' || two === '##') {\n out += two;\n i += 2;\n continue;\n }\n const ch = message[i]!;\n if (ch === '{') {\n const end = matchBrace(message, i);\n out += message.slice(i, end);\n i = end;\n continue;\n }\n if (ch === '<') {\n TAG_AT.lastIndex = i;\n const m = TAG_AT.exec(message);\n if (m) {\n out += m[0];\n i += m[0].length;\n continue;\n }\n }\n const mapped = ACCENTS[ch];\n if (mapped) {\n out += mapped;\n letters += 1;\n } else {\n out += ch;\n }\n i += 1;\n }\n const pad = '~'.repeat(Math.ceil(letters / 3));\n return `⟦${out}${pad ? ' ' + pad : ''}⟧`;\n}\n\nfunction matchBrace(message: string, start: number): number {\n let depth = 0;\n for (let i = start; i < message.length; i++) {\n const two = message.slice(i, i + 2);\n if (two === '{{' || two === '}}') {\n i += 1;\n continue;\n }\n const ch = message[i];\n if (ch === '{') depth += 1;\n else if (ch === '}') {\n depth -= 1;\n if (depth === 0) return i + 1;\n }\n }\n return message.length; // unbalanced → verbatim\n}\n\n// regenerates the whole pseudo catalog from the source catalog\nexport function pseudoCatalogs(\n cfg: ResolvedConfig,\n catalogs: Catalogs,\n locale: string = PSEUDO_LOCALE,\n): string[] {\n const source = catalogs[cfg.sourceLocale] ?? {};\n const target: Catalog = {};\n for (const [key, msg] of Object.entries(source)) {\n target[key] = msg ? pseudoLocalize(msg) : '';\n }\n catalogs[locale] = target;\n return Object.keys(target).filter((key) => target[key]);\n}\n","import { existsSync, readFileSync, readdirSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { RichLink, Routing } from 'verbaly';\nimport { PSEUDO_LOCALE } from './pseudo';\nimport type { TranslateProvider } from './translate';\n\n// a term maps to how it must come out: one rendering for every locale, or one per locale\nexport type GlossaryEntry = string | Record<string, string>;\n\nexport interface TranslateConfig {\n provider?: 'claude' | TranslateProvider;\n model?: string;\n batchSize?: number;\n concurrency?: number;\n retries?: number;\n instructions?: string;\n glossary?: Record<string, GlossaryEntry>;\n}\n\nexport interface RedirectConfig {\n on?: 'root' | 'all';\n storageKey?: string | false;\n}\n\nexport interface BundleConfig {\n exclude?: string[];\n}\n\nexport interface RenderConfig {\n links?: Record<string, RichLink>;\n exclude?: string[];\n site?: string;\n attribute?: string;\n base?: string;\n baseUrl?: string;\n hreflang?: boolean;\n sitemap?: boolean | string;\n redirect?: boolean | RedirectConfig;\n clean?: boolean;\n}\n\nexport interface VerbalyConfig {\n root?: string;\n dir?: string;\n sourceLocale?: string;\n locales?: string[];\n routing?: Routing;\n icu?: boolean;\n relative?: boolean;\n include?: string[];\n exclude?: string[];\n dts?: string | false;\n translate?: TranslateConfig;\n render?: RenderConfig;\n bundle?: BundleConfig;\n}\n\nexport interface ResolvedConfig {\n root: string;\n dir: string;\n sourceLocale: string;\n locales: string[];\n localesDeclared: boolean;\n routing: Routing;\n icu: boolean | undefined;\n relative: boolean | undefined;\n include: string[];\n exclude: string[];\n dts: string | false | undefined;\n translate: TranslateConfig;\n render: RenderConfig;\n bundle: BundleConfig;\n}\n\nexport function resolveConfig(config: VerbalyConfig = {}): ResolvedConfig {\n const root = resolve(config.root ?? process.cwd());\n const dir = resolve(root, config.dir ?? 'locales');\n const sourceLocale = config.sourceLocale ?? 'en';\n\n const localesDeclared = config.locales !== undefined;\n const locales = new Set<string>([sourceLocale, ...(config.locales ?? [])]);\n // a declared list is the list: discovery is for a project that never wrote one down\n if (!localesDeclared && existsSync(dir)) {\n for (const file of readdirSync(dir)) {\n if (file.endsWith('.json') && !file.startsWith('.') && file !== `${PSEUDO_LOCALE}.json`) {\n locales.add(file.slice(0, -5));\n }\n }\n }\n\n return {\n root,\n dir,\n sourceLocale,\n localesDeclared,\n // the mode follows the surface: render is what builds a url tree per locale, so it is the tell\n routing: config.routing ?? (config.render ? 'prefix-except-source' : 'no-prefix'),\n // the catalogs decide on their own; these only force it for messages that land after the build\n icu: config.icu,\n relative: config.relative,\n locales: [...locales],\n include: config.include ?? ['{src,app}/**/*.{js,jsx,ts,tsx,mjs,mts,svelte,vue,astro}'],\n exclude: config.exclude ?? ['**/node_modules/**', '**/dist/**'],\n dts: typeof config.dts === 'string' ? resolve(root, config.dts) : config.dts,\n translate: config.translate ?? {},\n render: config.render ?? {},\n bundle: config.bundle ?? {},\n };\n}\n\nconst CONFIG_FILES = [\n 'verbaly.config.js',\n 'verbaly.config.mjs',\n 'verbaly.config.ts',\n 'verbaly.config.mts',\n 'verbaly.config.json',\n];\n\nexport function findConfigFile(root: string): string | undefined {\n return CONFIG_FILES.find((name) => existsSync(join(root, name)));\n}\n\nexport async function loadConfigFile(root: string): Promise<VerbalyConfig> {\n for (const name of ['verbaly.config.js', 'verbaly.config.mjs']) {\n const path = join(root, name);\n if (existsSync(path)) {\n const mod = (await import(pathToFileURL(path).href)) as { default?: VerbalyConfig };\n return mod.default ?? {};\n }\n }\n for (const name of ['verbaly.config.ts', 'verbaly.config.mts']) {\n const path = join(root, name);\n if (existsSync(path)) return loadTsConfig(path);\n }\n const jsonPath = join(root, 'verbaly.config.json');\n if (existsSync(jsonPath)) {\n return JSON.parse(readFileSync(jsonPath, 'utf8')) as VerbalyConfig;\n }\n return {};\n}\n\nasync function loadTsConfig(path: string): Promise<VerbalyConfig> {\n try {\n const { bundleRequire } = await import('bundle-require');\n const { mod } = await bundleRequire<{ default?: VerbalyConfig }>({ filepath: path });\n return mod.default ?? {};\n } catch (error) {\n if (isModuleNotFound(error, 'esbuild')) {\n throw new Error(`[verbaly] ${path} needs esbuild: install it with pnpm add -D esbuild`, {\n cause: error,\n });\n }\n throw error;\n }\n}\n\nexport function isModuleNotFound(error: unknown, name: string): boolean {\n return (\n error instanceof Error &&\n (error as { code?: string }).code === 'ERR_MODULE_NOT_FOUND' &&\n error.message.includes(name)\n );\n}\n\n// non-source locales a command may write to (optional CLI override, always config-bounded)\nexport function targetLocales(cfg: ResolvedConfig, override?: string[]): string[] {\n return (override ?? cfg.locales).filter(\n (locale) => locale !== cfg.sourceLocale && cfg.locales.includes(locale),\n );\n}\n\n// file config + inline overrides\nexport async function loadConfig(\n root: string,\n overrides: VerbalyConfig = {},\n): Promise<ResolvedConfig> {\n const fileConfig = await loadConfigFile(root);\n return resolveConfig({ ...fileConfig, ...definedOnly(overrides), root });\n}\n\nfunction definedOnly(config: VerbalyConfig): VerbalyConfig {\n return Object.fromEntries(\n Object.entries(config).filter(([, value]) => value !== undefined),\n ) as VerbalyConfig;\n}\n"],"mappings":"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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ interface BundleConfig {
|
|
|
70
70
|
}
|
|
71
71
|
interface RenderConfig {
|
|
72
72
|
links?: Record<string, RichLink>;
|
|
73
|
+
exclude?: string[];
|
|
73
74
|
site?: string;
|
|
74
75
|
attribute?: string;
|
|
75
76
|
base?: string;
|
|
@@ -99,6 +100,7 @@ interface ResolvedConfig {
|
|
|
99
100
|
dir: string;
|
|
100
101
|
sourceLocale: string;
|
|
101
102
|
locales: string[];
|
|
103
|
+
localesDeclared: boolean;
|
|
102
104
|
routing: Routing;
|
|
103
105
|
icu: boolean | undefined;
|
|
104
106
|
relative: boolean | undefined;
|
|
@@ -245,7 +247,7 @@ interface CheckResult {
|
|
|
245
247
|
broken: BrokenEntry[];
|
|
246
248
|
}
|
|
247
249
|
declare function check(cfg: ResolvedConfig, catalogs: Catalogs, registry: MessageRegistry): CheckResult;
|
|
248
|
-
declare function formatCheckResult(result: CheckResult): string;
|
|
250
|
+
declare function formatCheckResult(result: CheckResult, root?: string): string;
|
|
249
251
|
declare function formatCheckWarnings(result: CheckResult): string;
|
|
250
252
|
//#endregion
|
|
251
253
|
//#region src/drafts.d.ts
|
|
@@ -302,11 +304,17 @@ interface WrapSkip {
|
|
|
302
304
|
text: string;
|
|
303
305
|
reason: string;
|
|
304
306
|
}
|
|
307
|
+
interface WrapBlocked {
|
|
308
|
+
file: string;
|
|
309
|
+
texts: number;
|
|
310
|
+
client: boolean;
|
|
311
|
+
}
|
|
305
312
|
interface WrapResult {
|
|
306
313
|
files: number;
|
|
307
314
|
changed: string[];
|
|
308
315
|
wrapped: WrapEntry[];
|
|
309
316
|
skipped: WrapSkip[];
|
|
317
|
+
blocked: WrapBlocked[];
|
|
310
318
|
}
|
|
311
319
|
interface WrapOptions {
|
|
312
320
|
write?: boolean;
|
|
@@ -323,6 +331,7 @@ interface RenderSiteOptions {
|
|
|
323
331
|
base?: string;
|
|
324
332
|
baseUrl?: string;
|
|
325
333
|
hreflang?: boolean;
|
|
334
|
+
exclude?: string[];
|
|
326
335
|
sitemap?: boolean | string;
|
|
327
336
|
redirect?: boolean | RedirectConfig;
|
|
328
337
|
clean?: boolean;
|
|
@@ -336,5 +345,5 @@ interface RenderSiteResult {
|
|
|
336
345
|
declare function renderSite(cfg: ResolvedConfig, options?: RenderSiteOptions): Promise<RenderSiteResult>;
|
|
337
346
|
declare function formatRenderWarnings(result: RenderSiteResult, sourceLocale: string): string[];
|
|
338
347
|
//#endregion
|
|
339
|
-
export { type BrokenEntry, type BundleConfig, type Catalog, type Catalogs, type CheckResult, type DoctorEntry, type DoctorResult, type Drafts, type GlossaryEntry, type IssueSeverity, LOCALE_MODULE_PREFIX, type LocaleStatus, MessageRegistry, type MissingEntry, type PluginOptions, RESOLVED_VIRTUAL_ID, type RedirectConfig, type RenderConfig, type RenderSiteOptions, type RenderSiteResult, type ResolvedConfig, type RuntimeModuleOptions, SOURCE_FILE_RE, type StatusResult, type SyncResult, type TransformResult, type TranslateConfig, type TranslateFailure, type TranslateOptions, type TranslateProgress, type TranslateProvider, type TranslateRequest, type TranslateResult, type UnknownEntry, type VerbalyConfig, type WrapEntry, type WrapOptions, type WrapResult, type WrapSkip, check, clientCatalogs, collectOrigins, counted, createSourceFilter, doctor, effectiveDrafts, extractProject, formatCheckResult, formatCheckWarnings, formatDoctorEntry, formatRenderWarnings, formatStatusResult, formatTranslateFailures, generateDts, generateLocaleModule, generateRuntimeModule, isTransformTarget, loadCatalogs, loadConfig, loadDrafts, loadVirtualModule, markDrafts, needsIcu, needsRelative, pruneCatalogs, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, stableKey, status, syncCatalogs, transformCode, transformSource, translateCatalogs, wrapProject, writeCatalog, writeDts };
|
|
348
|
+
export { type BrokenEntry, type BundleConfig, type Catalog, type Catalogs, type CheckResult, type DoctorEntry, type DoctorResult, type Drafts, type GlossaryEntry, type IssueSeverity, LOCALE_MODULE_PREFIX, type LocaleStatus, MessageRegistry, type MissingEntry, type PluginOptions, RESOLVED_VIRTUAL_ID, type RedirectConfig, type RenderConfig, type RenderSiteOptions, type RenderSiteResult, type ResolvedConfig, type RuntimeModuleOptions, SOURCE_FILE_RE, type StatusResult, type SyncResult, type TransformResult, type TranslateConfig, type TranslateFailure, type TranslateOptions, type TranslateProgress, type TranslateProvider, type TranslateRequest, type TranslateResult, type UnknownEntry, type VerbalyConfig, type WrapBlocked, type WrapEntry, type WrapOptions, type WrapResult, type WrapSkip, check, clientCatalogs, collectOrigins, counted, createSourceFilter, doctor, effectiveDrafts, extractProject, formatCheckResult, formatCheckWarnings, formatDoctorEntry, formatRenderWarnings, formatStatusResult, formatTranslateFailures, generateDts, generateLocaleModule, generateRuntimeModule, isTransformTarget, loadCatalogs, loadConfig, loadDrafts, loadVirtualModule, markDrafts, needsIcu, needsRelative, pruneCatalogs, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, stableKey, status, syncCatalogs, transformCode, transformSource, translateCatalogs, wrapProject, writeCatalog, writeDts };
|
|
340
349
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as targetLocales, i as resolveConfig, r as loadConfig, t as findConfigFile } from "./config-
|
|
1
|
+
import { a as targetLocales, i as resolveConfig, r as loadConfig, t as findConfigFile } from "./config-iLrfRYDB.js";
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join, relative } from "node:path";
|
|
4
4
|
import { LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, createVerbaly, flatten, localeDirection, normalizeLink, parse, parseTags, safeAttribute } from "verbaly";
|
|
@@ -242,6 +242,7 @@ const SKIP_KEYS = /* @__PURE__ */ new Set([
|
|
|
242
242
|
]);
|
|
243
243
|
const DEFAULT_T_NAMES = ["t"];
|
|
244
244
|
const JSX_FILE_RE = /\.(?:[cm]?jsx?|tsx)$/;
|
|
245
|
+
const DEFINE_KEYS = "defineKeys";
|
|
245
246
|
function analyze(code, file, options = {}) {
|
|
246
247
|
const names = new Set(options.tNames ?? DEFAULT_T_NAMES);
|
|
247
248
|
const ast = parse$1(code, {
|
|
@@ -273,8 +274,13 @@ function analyze(code, file, options = {}) {
|
|
|
273
274
|
});
|
|
274
275
|
} else if (node.type === "CallExpression") {
|
|
275
276
|
const callee = node.callee;
|
|
277
|
+
const args = node.arguments;
|
|
278
|
+
if (callee.type === "Identifier" && callee.name === DEFINE_KEYS) {
|
|
279
|
+
collectDeclaredKeys(args[0], file, usedKeys);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
276
282
|
if (!isTReference(callee, names)) return;
|
|
277
|
-
const first =
|
|
283
|
+
const first = args[0];
|
|
278
284
|
if (first?.type === "StringLiteral") usedKeys.push({
|
|
279
285
|
key: first.value,
|
|
280
286
|
file
|
|
@@ -287,6 +293,19 @@ function analyze(code, file, options = {}) {
|
|
|
287
293
|
strayImports
|
|
288
294
|
};
|
|
289
295
|
}
|
|
296
|
+
function collectDeclaredKeys(node, file, out) {
|
|
297
|
+
if (node?.type !== "ObjectExpression") return;
|
|
298
|
+
for (const property of node.properties) {
|
|
299
|
+
if (property.type !== "ObjectProperty") continue;
|
|
300
|
+
const value = property.value;
|
|
301
|
+
if (value.type === "StringLiteral") {
|
|
302
|
+
if (value.value !== "") out.push({
|
|
303
|
+
key: value.value,
|
|
304
|
+
file
|
|
305
|
+
});
|
|
306
|
+
} else if (value.type === "ObjectExpression") collectDeclaredKeys(value, file, out);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
290
309
|
const VERBALY_PACKAGE = /^(?:verbaly|@verbaly\/[\w-]+)$/;
|
|
291
310
|
function collectStrayImports(node, file, out) {
|
|
292
311
|
const source = node.source;
|
|
@@ -294,8 +313,10 @@ function collectStrayImports(node, file, out) {
|
|
|
294
313
|
for (const spec of node.specifiers) {
|
|
295
314
|
if (spec.type !== "ImportSpecifier") continue;
|
|
296
315
|
const imported = spec.imported;
|
|
297
|
-
if (imported.type
|
|
298
|
-
|
|
316
|
+
if (imported.type !== "Identifier") continue;
|
|
317
|
+
const name = imported.name;
|
|
318
|
+
if (name === "t" || name === DEFINE_KEYS) out.push({
|
|
319
|
+
name,
|
|
299
320
|
source: source.value,
|
|
300
321
|
file
|
|
301
322
|
});
|
|
@@ -948,6 +969,11 @@ export function localeFromPath(options) {
|
|
|
948
969
|
return readPath({ ...options, supported: locales });
|
|
949
970
|
}
|
|
950
971
|
|
|
972
|
+
// identity: it exists so the compiler can see keys that live in a module instead of at a call site
|
|
973
|
+
export function defineKeys(keys) {
|
|
974
|
+
return keys;
|
|
975
|
+
}
|
|
976
|
+
|
|
951
977
|
// the whole switch a language control needs, in either mode: catalog or navigation, then persistence
|
|
952
978
|
export function switchLocale(locale, options) {
|
|
953
979
|
return runSwitch(v, locale, { supported: locales, sourceLocale, routing, ...options });
|
|
@@ -1021,6 +1047,9 @@ ${lines.join("\n")}
|
|
|
1021
1047
|
}
|
|
1022
1048
|
export type VerbalyKey = keyof VerbalyMessages & string;
|
|
1023
1049
|
|
|
1050
|
+
export type VerbalyKeyTree = VerbalyKey | { readonly [name: string]: VerbalyKeyTree };
|
|
1051
|
+
export function defineKeys<const T extends VerbalyKeyTree>(keys: T): T;
|
|
1052
|
+
|
|
1024
1053
|
export const verbaly: import('verbaly').Verbaly<VerbalyKey>;
|
|
1025
1054
|
|
|
1026
1055
|
export const sourceLocale: string;
|
|
@@ -1081,6 +1110,87 @@ function writeDts(cfg, catalog, file) {
|
|
|
1081
1110
|
writeFileSync(file, content);
|
|
1082
1111
|
}
|
|
1083
1112
|
//#endregion
|
|
1113
|
+
//#region src/init.ts
|
|
1114
|
+
const HOSTS = [
|
|
1115
|
+
{
|
|
1116
|
+
name: "nuxt",
|
|
1117
|
+
dep: "nuxt",
|
|
1118
|
+
pkg: "@verbaly/nuxt",
|
|
1119
|
+
wire: "add '@verbaly/nuxt' to the modules in nuxt.config"
|
|
1120
|
+
},
|
|
1121
|
+
{
|
|
1122
|
+
name: "next",
|
|
1123
|
+
dep: "next",
|
|
1124
|
+
pkg: "@verbaly/next",
|
|
1125
|
+
wire: "wrap the export of next.config with withVerbaly"
|
|
1126
|
+
},
|
|
1127
|
+
{
|
|
1128
|
+
name: "sveltekit",
|
|
1129
|
+
dep: "@sveltejs/kit",
|
|
1130
|
+
pkg: "@verbaly/vite",
|
|
1131
|
+
wire: "add verbaly() to the plugins in vite.config (per-request locale: @verbaly/sveltekit)"
|
|
1132
|
+
},
|
|
1133
|
+
{
|
|
1134
|
+
name: "astro",
|
|
1135
|
+
dep: "astro",
|
|
1136
|
+
pkg: "@verbaly/astro",
|
|
1137
|
+
wire: "add verbaly() to the integrations in astro.config"
|
|
1138
|
+
},
|
|
1139
|
+
{
|
|
1140
|
+
name: "vite",
|
|
1141
|
+
dep: "vite",
|
|
1142
|
+
pkg: "@verbaly/vite",
|
|
1143
|
+
wire: "add verbaly() to the plugins in vite.config"
|
|
1144
|
+
},
|
|
1145
|
+
{
|
|
1146
|
+
name: "webpack",
|
|
1147
|
+
dep: "webpack",
|
|
1148
|
+
pkg: "@verbaly/unplugin",
|
|
1149
|
+
wire: "add the verbaly webpack plugin to your build config"
|
|
1150
|
+
},
|
|
1151
|
+
{
|
|
1152
|
+
name: "rspack",
|
|
1153
|
+
dep: "@rspack/core",
|
|
1154
|
+
pkg: "@verbaly/unplugin",
|
|
1155
|
+
wire: "add the verbaly rspack plugin to your build config"
|
|
1156
|
+
},
|
|
1157
|
+
{
|
|
1158
|
+
name: "rollup",
|
|
1159
|
+
dep: "rollup",
|
|
1160
|
+
pkg: "@verbaly/unplugin",
|
|
1161
|
+
wire: "add the verbaly rollup plugin to your build config"
|
|
1162
|
+
},
|
|
1163
|
+
{
|
|
1164
|
+
name: "esbuild",
|
|
1165
|
+
dep: "esbuild",
|
|
1166
|
+
pkg: "@verbaly/unplugin",
|
|
1167
|
+
wire: "add the verbaly esbuild plugin to your build config"
|
|
1168
|
+
}
|
|
1169
|
+
];
|
|
1170
|
+
const WIRING_PACKAGES = [...new Set(HOSTS.map((host) => host.pkg))];
|
|
1171
|
+
function readDependencies(root) {
|
|
1172
|
+
const path = join(root, "package.json");
|
|
1173
|
+
if (!existsSync(path)) return {};
|
|
1174
|
+
try {
|
|
1175
|
+
const pkg = JSON.parse(readFileSync(path, "utf8"));
|
|
1176
|
+
return {
|
|
1177
|
+
...pkg.dependencies,
|
|
1178
|
+
...pkg.devDependencies
|
|
1179
|
+
};
|
|
1180
|
+
} catch {
|
|
1181
|
+
return {};
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
function cliReachable(root) {
|
|
1185
|
+
const bin = join(root, "node_modules", ".bin");
|
|
1186
|
+
return existsSync(join(bin, "verbaly")) || existsSync(join(bin, "verbaly.CMD"));
|
|
1187
|
+
}
|
|
1188
|
+
const CLI_INSTALL_FIX = "add `@verbaly/compiler` to your dev dependencies, then `npx verbaly` resolves";
|
|
1189
|
+
function detectHost(root) {
|
|
1190
|
+
const deps = readDependencies(root);
|
|
1191
|
+
return HOSTS.find((host) => deps[host.dep]);
|
|
1192
|
+
}
|
|
1193
|
+
//#endregion
|
|
1084
1194
|
//#region src/check.ts
|
|
1085
1195
|
function gatePasses(result) {
|
|
1086
1196
|
return result.missing.length === 0 && result.unknown.length === 0 && !result.broken.some((entry) => entry.severity === "error");
|
|
@@ -1142,7 +1252,8 @@ function check(cfg, catalogs, registry) {
|
|
|
1142
1252
|
broken
|
|
1143
1253
|
};
|
|
1144
1254
|
}
|
|
1145
|
-
function formatCheckResult(result) {
|
|
1255
|
+
function formatCheckResult(result, root) {
|
|
1256
|
+
const show = (file) => root ? relative(root, file).replaceAll("\\", "/") : file;
|
|
1146
1257
|
const lines = [];
|
|
1147
1258
|
if (result.missing.length > 0) {
|
|
1148
1259
|
lines.push("missing translations:");
|
|
@@ -1153,7 +1264,7 @@ function formatCheckResult(result) {
|
|
|
1153
1264
|
}
|
|
1154
1265
|
if (result.unknown.length > 0) {
|
|
1155
1266
|
lines.push("unknown keys (not in any catalog):");
|
|
1156
|
-
for (const entry of result.unknown) lines.push(` ${entry.key} (used in ${entry.files.join(", ")})`);
|
|
1267
|
+
for (const entry of result.unknown) lines.push(` ${entry.key} (used in ${entry.files.map(show).join(", ")})`);
|
|
1157
1268
|
}
|
|
1158
1269
|
const errors = result.broken.filter((entry) => entry.severity === "error");
|
|
1159
1270
|
if (errors.length > 0) {
|
|
@@ -1162,11 +1273,12 @@ function formatCheckResult(result) {
|
|
|
1162
1273
|
}
|
|
1163
1274
|
return lines.join("\n");
|
|
1164
1275
|
}
|
|
1165
|
-
function checkNextSteps(result) {
|
|
1276
|
+
function checkNextSteps(result, cliReachable = true) {
|
|
1166
1277
|
const steps = [];
|
|
1167
1278
|
if (result.missing.length > 0) steps.push("missing: run `npx verbaly extract` to scaffold the keys, then fill them (or run `npx verbaly translate`)");
|
|
1168
1279
|
if (result.unknown.length > 0) steps.push("unknown keys: the key used in the code is in no catalog, fix the key or run `npx verbaly extract`");
|
|
1169
1280
|
if (result.broken.some((entry) => entry.severity === "error")) steps.push("broken: a translation has to keep the params, tags and plural cases of its source message");
|
|
1281
|
+
if (steps.length > 0 && !cliReachable) steps.push(`the verbaly command is not linked in this project: ${CLI_INSTALL_FIX}`);
|
|
1170
1282
|
return steps.join("\n");
|
|
1171
1283
|
}
|
|
1172
1284
|
function formatCheckWarnings(result) {
|
|
@@ -1253,7 +1365,7 @@ function runBuildGate(cfg, registry, failOnMissing) {
|
|
|
1253
1365
|
missing: []
|
|
1254
1366
|
} : found;
|
|
1255
1367
|
if (gatePasses(result)) return;
|
|
1256
|
-
throw new Error(`[verbaly] build blocked\n${formatCheckResult(result)}\n${checkNextSteps(result)}`);
|
|
1368
|
+
throw new Error(`[verbaly] build blocked\n${formatCheckResult(result, cfg.root)}\n${checkNextSteps(result, cliReachable(cfg.root))}`);
|
|
1257
1369
|
}
|
|
1258
1370
|
//#endregion
|
|
1259
1371
|
//#region src/drafts.ts
|
|
@@ -1486,7 +1598,7 @@ function formatTranslateFailures(failed) {
|
|
|
1486
1598
|
async function resolveProvider(cfg, model) {
|
|
1487
1599
|
const configured = cfg.translate.provider;
|
|
1488
1600
|
if (typeof configured === "function") return configured;
|
|
1489
|
-
const { claudeProvider } = await import("./claude-
|
|
1601
|
+
const { claudeProvider } = await import("./claude-B-vethK9.js");
|
|
1490
1602
|
return claudeProvider({ model: model ?? cfg.translate.model });
|
|
1491
1603
|
}
|
|
1492
1604
|
function structureMatches(source, translated) {
|
|
@@ -1517,82 +1629,6 @@ function glossaryFor(cfg, locale, messages) {
|
|
|
1517
1629
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
1518
1630
|
}
|
|
1519
1631
|
//#endregion
|
|
1520
|
-
//#region src/init.ts
|
|
1521
|
-
const HOSTS = [
|
|
1522
|
-
{
|
|
1523
|
-
name: "nuxt",
|
|
1524
|
-
dep: "nuxt",
|
|
1525
|
-
pkg: "@verbaly/nuxt",
|
|
1526
|
-
wire: "add '@verbaly/nuxt' to the modules in nuxt.config"
|
|
1527
|
-
},
|
|
1528
|
-
{
|
|
1529
|
-
name: "next",
|
|
1530
|
-
dep: "next",
|
|
1531
|
-
pkg: "@verbaly/next",
|
|
1532
|
-
wire: "wrap the export of next.config with withVerbaly"
|
|
1533
|
-
},
|
|
1534
|
-
{
|
|
1535
|
-
name: "sveltekit",
|
|
1536
|
-
dep: "@sveltejs/kit",
|
|
1537
|
-
pkg: "@verbaly/vite",
|
|
1538
|
-
wire: "add verbaly() to the plugins in vite.config (per-request locale: @verbaly/sveltekit)"
|
|
1539
|
-
},
|
|
1540
|
-
{
|
|
1541
|
-
name: "astro",
|
|
1542
|
-
dep: "astro",
|
|
1543
|
-
pkg: "@verbaly/astro",
|
|
1544
|
-
wire: "add verbaly() to the integrations in astro.config"
|
|
1545
|
-
},
|
|
1546
|
-
{
|
|
1547
|
-
name: "vite",
|
|
1548
|
-
dep: "vite",
|
|
1549
|
-
pkg: "@verbaly/vite",
|
|
1550
|
-
wire: "add verbaly() to the plugins in vite.config"
|
|
1551
|
-
},
|
|
1552
|
-
{
|
|
1553
|
-
name: "webpack",
|
|
1554
|
-
dep: "webpack",
|
|
1555
|
-
pkg: "@verbaly/unplugin",
|
|
1556
|
-
wire: "add the verbaly webpack plugin to your build config"
|
|
1557
|
-
},
|
|
1558
|
-
{
|
|
1559
|
-
name: "rspack",
|
|
1560
|
-
dep: "@rspack/core",
|
|
1561
|
-
pkg: "@verbaly/unplugin",
|
|
1562
|
-
wire: "add the verbaly rspack plugin to your build config"
|
|
1563
|
-
},
|
|
1564
|
-
{
|
|
1565
|
-
name: "rollup",
|
|
1566
|
-
dep: "rollup",
|
|
1567
|
-
pkg: "@verbaly/unplugin",
|
|
1568
|
-
wire: "add the verbaly rollup plugin to your build config"
|
|
1569
|
-
},
|
|
1570
|
-
{
|
|
1571
|
-
name: "esbuild",
|
|
1572
|
-
dep: "esbuild",
|
|
1573
|
-
pkg: "@verbaly/unplugin",
|
|
1574
|
-
wire: "add the verbaly esbuild plugin to your build config"
|
|
1575
|
-
}
|
|
1576
|
-
];
|
|
1577
|
-
const WIRING_PACKAGES = [...new Set(HOSTS.map((host) => host.pkg))];
|
|
1578
|
-
function readDependencies(root) {
|
|
1579
|
-
const path = join(root, "package.json");
|
|
1580
|
-
if (!existsSync(path)) return {};
|
|
1581
|
-
try {
|
|
1582
|
-
const pkg = JSON.parse(readFileSync(path, "utf8"));
|
|
1583
|
-
return {
|
|
1584
|
-
...pkg.dependencies,
|
|
1585
|
-
...pkg.devDependencies
|
|
1586
|
-
};
|
|
1587
|
-
} catch {
|
|
1588
|
-
return {};
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
function detectHost(root) {
|
|
1592
|
-
const deps = readDependencies(root);
|
|
1593
|
-
return HOSTS.find((host) => deps[host.dep]);
|
|
1594
|
-
}
|
|
1595
|
-
//#endregion
|
|
1596
1632
|
//#region src/doctor.ts
|
|
1597
1633
|
const PREVIEW = 5;
|
|
1598
1634
|
function readRoutingChoice(root, configFile) {
|
|
@@ -1640,6 +1676,8 @@ async function doctor(cfg) {
|
|
|
1640
1676
|
const configFile = findConfigFile(cfg.root);
|
|
1641
1677
|
if (configFile) ok("config", `${configFile} found`);
|
|
1642
1678
|
else warn("config", "no config file, running on defaults", "run `npx verbaly init`");
|
|
1679
|
+
if (cliReachable(cfg.root)) ok("cli", "the verbaly command is available in this project");
|
|
1680
|
+
else warn("cli", "the verbaly command is not linked in node_modules/.bin", CLI_INSTALL_FIX);
|
|
1643
1681
|
const catalogs = {};
|
|
1644
1682
|
let catalogsHealthy = true;
|
|
1645
1683
|
if (!existsSync(cfg.dir)) {
|
|
@@ -1665,7 +1703,10 @@ async function doctor(cfg) {
|
|
|
1665
1703
|
error(`locale ${locale}`, `${rel(file)} is not valid JSON`, "repair the file (or delete it and run `npx verbaly extract`)");
|
|
1666
1704
|
}
|
|
1667
1705
|
}
|
|
1668
|
-
if (catalogsHealthy)
|
|
1706
|
+
if (catalogsHealthy) {
|
|
1707
|
+
const how = cfg.localesDeclared ? "" : ", no locales set, so the catalog files decide";
|
|
1708
|
+
ok("catalogs", `${counted(cfg.locales.length, "locale")} (${cfg.locales.join(", ")}) in ${rel(cfg.dir)}/${how}`);
|
|
1709
|
+
}
|
|
1669
1710
|
}
|
|
1670
1711
|
const source = catalogs[cfg.sourceLocale];
|
|
1671
1712
|
if (source && Object.keys(source).length === 0) warn("source", `source catalog ${cfg.sourceLocale}.json is empty`, "write your first t`…` message and run `npx verbaly extract`");
|
|
@@ -1753,8 +1794,16 @@ const WRAP_ATTRS = /* @__PURE__ */ new Set([
|
|
|
1753
1794
|
"placeholder",
|
|
1754
1795
|
"aria-label"
|
|
1755
1796
|
]);
|
|
1797
|
+
const CODE_TAGS = /* @__PURE__ */ new Set([
|
|
1798
|
+
"code",
|
|
1799
|
+
"pre",
|
|
1800
|
+
"kbd",
|
|
1801
|
+
"samp",
|
|
1802
|
+
"var"
|
|
1803
|
+
]);
|
|
1756
1804
|
const T_NAMES = /* @__PURE__ */ new Set(["t"]);
|
|
1757
1805
|
const LETTER = /\p{L}/u;
|
|
1806
|
+
const WHITESPACE = /\s/;
|
|
1758
1807
|
async function wrapProject(cfg, options = {}) {
|
|
1759
1808
|
const files = (await glob(cfg.include, {
|
|
1760
1809
|
cwd: cfg.root,
|
|
@@ -1765,7 +1814,8 @@ async function wrapProject(cfg, options = {}) {
|
|
|
1765
1814
|
files: files.length,
|
|
1766
1815
|
changed: [],
|
|
1767
1816
|
wrapped: [],
|
|
1768
|
-
skipped: []
|
|
1817
|
+
skipped: [],
|
|
1818
|
+
blocked: []
|
|
1769
1819
|
};
|
|
1770
1820
|
for (const file of files) {
|
|
1771
1821
|
const code = readFileSync(file, "utf8");
|
|
@@ -1773,10 +1823,17 @@ async function wrapProject(cfg, options = {}) {
|
|
|
1773
1823
|
const out = wrapCode(code, label);
|
|
1774
1824
|
result.wrapped.push(...out.wrapped);
|
|
1775
1825
|
result.skipped.push(...out.skipped);
|
|
1776
|
-
if (out.code
|
|
1777
|
-
|
|
1778
|
-
|
|
1826
|
+
if (out.code === void 0) continue;
|
|
1827
|
+
result.changed.push(label);
|
|
1828
|
+
if (!out.hasT) {
|
|
1829
|
+
result.blocked.push({
|
|
1830
|
+
file: label,
|
|
1831
|
+
texts: out.wrapped.length,
|
|
1832
|
+
client: out.client
|
|
1833
|
+
});
|
|
1834
|
+
continue;
|
|
1779
1835
|
}
|
|
1836
|
+
if (options.write) writeFileSync(file, out.code);
|
|
1780
1837
|
}
|
|
1781
1838
|
return result;
|
|
1782
1839
|
}
|
|
@@ -1793,9 +1850,13 @@ function wrapCode(code, file) {
|
|
|
1793
1850
|
} catch {
|
|
1794
1851
|
return {
|
|
1795
1852
|
wrapped,
|
|
1796
|
-
skipped
|
|
1853
|
+
skipped,
|
|
1854
|
+
hasT: false,
|
|
1855
|
+
client: false
|
|
1797
1856
|
};
|
|
1798
1857
|
}
|
|
1858
|
+
const hasT = declaresT(ast);
|
|
1859
|
+
const client = hasDirective(ast, "use client");
|
|
1799
1860
|
const s = new MagicString(code);
|
|
1800
1861
|
const visited = /* @__PURE__ */ new Set();
|
|
1801
1862
|
let changed = false;
|
|
@@ -1807,10 +1868,14 @@ function wrapCode(code, file) {
|
|
|
1807
1868
|
return changed ? {
|
|
1808
1869
|
code: s.toString(),
|
|
1809
1870
|
wrapped,
|
|
1810
|
-
skipped
|
|
1871
|
+
skipped,
|
|
1872
|
+
hasT,
|
|
1873
|
+
client
|
|
1811
1874
|
} : {
|
|
1812
1875
|
wrapped,
|
|
1813
|
-
skipped
|
|
1876
|
+
skipped,
|
|
1877
|
+
hasT,
|
|
1878
|
+
client
|
|
1814
1879
|
};
|
|
1815
1880
|
function processElement(node) {
|
|
1816
1881
|
visited.add(node);
|
|
@@ -1819,6 +1884,7 @@ function wrapCode(code, file) {
|
|
|
1819
1884
|
const name = opening.name;
|
|
1820
1885
|
if (name.type === "JSXIdentifier" && name.name === "Trans") return markSubtree(node);
|
|
1821
1886
|
if (hasVerbalyAttr(opening)) return markSubtree(node);
|
|
1887
|
+
if (name.type === "JSXIdentifier" && CODE_TAGS.has(name.name)) return markSubtree(node);
|
|
1822
1888
|
wrapAttributes(opening);
|
|
1823
1889
|
}
|
|
1824
1890
|
const children = node.children ?? [];
|
|
@@ -1839,6 +1905,10 @@ function wrapCode(code, file) {
|
|
|
1839
1905
|
if (meaningful.length === 0) return;
|
|
1840
1906
|
const first = meaningful[0];
|
|
1841
1907
|
const last = meaningful[meaningful.length - 1];
|
|
1908
|
+
if (first.type === "JSXExpressionContainer" && meaningful.length > 1) {
|
|
1909
|
+
skip(parent, snippet(children), "starts with an interpolation: wrap the sentence by hand");
|
|
1910
|
+
return;
|
|
1911
|
+
}
|
|
1842
1912
|
let template = "";
|
|
1843
1913
|
let report = "";
|
|
1844
1914
|
for (let i = children.indexOf(first); i <= children.indexOf(last); i++) {
|
|
@@ -1872,6 +1942,7 @@ function wrapCode(code, file) {
|
|
|
1872
1942
|
} else return;
|
|
1873
1943
|
}
|
|
1874
1944
|
if (!LETTER.test(report)) return;
|
|
1945
|
+
if (isIdentifierLike(report)) return;
|
|
1875
1946
|
const start = first.type === "JSXText" ? first.start + leadingWs(first.value) : first.start;
|
|
1876
1947
|
const end = last.type === "JSXText" ? last.end - trailingWs(last.value) : last.end;
|
|
1877
1948
|
s.overwrite(start, end, "{t`" + template + "`}");
|
|
@@ -1891,7 +1962,7 @@ function wrapCode(code, file) {
|
|
|
1891
1962
|
const value = attr.value;
|
|
1892
1963
|
if (value?.type !== "StringLiteral") continue;
|
|
1893
1964
|
const raw = value.value;
|
|
1894
|
-
if (!LETTER.test(raw)) continue;
|
|
1965
|
+
if (!LETTER.test(raw) || isIdentifierLike(raw)) continue;
|
|
1895
1966
|
s.overwrite(value.start, value.end, "{t`" + escapeTemplate(raw) + "`}");
|
|
1896
1967
|
changed = true;
|
|
1897
1968
|
wrapped.push({
|
|
@@ -1923,6 +1994,40 @@ function wrapCode(code, file) {
|
|
|
1923
1994
|
});
|
|
1924
1995
|
}
|
|
1925
1996
|
}
|
|
1997
|
+
function isIdentifierLike(text) {
|
|
1998
|
+
const trimmed = text.trim();
|
|
1999
|
+
if (WHITESPACE.test(trimmed)) return false;
|
|
2000
|
+
const first = [...trimmed].find((char) => LETTER.test(char));
|
|
2001
|
+
return first !== void 0 && first !== first.toUpperCase();
|
|
2002
|
+
}
|
|
2003
|
+
function hasDirective(program, value) {
|
|
2004
|
+
return (program.directives ?? []).some((d) => d.value?.value === value);
|
|
2005
|
+
}
|
|
2006
|
+
function declaresT(program) {
|
|
2007
|
+
let found = false;
|
|
2008
|
+
walk$1(program, (node) => {
|
|
2009
|
+
if (found) return;
|
|
2010
|
+
if (node.type === "ImportDeclaration") {
|
|
2011
|
+
for (const spec of node.specifiers) if (isTName(spec.local?.name)) found = true;
|
|
2012
|
+
return;
|
|
2013
|
+
}
|
|
2014
|
+
if (node.type === "VariableDeclarator" && bindsT(node.id)) found = true;
|
|
2015
|
+
if (node.type === "FunctionDeclaration" && isTName(node.id?.name)) found = true;
|
|
2016
|
+
if (node.params?.some((param) => bindsT(param))) found = true;
|
|
2017
|
+
});
|
|
2018
|
+
return found;
|
|
2019
|
+
}
|
|
2020
|
+
function bindsT(pattern) {
|
|
2021
|
+
if (!pattern) return false;
|
|
2022
|
+
if (pattern.type === "Identifier") return isTName(pattern.name);
|
|
2023
|
+
if (pattern.type === "AssignmentPattern") return bindsT(pattern.left);
|
|
2024
|
+
if (pattern.type === "ObjectPattern") return pattern.properties.some((prop) => prop.type === "RestElement" ? bindsT(prop.argument) : bindsT(prop.value));
|
|
2025
|
+
if (pattern.type === "ArrayPattern") return pattern.elements.some((el) => bindsT(el ?? void 0));
|
|
2026
|
+
return false;
|
|
2027
|
+
}
|
|
2028
|
+
function isTName(name) {
|
|
2029
|
+
return typeof name === "string" && T_NAMES.has(name);
|
|
2030
|
+
}
|
|
1926
2031
|
function hasVerbalyAttr(opening) {
|
|
1927
2032
|
return opening.attributes.some((attr) => {
|
|
1928
2033
|
if (attr.type !== "JSXAttribute") return false;
|
|
@@ -2134,6 +2239,10 @@ function injectAlternates(ms, html, alternates) {
|
|
|
2134
2239
|
}
|
|
2135
2240
|
const TITLE_TAG = /<title\b([^>]*)>/i;
|
|
2136
2241
|
const REFRESH_META = /<meta\b[^>]*http-equiv\s*=\s*["']?refresh/i;
|
|
2242
|
+
const NOINDEX_META = /<meta\b[^>]*name\s*=\s*["']?robots["']?[^>]*content\s*=\s*["'][^"']*noindex/i;
|
|
2243
|
+
function isIndexable(html) {
|
|
2244
|
+
return !REFRESH_META.test(html) && !NOINDEX_META.test(html);
|
|
2245
|
+
}
|
|
2137
2246
|
function headIsBound(html, attr) {
|
|
2138
2247
|
if (REFRESH_META.test(html)) return true;
|
|
2139
2248
|
const title = TITLE_TAG.exec(html);
|
|
@@ -2146,6 +2255,8 @@ async function renderSite(cfg, options = {}) {
|
|
|
2146
2255
|
const base = normalizeBase(options.base ?? cfg.render.base);
|
|
2147
2256
|
const baseUrl = (options.baseUrl ?? cfg.render.baseUrl)?.replace(/\/+$/, "");
|
|
2148
2257
|
const wantHreflang = (options.hreflang ?? cfg.render.hreflang ?? true) && baseUrl !== void 0;
|
|
2258
|
+
const patterns = options.exclude ?? cfg.render.exclude ?? [];
|
|
2259
|
+
const excluded = patterns.length > 0 ? picomatch(patterns) : () => false;
|
|
2149
2260
|
const sitemap = options.sitemap ?? cfg.render.sitemap ?? false;
|
|
2150
2261
|
const wantSitemap = sitemap !== false && baseUrl !== void 0;
|
|
2151
2262
|
const clean = options.clean ?? cfg.render.clean ?? false;
|
|
@@ -2179,7 +2290,7 @@ async function renderSite(cfg, options = {}) {
|
|
|
2179
2290
|
const rel = relative(site, file).replace(/\\/g, "/");
|
|
2180
2291
|
if (locales.length > 1 && !headIsBound(html, attribute ?? "data-verbaly")) untranslatedHead.push(rel);
|
|
2181
2292
|
const alternates = wantHreflang ? pageAlternates(baseUrl, rel, locales, cfg.sourceLocale) : [];
|
|
2182
|
-
if (wantHreflang) urls.push({
|
|
2293
|
+
if (wantHreflang && isIndexable(html) && !excluded(rel)) urls.push({
|
|
2183
2294
|
rel,
|
|
2184
2295
|
alternates
|
|
2185
2296
|
});
|