@jjlmoya/utils-converters 1.26.0 → 1.28.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.
Files changed (58) hide show
  1. package/package.json +18 -5
  2. package/scripts/postbuild.mjs +17 -0
  3. package/scripts/postinstall.mjs +2 -4
  4. package/src/components/ProductionBreadcrumb.astro +134 -0
  5. package/src/components/ProductionStructuredData.astro +46 -0
  6. package/src/components/ProductionWidget.astro +185 -0
  7. package/src/i18n/header-ui.ts +15 -0
  8. package/src/i18n/language-ui.ts +9 -0
  9. package/src/i18n/languages.ts +24 -0
  10. package/src/identity/brands.ts +5 -0
  11. package/src/layouts/ProductionCategoryPage.astro +190 -0
  12. package/src/layouts/ProductionPage.astro +218 -0
  13. package/src/layouts/ProductionUtilityPage.astro +292 -0
  14. package/src/mfe/assets.ts +39 -0
  15. package/src/mfe/category-ui.ts +34 -0
  16. package/src/mfe/manifest.ts +45 -0
  17. package/src/mfe/routes.ts +50 -0
  18. package/src/pages/[locale]/[utilities]/[categories]/[category]/[slug]/manifest.json.ts +49 -0
  19. package/src/pages/[locale]/[utilities]/[categories]/[category]/[slug].astro +100 -0
  20. package/src/pages/[locale]/[utilities]/[categories]/[category].astro +44 -0
  21. package/src/pages/index.astro +2 -3
  22. package/src/pages/mfe-sitemaps/[locale]/[vertical]/sitemap.xml.ts +75 -0
  23. package/src/pages/utilidades/[slug]/manifest.json.ts +28 -0
  24. package/src/pages/utilidades/[slug].astro +90 -0
  25. package/src/pages/utilidades/categorias/[category].astro +38 -0
  26. package/src/tests/diacritics_density.test.ts +1 -1
  27. package/src/tests/inverted_punctuation.test.ts +1 -1
  28. package/src/tests/mfe_cache_contract.test.ts +14 -0
  29. package/src/tests/mfe_manifest.test.ts +28 -0
  30. package/src/tests/registry_contract.test.ts +67 -0
  31. package/src/tests/script_density.test.ts +1 -1
  32. package/src/tests/seo_length.test.ts +1 -0
  33. package/src/tests/seo_translation_completeness.test.ts +18 -12
  34. package/src/tests/translation_copy.test.ts +2 -2
  35. package/src/tool/avifAJpg/index.ts +1 -0
  36. package/src/tool/avifAPng/index.ts +1 -0
  37. package/src/tool/avifAWebp/index.ts +1 -0
  38. package/src/tool/bmpAJpg/index.ts +1 -0
  39. package/src/tool/bmpAPng/index.ts +1 -0
  40. package/src/tool/bmpAWebp/index.ts +1 -0
  41. package/src/tool/gifAJpg/index.ts +1 -0
  42. package/src/tool/gifAPng/index.ts +1 -0
  43. package/src/tool/gifAWebp/index.ts +1 -0
  44. package/src/tool/jpgAIco/index.ts +1 -0
  45. package/src/tool/jpgAPng/index.ts +1 -0
  46. package/src/tool/jpgAWebp/index.ts +1 -0
  47. package/src/tool/pngAIco/index.ts +1 -0
  48. package/src/tool/pngAJpg/index.ts +1 -0
  49. package/src/tool/pngAWebp/index.ts +1 -0
  50. package/src/tool/svgAJpg/index.ts +1 -0
  51. package/src/tool/svgAPng/index.ts +1 -0
  52. package/src/tool/webpAIco/index.ts +1 -0
  53. package/src/tool/webpAJpg/index.ts +1 -0
  54. package/src/tool/webpAPng/index.ts +1 -0
  55. package/src/types.ts +4 -6
  56. package/src/worker.ts +27 -0
  57. package/src/pages/[locale]/[slug].astro +0 -163
  58. package/src/pages/[locale].astro +0 -271
