@verbaly/astro 0.74.0 → 0.76.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/README.md CHANGED
@@ -19,6 +19,7 @@ One line in `astro.config` wires everything: the Vite plugin (live extraction, t
19
19
 
20
20
  ```bash
21
21
  pnpm add verbaly @verbaly/astro
22
+ pnpm add -D @verbaly/compiler # the verbaly command: init, extract, check
22
23
  ```
23
24
 
24
25
  ## ⚡ Wire it up
@@ -33,10 +34,11 @@ export default defineConfig({
33
34
  });
34
35
  ```
35
36
 
36
- Locales live in your `verbaly.config` (created by `npx verbaly init`), or inline:
37
+ Locales live in your `verbaly.config` (created by `npx verbaly init`), where `verbaly check` and `extract` read them too:
37
38
 
38
- ```js
39
- integrations: [verbaly({ locales: ['en', 'es', 'pt'] })],
39
+ ```ts
40
+ // verbaly.config.ts, created by npx verbaly init: list your languages, the build and `verbaly check` read them
41
+ export default { sourceLocale: 'en', locales: ['en', 'es', 'pt'] };
40
42
  ```
41
43
 
42
44
  ## ✍️ Write the text in place
@@ -80,6 +82,8 @@ export default {
80
82
 
81
83
  Force it on or off with the integration option: `verbaly({ render: true })`.
82
84
 
85
+ Every url the mirror and `virtual:verbaly` write (hreflang, sitemap, canonical, links and `localePath`) follows Astro's own `trailingSlash`, so with `'never'` the Spanish home is `/es`, never `/es/`. With `<ClientRouter />`, `virtual:verbaly` takes the language of each page before the swap, so a live `bindDom` paints the incoming page in its own language: bind it with `{ root: document }`, since the router replaces the `body`.
86
+
83
87
  ## 📚 Docs
84
88
 
85
89
  Full guide: [verbaly-web.vercel.app/docs/frameworks/astro](https://verbaly-web.vercel.app/docs/frameworks/astro)
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export interface VerbalyAstroOptions extends Omit<ViteVerbalyOptions$1, 'render'
6
6
  }
7
7
  interface AstroConfigLike {
8
8
  root: URL;
9
+ trailingSlash?: 'always' | 'never' | 'ignore';
9
10
  }
10
11
  interface ConfigSetupLike {
11
12
  config: AstroConfigLike;
@@ -14,7 +15,6 @@ interface ConfigSetupLike {
14
15
  plugins?: unknown;
15
16
  };
16
17
  }): unknown;
17
- injectScript(stage: 'page', content: string): void;
18
18
  }
