@verbaly/compiler 0.47.0 → 0.48.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/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { basename, dirname, join, relative, resolve } from "node:path";
3
3
  import { parseArgs } from "node:util";
4
4
  import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, watch, writeFileSync } from "node:fs";
5
- import { LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, createVerbaly, flatten, localeDirection, normalizeLink, parse, parseTags, safeAttribute } from "verbaly";
5
+ import { LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, alternateLinks, createVerbaly, flatten, localeDirection, normalizeLink, parse, parseTags, safeAttribute } from "verbaly";
6
6
  import { pathToFileURL } from "node:url";
7
7
  import { glob } from "tinyglobby";
8
8
  import { parse as parse$1 } from "@babel/parser";
@@ -2699,24 +2699,18 @@ function formatRenderWarnings(result, sourceLocale) {
2699
2699
  if (result.untranslatedHead.length > 0) lines.push(` ${counted(result.untranslatedHead.length, "page")} of ${result.files} ship the same <title> in every locale (${result.untranslatedHead[0]}), so search results read in ${sourceLocale}`, ` fix: bind the head too, <title data-verbaly="key"> and a meta through data-verbaly-attr`);
2700
2700
  return lines;
2701
2701
  }
2702
- function pageUrl(baseUrl, prefix, rel) {
2702
+ function pagePath(rel) {
2703
2703
  const path = rel.replace(/(^|\/)index\.html$/, "$1");
2704
- return `${baseUrl}${prefix}${path ? `/${path}` : "/"}`;
2704
+ return path ? `/${path}` : "/";
2705
2705
  }
2706
2706
  function pageAlternates(baseUrl, rel, locales, sourceLocale) {
2707
- const alternates = [];
2708
- for (const locale of locales) {
2709
- const prefix = locale === sourceLocale ? "" : `/${locale}`;
2710
- alternates.push({
2711
- hreflang: locale,
2712
- href: pageUrl(baseUrl, prefix, rel)
2713
- });
2714
- }
2715
- alternates.push({
2716
- hreflang: "x-default",
2717
- href: pageUrl(baseUrl, "", rel)
2707
+ return alternateLinks({
2708
+ supported: locales,
2709
+ sourceLocale,
2710
+ path: pagePath(rel),
2711
+ routing: "prefix-except-source",
2712
+ baseUrl
2718
2713
  });
2719
- return alternates;
2720
2714
  }
2721
2715
  function buildSitemap(urls) {
2722
2716
  return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">${urls.flatMap(({ alternates }) => {