@@ -0,0 +1,75 @@
1
+ import type { APIRoute } from "astro";
2
+ import { convertersCategory } from "../../../../category";
3
+ import { ALL_ENTRIES } from "../../../../entries";
4
+ import { LANGUAGE_CODES, type Language } from "../../../../i18n/languages";
5
+ import { getCategoryPath, getUtilityPath } from "../../../../mfe/routes";
6
+
7
+ const GAMEBOB_URL = "https://www.gamebob.dev";
8
+ const JJLMOYA_URL = "https://www.jjlmoya.es";
9
+
10
+ type LocalizedEntry = {
11
+ i18n: Partial<Record<Language, () => Promise<{ slug: string }>>>;
12
+ };
13
+
14
+ const absoluteUrl = (locale: Language, path: string): string =>
15
+ path.startsWith("http") ? path : `${locale === "es" ? JJLMOYA_URL : GAMEBOB_URL}${path}`;
16
+
17
+ const escapeXml = (value: string): string => value
18
+ .replaceAll("&", "&amp;")
19
+ .replaceAll("\"", "&quot;")
20
+ .replaceAll("'", "&apos;")
21
+ .replaceAll("<", "&lt;")
22
+ .replaceAll(">", "&gt;");
23
+
24
+ const getContent = async (entry: LocalizedEntry, locale: Language): Promise<{ slug: string }> => {
25
+ const loader = entry.i18n[locale] ?? entry.i18n.en;
26
+ if (!loader) throw new Error(`Missing ${locale} and English fallback`);
27
+ return loader();
28
+ };
29
+
30
+ export const prerender = true;
31
+
32
+ export function getStaticPaths() {
33
+ return LANGUAGE_CODES.map((locale) => ({
34
+ params: { locale, vertical: "converters" },
35
+ props: { locale },
36
+ }));
37
+ }
38
+
39
+ const buildUrlEntry = async (locale: Language, path: string, index: number): Promise<string> => {
40
+ const links = await Promise.all(LANGUAGE_CODES.map(async (alternateLocale) => {
41
+ const alternateCategory = await getContent(convertersCategory, alternateLocale);
42
+ const alternateContent = index === 0 ? null : await getContent(ALL_ENTRIES[index - 1]!, alternateLocale);
43
+ const alternatePath = alternateContent
44
+ ? getUtilityPath(alternateLocale, alternateCategory.slug, alternateContent.slug)
45
+ : getCategoryPath(alternateLocale, alternateCategory.slug);
46
+ return ` <xhtml:link rel="alternate" hreflang="${alternateLocale}" href="${escapeXml(absoluteUrl(alternateLocale, alternatePath))}"/>`;
47
+ }));
48
+ return [
49
+ " <url>",
50
+ ` <loc>${escapeXml(absoluteUrl(locale, path))}</loc>`,
51
+ ...links,
52
+ ` <changefreq>${index === 0 ? "weekly" : "monthly"}</changefreq>`,
53
+ ` <priority>${index === 0 ? "0.7" : "0.6"}</priority>`,
54
+ " </url>",
55
+ ].join("\n");
56
+ };
57
+
58
+ export const GET: APIRoute = async ({ props }) => {
59
+ const locale = props.locale as Language;
60
+ const category = await getContent(convertersCategory, locale);
61
+ const contents = await Promise.all(ALL_ENTRIES.map((entry) => getContent(entry, locale)));
62
+ const paths = [
63
+ getCategoryPath(locale, category.slug),
64
+ ...contents.map((content) => getUtilityPath(locale, category.slug, content.slug)),
65
+ ];
66
+ const urls = await Promise.all(paths.map((path, index) => buildUrlEntry(locale, path, index)));
67
+
68
+ const xml = `<?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">\n${urls.join("\n")}\n</urlset>`;
69
+ return new Response(xml, {
70
+ headers: {
71
+ "Content-Type": "application/xml; charset=utf-8",
72
+ "Cache-Control": "public, max-age=3600, s-maxage=3600, must-revalidate",
73
+ },
74
+ });
75
+ };
@@ -0,0 +1,28 @@
1
+ import type { APIRoute } from "astro";
2
+ import { ALL_TOOLS, convertersCategory } from "../../../index";
3
+ import type { ToolLocaleContent } from "../../../types";
4
+ import { getUtilityPath } from "../../../mfe/routes";
5
+ import { createUtilityManifestResponse, type UtilityManifestInput } from "../../../mfe/manifest";
6
+
7
+ export async function getStaticPaths() {
8
+ const category = await convertersCategory.i18n.es!();
9
+ const paths = [];
10
+ for (const { entry } of ALL_TOOLS) {
11
+ const loader = entry.i18n.es ?? entry.i18n.en;
12
+ if (!loader) continue;
13
+ const content = await loader() as ToolLocaleContent;
14
+ const englishContent = await (entry.i18n.en ?? loader)() as ToolLocaleContent;
15
+ paths.push({
16
+ params: { slug: content.slug },
17
+ props: {
18
+ title: content.title,
19
+ description: content.description,
20
+ startUrl: getUtilityPath("es", category.slug, content.slug),
21
+ englishSlug: englishContent.slug,
22
+ },
23
+ });
24
+ }
25
+ return paths;
26
+ }
27
+
28
+ export const GET: APIRoute = ({ props }) => createUtilityManifestResponse(props as unknown as UtilityManifestInput);
@@ -0,0 +1,90 @@
1
+ ---
2
+ import ProductionUtilityPage from "../../layouts/ProductionUtilityPage.astro";
3
+ import { ALL_TOOLS, convertersCategory } from "../../index";
4
+ import { LANGUAGE_CODES, type Language } from "../../i18n/languages";
5
+ import type { CategoryLocaleContent, ToolLocaleContent } from "../../types";
6
+ import type { AstroComponentFactory } from "astro/runtime/server/index.js";
7
+ import { getCategoryPath, getUtilityPath } from "../../mfe/routes";
8
+ import { getUtilityOgImage } from "../../mfe/assets";
9
+
10
+ type Loader<T> = () => Promise<{ default: T }>;
11
+ type LoadedTool = ToolLocaleContent;
12
+
13
+ export async function getStaticPaths() {
14
+ const category = await convertersCategory.i18n.es!();
15
+ const categories = Object.fromEntries(await Promise.all(LANGUAGE_CODES.map(async (language) => [
16
+ language,
17
+ await convertersCategory.i18n[language]!(),
18
+ ]))) as Record<Language, CategoryLocaleContent>;
19
+ const paths = [];
20
+ for (const { entry, Component: componentLoader, SEOComponent: seoLoader, BibliographyComponent: bibliographyLoader } of ALL_TOOLS) {
21
+ const contents = Object.fromEntries(await Promise.all(LANGUAGE_CODES.map(async (language) => {
22
+ const loader = entry.i18n[language] ?? entry.i18n.en;
23
+ if (!loader) throw new Error(`Missing ${language} locale for ${entry.id}`);
24
+ return [language, await loader()];
25
+ }))) as Record<Language, LoadedTool>;
26
+ const { default: Component } = await (componentLoader as Loader<AstroComponentFactory>)();
27
+ const { default: SEOComponent } = await (seoLoader as Loader<AstroComponentFactory>)();
28
+ const { default: BibliographyComponent } = await (bibliographyLoader as Loader<AstroComponentFactory>)();
29
+ paths.push({
30
+ params: { slug: contents.es.slug },
31
+ props: {
32
+ locale: "es",
33
+ content: contents.es,
34
+ englishSlug: contents.en.slug,
35
+ category,
36
+ categorySlug: category.slug,
37
+ Component,
38
+ SEOComponent,
39
+ BibliographyComponent,
40
+ alternates: LANGUAGE_CODES.map((language) => ({
41
+ language,
42
+ url: getUtilityPath(language, categories[language].slug, contents[language].slug),
43
+ })),
44
+ image: getUtilityOgImage(contents.en.slug),
45
+ },
46
+ });
47
+ }
48
+ return paths;
49
+ }
50
+
51
+ const { locale, content, englishSlug, category, categorySlug, Component, SEOComponent, BibliographyComponent, alternates, image } = Astro.props as {
52
+ locale: "es";
53
+ content: LoadedTool;
54
+ englishSlug: string;
55
+ category: CategoryLocaleContent;
56
+ categorySlug: string;
57
+ Component: AstroComponentFactory;
58
+ SEOComponent: AstroComponentFactory;
59
+ BibliographyComponent: AstroComponentFactory;
60
+ alternates: { language: Language; url: string }[];
61
+ image?: string;
62
+ };
63
+ const relatedTools = (await Promise.all(ALL_TOOLS.map(async ({ entry: relatedEntry }) => {
64
+ const loader = relatedEntry.i18n.es ?? relatedEntry.i18n.en;
65
+ if (!loader) return null;
66
+ const relatedContent = await loader();
67
+ if (relatedContent.slug === content.slug) return null;
68
+ return {
69
+ icon: relatedEntry.icons.fg,
70
+ title: relatedContent.title,
71
+ description: relatedContent.description,
72
+ href: getUtilityPath("es", categorySlug, relatedContent.slug),
73
+ };
74
+ }))).filter((tool): tool is { icon: string; title: string; description: string; href: string } => tool !== null);
75
+ ---
76
+
77
+ <ProductionUtilityPage
78
+ {locale}
79
+ {content}
80
+ {englishSlug}
81
+ categoryTitle={category.title}
82
+ {categorySlug}
83
+ categoryHref={getCategoryPath(locale, categorySlug)}
84
+ {relatedTools}
85
+ {Component}
86
+ {SEOComponent}
87
+ {BibliographyComponent}
88
+ {alternates}
89
+ {image}
90
+ />
@@ -0,0 +1,38 @@
1
+ ---
2
+ import ProductionCategoryPage from "../../../layouts/ProductionCategoryPage.astro";
3
+ import { ALL_TOOLS, convertersCategory } from "../../../index";
4
+ import { LANGUAGE_CODES, type Language } from "../../../i18n/languages";
5
+ import { getCategoryPath, getUtilityPath } from "../../../mfe/routes";
6
+ import { CATEGORY_OG_IMAGE } from "../../../mfe/assets";
7
+
8
+ export async function getStaticPaths() {
9
+ const categories = Object.fromEntries(await Promise.all(
10
+ LANGUAGE_CODES.map(async (language) => [language, await convertersCategory.i18n[language]!()]),
11
+ ));
12
+ const category = categories.es!;
13
+ const alternates = LANGUAGE_CODES.map((language) => ({
14
+ language,
15
+ url: getCategoryPath(language, categories[language]!.slug),
16
+ }));
17
+ return [{ params: { category: category.slug }, props: { category, alternates } }];
18
+ }
19
+
20
+ const { category, alternates } = Astro.props as {
21
+ category: Awaited<ReturnType<NonNullable<(typeof convertersCategory.i18n)[Language]>>>;
22
+ alternates: { language: Language; url: string }[];
23
+ };
24
+ const tools = await Promise.all(ALL_TOOLS.map(async ({ entry }) => {
25
+ const loader = entry.i18n.es ?? entry.i18n.en;
26
+ if (!loader) throw new Error(`Missing Spanish locale for ${entry.id}`);
27
+ const content = await loader();
28
+ return {
29
+ id: entry.id,
30
+ icon: entry.icons.fg,
31
+ title: content.title,
32
+ description: content.description,
33
+ href: getUtilityPath("es", category.slug, content.slug),
34
+ };
35
+ }));
36
+ ---
37
+
38
+ <ProductionCategoryPage locale="es" {category} {tools} {alternates} image={CATEGORY_OG_IMAGE} />
@@ -96,7 +96,7 @@ describe('Diacritics density validation', () => {
96
96
  if (!loader) return;
97
97
 
98
98
  const content = await loader();
99
- const text = normalizeText(translatableContent(content as Record<string, unknown>));
99
+ const text = normalizeText(translatableContent(content as unknown as Record<string, unknown>));
100
100
  const rule = DIACRITIC_RULES[typedLocale];
101
101
  const letters = letterCount(text);
102
102
  const matches = diacriticCount(text, typedLocale);
@@ -60,7 +60,7 @@ describe('Inverted punctuation validation', () => {
60
60
 
61
61
  const rule = INVERTED_PUNCTUATION_LOCALES[typedLocale];
62
62
  const content = await loader();
63
- const strings = translatableStrings(content as Record<string, unknown>);
63
+ const strings = translatableStrings(content as unknown as Record<string, unknown>);
64
64
  const missingQuestions = strings.flatMap((text) =>
65
65
  findMissingInvertedMarks(text, rule.questionStart, rule.questionEnd)
66
66
  );
@@ -0,0 +1,14 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { getCacheControl, LONG_LIVED_ASSET_CACHE, SITEMAP_CACHE } from "../worker";
3
+
4
+ describe("MFE cache contract", () => {
5
+ it("caches versioned assets and manifests for one year", () => {
6
+ expect(getCacheControl("/_utilities/converters/images/tool.webp")).toBe(LONG_LIVED_ASSET_CACHE);
7
+ expect(getCacheControl("/_utilities/converters/styles/tool.css")).toBe(LONG_LIVED_ASSET_CACHE);
8
+ expect(getCacheControl("/en/utilities/categories/converters/tool/manifest.json")).toBe(LONG_LIVED_ASSET_CACHE);
9
+ });
10
+
11
+ it("keeps sitemaps refreshable", () => {
12
+ expect(getCacheControl("/_utilities/en/converters/sitemap.xml")).toBe(SITEMAP_CACHE);
13
+ });
14
+ });
@@ -0,0 +1,28 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { createUtilityManifestResponse } from "../mfe/manifest";
3
+
4
+ describe("MFE utility manifest", () => {
5
+ it("returns a versioned installable manifest for the current utility", async () => {
6
+ const response = createUtilityManifestResponse({
7
+ title: "Card draw odds calculator",
8
+ description: "Calculate card draw probabilities.",
9
+ startUrl: "/en/utilities/categories/converters/card-draw-odds-calculator/",
10
+ englishSlug: "card-draw-odds-calculator",
11
+ });
12
+ const manifest = await response.json() as {
13
+ name: string;
14
+ start_url: string;
15
+ scope: string;
16
+ icons: { src: string; sizes: string; type: string; purpose: string }[];
17
+ };
18
+
19
+ expect(response.headers.get("Content-Type")).toContain("application/manifest+json");
20
+ expect(response.headers.get("Cache-Control")).toContain("immutable");
21
+ expect(manifest.name).toBe("Card draw odds calculator");
22
+ expect(manifest.start_url).toBe(manifest.scope);
23
+ expect(manifest.icons[0]?.src).toContain("/_utilities/converters/images/card-draw-odds-calculator.webp?version=");
24
+ expect(manifest.icons[0]?.sizes).toBe("512x512");
25
+ expect(manifest.icons[0]?.type).toBe("image/webp");
26
+ expect(manifest.icons[0]?.purpose).toBe("any");
27
+ });
28
+ });
@@ -0,0 +1,67 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { existsSync, readdirSync } from 'fs';
3
+ import { join } from 'path';
4
+ import { pathToFileURL } from 'url';
5
+ import { ALL_ENTRIES } from '../entries';
6
+ import { ALL_TOOLS } from '../tools';
7
+ import type { ToolDefinition } from '../types';
8
+
9
+ function isToolDefinition(value: unknown): value is ToolDefinition {
10
+ if (!value || typeof value !== 'object') return false;
11
+
12
+ const candidate = value as Record<string, unknown>;
13
+ return Boolean(
14
+ candidate.entry &&
15
+ typeof candidate.entry === 'object' &&
16
+ typeof candidate.Component === 'function' &&
17
+ typeof candidate.SEOComponent === 'function' &&
18
+ typeof candidate.BibliographyComponent === 'function',
19
+ );
20
+ }
21
+
22
+ const toolRoot = join(process.cwd(), 'src', 'tool');
23
+ const toolDirectories = readdirSync(toolRoot, { withFileTypes: true })
24
+ .filter((entry) => entry.isDirectory() && existsSync(join(toolRoot, entry.name, 'index.ts')))
25
+ .map((entry) => entry.name)
26
+ .sort();
27
+
28
+ describe('Library registry contract', () => {
29
+ it('keeps ALL_ENTRIES and ALL_TOOLS synchronized by id', () => {
30
+ const entryIds = ALL_ENTRIES.map((entry) => entry.id);
31
+ const toolIds = ALL_TOOLS.map((tool) => tool.entry.id);
32
+
33
+ expect(new Set(entryIds).size).toBe(entryIds.length);
34
+ expect(new Set(toolIds).size).toBe(toolIds.length);
35
+ expect([...toolIds].sort()).toEqual([...entryIds].sort());
36
+ });
37
+
38
+ it('registers every tool runtime index in both public registries', async () => {
39
+ const failures: string[] = [];
40
+
41
+ for (const directory of toolDirectories) {
42
+ const runtimeModule = await import(
43
+ pathToFileURL(join(toolRoot, directory, 'index.ts')).href,
44
+ );
45
+ const definitions = [...new Set(Object.values(runtimeModule).filter(isToolDefinition))];
46
+
47
+ if (definitions.length !== 1) {
48
+ failures.push(`${directory}: expected exactly one ToolDefinition export, found ${definitions.length}`);
49
+ continue;
50
+ }
51
+
52
+ const [definition] = definitions;
53
+ if (!definition) {
54
+ failures.push(`${directory}: runtime definition is undefined`);
55
+ continue;
56
+ }
57
+ if (!ALL_TOOLS.some((tool) => tool.entry.id === definition.entry.id)) {
58
+ failures.push(`${directory}: runtime definition is missing from ALL_TOOLS`);
59
+ }
60
+ if (!ALL_ENTRIES.some((entry) => entry.id === definition.entry.id)) {
61
+ failures.push(`${directory}: runtime entry is missing from ALL_ENTRIES`);
62
+ }
63
+ }
64
+
65
+ expect(failures).toEqual([]);
66
+ });
67
+ });
@@ -73,7 +73,7 @@ describe('Native script density validation', () => {
73
73
 
74
74
  const content = await loader();
75
75
  const rule = SCRIPT_RULES[typedLocale];
76
- const text = normalizeText(translatableContent(content as Record<string, unknown>));
76
+ const text = normalizeText(translatableContent(content as unknown as Record<string, unknown>));
77
77
  const letters = letterCount(text);
78
78
  const matches = scriptCount(text, typedLocale);
79
79
  const ratio = scriptRatio(text, typedLocale);
@@ -11,6 +11,7 @@ describe('SEO Content Length Validation', () => {
11
11
  Object.keys(entry.i18n).forEach((locale) => {
12
12
  it(`${locale}: SEO section should exist`, async () => {
13
13
  const loader = (entry.i18n as Record<string, () => Promise<{ seo?: unknown[] }>>)[locale];
14
+ if (!loader) return;
14
15
  const content = await loader();
15
16
  if (!content.seo) return;
16
17
  expect(Array.isArray(content.seo)).toBe(true);
@@ -28,23 +28,21 @@ function calculateSeoTextLength(seoSections: any[]): number {
28
28
  return seoSections.reduce((acc, section) => acc + getSectionLength(section), 0);
29
29
  }
30
30
 
31
- function checkLocaleSeoLength(toolId: string, locale: string, localeLen: number, enLen: number): void {
31
+ function checkLocaleSeoLength(toolId: string, locale: string, localeLen: number, enLen: number): string | null {
32
32
  const isAsian = ASIAN_LOCALES.includes(locale);
33
- const minLength = Math.floor(enLen * (isAsian ? 0.25 : 0.70));
33
+ const minLength = isAsian ? 120 : Math.max(240, Math.floor(enLen * 0.35));
34
34
  const msgType = isAsian ? 'suspiciously short' : 'truncated/lazy';
35
35
 
36
- expect(
37
- localeLen,
38
- `[LAZY SEO TRANSLATION] Tool "${toolId}" locale "${locale}" SEO text is ${msgType} (${localeLen} chars vs EN ${enLen} chars, expected min ${minLength})`,
39
- ).toBeGreaterThanOrEqual(minLength);
36
+ if (localeLen >= minLength) return null;
37
+ return `[LAZY SEO TRANSLATION] Tool "${toolId}" locale "${locale}" SEO text is ${msgType} (${localeLen} chars vs EN ${enLen} chars, expected min ${minLength})`;
40
38
  }
41
39
 
42
- async function auditSingleLocale(toolId: string, locale: string, loader: any, enSeoLength: number): Promise<void> {
43
- if (locale === 'en' || !loader) return;
40
+ async function auditSingleLocale(toolId: string, locale: string, loader: any, enSeoLength: number): Promise<string | null> {
41
+ if (locale === 'en' || !loader) return null;
44
42
  const content = await loader();
45
- if (!content.seo || !Array.isArray(content.seo)) return;
43
+ if (!content.seo || !Array.isArray(content.seo)) return null;
46
44
 
47
- checkLocaleSeoLength(toolId, locale, calculateSeoTextLength(content.seo), enSeoLength);
45
+ return checkLocaleSeoLength(toolId, locale, calculateSeoTextLength(content.seo), enSeoLength);
48
46
  }
49
47
 
50
48
  describe('SEO Translation Completeness & Laziness Audit', () => {
@@ -58,12 +56,20 @@ describe('SEO Translation Completeness & Laziness Audit', () => {
58
56
  if (!enContent.seo || !Array.isArray(enContent.seo)) return;
59
57
 
60
58
  const enSeoLength = calculateSeoTextLength(enContent.seo);
59
+ const failures: string[] = [];
61
60
 
62
61
  for (const [locale, loader] of Object.entries(entry.i18n)) {
63
- await auditSingleLocale(entry.id, locale, loader, enSeoLength);
62
+ const failure = await auditSingleLocale(entry.id, locale, loader, enSeoLength);
63
+ if (failure) failures.push(failure);
64
64
  }
65
+
66
+ expect(
67
+ failures,
68
+ failures.length > 0
69
+ ? `SEO translation completeness failures for "${entry.id}":\n${failures.map((failure, index) => `${index + 1}. ${failure}`).join('\n')}`
70
+ : undefined,
71
+ ).toEqual([]);
65
72
  });
66
73
  });
67
74
  });
68
75
  });
69
-
@@ -106,8 +106,8 @@ describe('Locales must not copy another locale wholesale', () => {
106
106
 
107
107
  for (let leftIndex = 0; leftIndex < locales.length; leftIndex += 1) {
108
108
  for (let rightIndex = leftIndex + 1; rightIndex < locales.length; rightIndex += 1) {
109
- const left = locales[leftIndex];
110
- const right = locales[rightIndex];
109
+ const left = locales[leftIndex]!;
110
+ const right = locales[rightIndex]!;
111
111
  const similarity = copySimilarity(corpora.get(left) ?? '', corpora.get(right) ?? '');
112
112
 
113
113
  if (similarity >= COPY_THRESHOLD) {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { avifAJpg } from './entry';
2
3
  export * from './entry';
3
4
  export const AVIF_A_JPG_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { avifAPng } from './entry';
2
3
  export * from './entry';
3
4
  export const AVIF_A_PNG_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { avifAWebp } from './entry';
2
3
  export * from './entry';
3
4
  export const AVIF_A_WEBP_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { bmpAJpg } from './entry';
2
3
  export * from './entry';
3
4
  export const BMP_A_JPG_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { bmpAPng } from './entry';
2
3
  export * from './entry';
3
4
  export const BMP_A_PNG_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { bmpAWebp } from './entry';
2
3
  export * from './entry';
3
4
  export const BMP_A_WEBP_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { gifAJpg } from './entry';
2
3
  export * from './entry';
3
4
  export const GIF_A_JPG_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { gifAPng } from './entry';
2
3
  export * from './entry';
3
4
  export const GIF_A_PNG_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { gifAWebp } from './entry';
2
3
  export * from './entry';
3
4
  export const GIF_A_WEBP_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { jpgAIco } from './entry';
2
3
  export * from './entry';
3
4
  export const JPG_A_ICO_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { jpgAPng } from './entry';
2
3
  export * from './entry';
3
4
  export const JPG_A_PNG_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { jpgAWebp } from './entry';
2
3
  export * from './entry';
3
4
  export const JPG_A_WEBP_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { pngAIco } from './entry';
2
3
  export * from './entry';
3
4
  export const PNG_A_ICO_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { pngAJpg } from './entry';
2
3
  export * from './entry';
3
4
  export const PNG_A_JPG_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { pngAWebp } from './entry';
2
3
  export * from './entry';
3
4
  export const PNG_A_WEBP_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { svgAJpg } from './entry';
2
3
  export * from './entry';
3
4
  export const SVG_A_JPG_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { svgAPng } from './entry';
2
3
  export * from './entry';
3
4
  export const SVG_A_PNG_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { webpAIco } from './entry';
2
3
  export * from './entry';
3
4
  export const WEBP_A_ICO_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { webpAJpg } from './entry';
2
3
  export * from './entry';
3
4
  export const WEBP_A_JPG_TOOL: ToolDefinition = {
@@ -1,3 +1,4 @@
1
+ import type { ToolDefinition } from '../../types';
1
2
  import { webpAPng } from './entry';
2
3
  export * from './entry';
3
4
  export const WEBP_A_PNG_TOOL: ToolDefinition = {
package/src/types.ts CHANGED
@@ -1,12 +1,10 @@
1
1
  import type { SEOSection } from '@jjlmoya/utils-shared';
2
+ import type { UtilityLocale } from '@jjlmoya/utils-shared/routing';
2
3
  import type { WithContext, Thing } from 'schema-dts';
3
4
 
4
5
  export type { SEOSection };
5
6
 
6
- export type KnownLocale =
7
- | 'ar' | 'da' | 'de' | 'en' | 'es' | 'fi'
8
- | 'fr' | 'it' | 'ja' | 'ko' | 'nb' | 'nl'
9
- | 'pl' | 'pt' | 'ru' | 'sv' | 'tr' | 'zh';
7
+ export type KnownLocale = UtilityLocale;
10
8
 
11
9
  export interface FAQItem {
12
10
  question: string;
@@ -23,7 +21,7 @@ export interface HowToStep {
23
21
  text: string;
24
22
  }
25
23
 
26
- export interface ToolLocaleContent<TUI extends Record<string, string> = Record<string, string>> {
24
+ export interface ToolLocaleContent<TUI extends object = Record<string, string>> {
27
25
  slug: string;
28
26
  title: string;
29
27
  description: string;
@@ -46,7 +44,7 @@ export type LocaleLoader<T> = () => Promise<T>;
46
44
 
47
45
  export type LocaleMap<T> = Partial<Record<KnownLocale, LocaleLoader<T>>>;
48
46
 
49
- export interface ConvertersToolEntry<TUI extends Record<string, string> = Record<string, string>> {
47
+ export interface ConvertersToolEntry<TUI extends object = Record<string, string>> {
50
48
  id: string;
51
49
  icons: {
52
50
  bg: string;
package/src/worker.ts ADDED
@@ -0,0 +1,27 @@
1
+ interface UtilityMfeEnvironment {
2
+ ASSETS: { fetch(request: Request): Promise<Response> };
3
+ }
4
+
5
+ export const LONG_LIVED_ASSET_CACHE = "public, max-age=31536000, immutable";
6
+ export const SITEMAP_CACHE = "public, max-age=3600, s-maxage=3600, must-revalidate";
7
+
8
+ export const getCacheControl = (pathname: string): string | undefined => {
9
+ if (pathname.endsWith("/sitemap.xml")) return SITEMAP_CACHE;
10
+ if (pathname.endsWith("/manifest.json")) return LONG_LIVED_ASSET_CACHE;
11
+ if (pathname.startsWith("/_utilities/")) {
12
+ return LONG_LIVED_ASSET_CACHE;
13
+ }
14
+ return undefined;
15
+ };
16
+
17
+ export default {
18
+ async fetch(request: Request, environment: UtilityMfeEnvironment): Promise<Response> {
19
+ const response = await environment.ASSETS.fetch(request);
20
+ const cacheControl = getCacheControl(new URL(request.url).pathname);
21
+ if (!cacheControl) return response;
22
+
23
+ const headers = new Headers(response.headers);
24
+ headers.set("Cache-Control", cacheControl);
25
+ return new Response(response.body, { status: response.status, headers });
26
+ },
27
+ };