19
19
  interface ConfigDoneLike {
20
20
  buildOutput?: 'static' | 'server';
@@ -36,5 +36,4 @@ export interface VerbalyAstroIntegration {
36
36
  }
37
37
  export default function verbaly(options?: VerbalyAstroOptions): VerbalyAstroIntegration;
38
38
  //#endregion
39
- export type { RenderConfig, VerbalyConfig, ViteVerbalyOptions };
40
- //# sourceMappingURL=index.d.ts.map
39
+ export type { RenderConfig, VerbalyConfig, ViteVerbalyOptions };
package/dist/index.js CHANGED
@@ -3,11 +3,6 @@ import verbalyVite from "@verbaly/vite";
3
3
  import { relative } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  //#region src/index.ts
6
- const ADOPT_SCRIPT = `import { adoptPage } from 'virtual:verbaly';
7
- document.addEventListener('astro:before-swap', (event) => {
8
- adoptPage({ root: event.newDocument, path: event.to.pathname });
9
- });
10
- `;
11
6
  function verbaly(options = {}) {
12
7
  const { render, ...rest } = options;
13
8
  const vite = typeof render === "object" ? {
@@ -19,14 +14,14 @@ function verbaly(options = {}) {
19
14
  return {
20
15
  name: "@verbaly/astro",
21
16
  hooks: {
22
- async "astro:config:setup"({ config, updateConfig, injectScript }) {
17
+ async "astro:config:setup"({ config, updateConfig }) {
23
18
  root = vite.root ??= fileURLToPath(config.root);
19
+ vite.trailingSlash ??= config.trailingSlash;
24
20
  updateConfig({ vite: { plugins: [verbalyVite(vite)] } });
25
- if ((await loadConfig(root, vite)).render.inlineCatalog === true) injectScript("page", ADOPT_SCRIPT);
26
21
  },
27
22
  async "astro:config:done"(options) {
28
23
  buildOutput = options.buildOutput;
29
- const cfg = await loadConfig(root, vite);
24
+ const cfg = await loadConfig(root, vite, { plugin: true });
30
25
  const url = options.injectTypes({
31
26
  filename: "verbaly.d.ts",
32
27
  content: generateDts(loadCatalogs(cfg)[cfg.sourceLocale] ?? {}, {
@@ -37,7 +32,7 @@ function verbaly(options = {}) {
37
32
  vite.dts = fileURLToPath(url);
38
33
  },
39
34
  async "astro:build:done"({ dir }) {
40
- const cfg = await loadConfig(root, vite);
35
+ const cfg = await loadConfig(root, vite, { plugin: true });
41
36
  if (!(render === void 0 ? Object.keys(cfg.render).length > 0 : Boolean(render))) return;
42
37
  if (buildOutput === "server") {
43
38
  console.warn("[verbaly] render skipped: only static output can be mirrored per locale. In server output, build the instance per request: `createRequestInstance(Astro.currentLocale ?? sourceLocale)` from 'virtual:verbaly'");
@@ -53,5 +48,3 @@ function verbaly(options = {}) {
53
48
  }
54
49
  //#endregion
55
50
  export { verbaly as default };
56
-
57
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verbaly/astro",
3
- "version": "0.74.0",
3
+ "version": "0.76.0",
4
4
  "description": "Astro integration for Verbaly: write-in-source extraction for .astro files plus automatic per-locale static rendering.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -41,15 +41,15 @@
41
41
  "access": "public"
42
42
  },
43
43
  "dependencies": {
44
- "@verbaly/compiler": "^0.74.0",
45
- "@verbaly/vite": "^0.74.0"
44
+ "@verbaly/compiler": "^0.76.0",
45
+ "@verbaly/vite": "^0.76.0"
46
46
  },
47
47
  "peerDependencies": {
48
- "verbaly": "^0.74.0"
48
+ "verbaly": "^0.76.0"
49
49
  },
50
50
  "devDependencies": {
51
- "astro": "^7.4.0",
52
- "verbaly": "^0.74.0"
51
+ "astro": "^7.4.2",
52
+ "verbaly": "^0.76.0"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "tsdown",
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n counted,\n generateDts,\n loadCatalogs,\n loadConfig,\n formatRenderWarnings,\n renderSite,\n type RenderConfig,\n} from '@verbaly/compiler';\nimport verbalyVite, { type ViteVerbalyOptions } from '@verbaly/vite';\nimport { relative } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nexport type { RenderConfig, VerbalyConfig } from '@verbaly/compiler';\nexport type { ViteVerbalyOptions } from '@verbaly/vite';\n\nexport interface VerbalyAstroOptions extends Omit<ViteVerbalyOptions, 'render'> {\n render?: boolean | RenderConfig;\n}\n\ninterface AstroConfigLike {\n root: URL;\n}\ninterface ConfigSetupLike {\n config: AstroConfigLike;\n updateConfig(config: { vite?: { plugins?: unknown } }): unknown;\n injectScript(stage: 'page', content: string): void;\n}\ninterface ConfigDoneLike {\n buildOutput?: 'static' | 'server';\n injectTypes(injectedType: { filename: string; content: string }): URL;\n}\ninterface BuildDoneLike {\n dir: URL;\n}\nexport interface VerbalyAstroIntegration {\n name: string;\n hooks: {\n 'astro:config:setup'(options: ConfigSetupLike): Promise<void>;\n 'astro:config:done'(options: ConfigDoneLike): Promise<void>;\n 'astro:build:done'(options: BuildDoneLike): Promise<void>;\n };\n}\n\n// the ClientRouter swaps the document, so each page's own slice has to reach the runtime with it\nconst ADOPT_SCRIPT = `import { adoptPage } from 'virtual:verbaly';\ndocument.addEventListener('astro:before-swap', (event) => {\n adoptPage({ root: event.newDocument, path: event.to.pathname });\n});\n`;\n\nexport default function verbaly(options: VerbalyAstroOptions = {}): VerbalyAstroIntegration {\n const { render, ...rest } = options;\n // one shared mutable options object: config:done fills dts, the plugin reads it lazily\n const vite: ViteVerbalyOptions = typeof render === 'object' ? { ...rest, render } : rest;\n let root = '';\n let buildOutput: 'static' | 'server' | undefined;\n\n return {\n name: '@verbaly/astro',\n hooks: {\n async 'astro:config:setup'({ config, updateConfig, injectScript }) {\n // root pinned to the project dir: Astro's Vite root can differ and discovery finds nothing\n root = vite.root ??= fileURLToPath(config.root);\n updateConfig({ vite: { plugins: [verbalyVite(vite)] } });\n const cfg = await loadConfig(root, vite);\n if (cfg.render.inlineCatalog === true) injectScript('page', ADOPT_SCRIPT);\n },\n async 'astro:config:done'(options) {\n buildOutput = options.buildOutput;\n // types go to Astro's own slot (.astro/), no file in the project\n const cfg = await loadConfig(root, vite);\n const url = options.injectTypes({\n filename: 'verbaly.d.ts',\n // the same options writeDts passes, so the CLI and dev write this very content\n content: generateDts(loadCatalogs(cfg)[cfg.sourceLocale] ?? {}, {\n inlineCatalog: cfg.render.inlineCatalog === true,\n locales: cfg.locales,\n }),\n });\n vite.dts = fileURLToPath(url);\n },\n async 'astro:build:done'({ dir }) {\n const cfg = await loadConfig(root, vite);\n // mirror is opt-in: a path-based i18n routing site must never get its pages mirrored on top\n const wanted = render === undefined ? Object.keys(cfg.render).length > 0 : Boolean(render);\n if (!wanted) return;\n if (buildOutput === 'server') {\n console.warn(\n \"[verbaly] render skipped: only static output can be mirrored per locale. In server output, build the instance per request: `createRequestInstance(Astro.currentLocale ?? sourceLocale)` from 'virtual:verbaly'\",\n );\n return;\n }\n const site = relative(cfg.root, fileURLToPath(dir)) || '.';\n const result = await renderSite(cfg, { site });\n console.log(\n `[verbaly] render: ${counted(result.files, 'page')} × ${counted(result.locales.length, 'locale')} (${result.locales.join(', ')})`,\n );\n for (const line of formatRenderWarnings(result, cfg.sourceLocale)) console.warn(line);\n },\n },\n };\n}\n"],"mappings":";;;;;AA6CA,MAAM,eAAe;;;;;AAMrB,SAAwB,QAAQ,UAA+B,CAAC,GAA4B;CAC1F,MAAM,EAAE,QAAQ,GAAG,SAAS;CAE5B,MAAM,OAA2B,OAAO,WAAW,WAAW;EAAE,GAAG;EAAM;CAAO,IAAI;CACpF,IAAI,OAAO;CACX,IAAI;CAEJ,OAAO;EACL,MAAM;EACN,OAAO;GACL,MAAM,qBAAqB,EAAE,QAAQ,cAAc,gBAAgB;IAEjE,OAAO,KAAK,SAAS,cAAc,OAAO,IAAI;IAC9C,aAAa,EAAE,MAAM,EAAE,SAAS,CAAC,YAAY,IAAI,CAAC,EAAE,EAAE,CAAC;IAEvD,KAAI,MADc,WAAW,MAAM,IAAI,EAAA,CAC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