@jjlmoya/utils-tabletop 1.38.0 → 1.40.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/package.json +1 -1
- package/src/components/ProductionBreadcrumb.astro +3 -1
- package/src/components/ProductionStructuredData.astro +46 -0
- package/src/layouts/ProductionPage.astro +10 -1
- package/src/layouts/ProductionUtilityPage.astro +8 -7
- package/src/mfe/assets.ts +24 -0
- package/src/mfe/category-ui.ts +23 -15
- package/src/mfe/manifest.ts +45 -0
- package/src/pages/[locale]/[utilities]/[categories]/[category]/[slug]/manifest.json.ts +49 -0
- package/src/pages/utilidades/[slug]/manifest.json.ts +28 -0
- package/src/tests/category_ui.test.ts +6 -0
- package/src/tests/mfe_manifest.test.ts +28 -0
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
import { Icon } from "astro-icon/components";
|
|
3
3
|
import type { KnownLocale } from "../types";
|
|
4
|
+
import { getCategoryUi } from "../mfe/category-ui";
|
|
4
5
|
import { getUtilitiesPath } from "@jjlmoya/utils-shared/routing";
|
|
5
6
|
|
|
6
7
|
interface Props {
|
|
@@ -30,9 +31,10 @@ const LABELS: Record<KnownLocale, string> = {
|
|
|
30
31
|
|
|
31
32
|
const { locale, categoryTitle, categoryHref, currentTitle } = Astro.props;
|
|
32
33
|
const homeLabel = LABELS[locale];
|
|
34
|
+
const breadcrumbLabel = getCategoryUi(locale).breadcrumb;
|
|
33
35
|
---
|
|
34
36
|
|
|
35
|
-
<nav class="production-breadcrumb" aria-label=
|
|
37
|
+
<nav class="production-breadcrumb" aria-label={breadcrumbLabel}>
|
|
36
38
|
<ol class="production-breadcrumb-list">
|
|
37
39
|
<li class="production-breadcrumb-item">
|
|
38
40
|
<a href={getUtilitiesPath(locale)}>{homeLabel}</a>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { KnownLocale, ToolLocaleContent } from "../types";
|
|
3
|
+
import { TABLETOP_ASSET_VERSION } from "../mfe/assets";
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
locale: KnownLocale;
|
|
7
|
+
content: ToolLocaleContent;
|
|
8
|
+
publicPath: string;
|
|
9
|
+
categoryTitle: string;
|
|
10
|
+
categoryHref: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const { locale, content, publicPath, categoryTitle, categoryHref } = Astro.props;
|
|
14
|
+
const siteOrigin = locale === "es" ? "https://www.jjlmoya.es" : "https://www.gamebob.dev";
|
|
15
|
+
const fullUrl = new URL(publicPath, siteOrigin).href;
|
|
16
|
+
const categoryUrl = new URL(categoryHref, siteOrigin).href;
|
|
17
|
+
const brandName = locale === "es" ? "jjlmoya" : "GameBob";
|
|
18
|
+
const schemas = (content.schemas ?? []).filter((schema) => (schema as unknown as Record<string, unknown>)["@type"] !== "FAQPage");
|
|
19
|
+
const schemaTypes = new Set(schemas.map((schema) => (schema as unknown as Record<string, unknown>)["@type"]));
|
|
20
|
+
const breadcrumbSchema = {
|
|
21
|
+
"@context": "https://schema.org",
|
|
22
|
+
"@type": "BreadcrumbList",
|
|
23
|
+
itemListElement: [
|
|
24
|
+
{ "@type": "ListItem", position: 1, name: brandName, item: `${siteOrigin}/${locale === "es" ? "" : `${locale}/`}` },
|
|
25
|
+
{ "@type": "ListItem", position: 2, name: categoryTitle, item: categoryUrl },
|
|
26
|
+
{ "@type": "ListItem", position: 3, name: content.title, item: fullUrl },
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
const webApplicationSchema = {
|
|
30
|
+
"@context": "https://schema.org",
|
|
31
|
+
"@type": "WebApplication",
|
|
32
|
+
name: content.title,
|
|
33
|
+
description: content.description,
|
|
34
|
+
url: fullUrl,
|
|
35
|
+
applicationCategory: "UtilityApplication",
|
|
36
|
+
operatingSystem: "Any",
|
|
37
|
+
softwareVersion: TABLETOP_ASSET_VERSION,
|
|
38
|
+
author: { "@type": "Person", name: "jjlmoya", url: siteOrigin },
|
|
39
|
+
publisher: { "@type": "Organization", name: brandName, url: siteOrigin },
|
|
40
|
+
inLanguage: locale,
|
|
41
|
+
offers: { "@type": "Offer", price: "0", priceCurrency: "EUR" },
|
|
42
|
+
};
|
|
43
|
+
---
|
|
44
|
+
<script is:inline type="application/ld+json" set:html={JSON.stringify(breadcrumbSchema)} />
|
|
45
|
+
{!schemaTypes.has("WebApplication") && <script is:inline type="application/ld+json" set:html={JSON.stringify(webApplicationSchema)} />}
|
|
46
|
+
{schemas.map((schema) => <script is:inline type="application/ld+json" set:html={JSON.stringify(schema)} />)}
|
|
@@ -12,6 +12,7 @@ import { HEADER_UI } from "../i18n/header-ui";
|
|
|
12
12
|
import { LANGUAGE_LOCALES, LANGUAGE_NAMES, type Language } from "../i18n/languages";
|
|
13
13
|
import { LANGUAGE_UI } from "../i18n/language-ui";
|
|
14
14
|
import { getBrand } from "../identity/brands";
|
|
15
|
+
import { getBrandAssetPath } from "../mfe/assets";
|
|
15
16
|
|
|
16
17
|
interface AlternateLink { language: Language; url: string; }
|
|
17
18
|
interface Props {
|
|
@@ -21,11 +22,15 @@ interface Props {
|
|
|
21
22
|
image?: string | undefined;
|
|
22
23
|
toolCss?: string | undefined;
|
|
23
24
|
publicPath: string;
|
|
25
|
+
manifestPath?: string | undefined;
|
|
24
26
|
alternates: readonly AlternateLink[];
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
const { title, description, locale, image, toolCss, publicPath, alternates } = Astro.props;
|
|
29
|
+
const { title, description, locale, image, toolCss, publicPath, manifestPath, alternates } = Astro.props;
|
|
28
30
|
const brand = getBrand(locale);
|
|
31
|
+
const brandFavicon = getBrandAssetPath(brand, "favicon");
|
|
32
|
+
const brandSizedFavicon = getBrandAssetPath(brand, "faviconSized");
|
|
33
|
+
const brandAppleTouchIcon = getBrandAssetPath(brand, "appleTouchIcon");
|
|
29
34
|
const origin = brand === "jjlmoya" ? "https://www.jjlmoya.es" : "https://www.gamebob.dev";
|
|
30
35
|
const canonical = new URL(publicPath, origin).href;
|
|
31
36
|
const socialImage = image ? new URL(image, canonical).href : undefined;
|
|
@@ -60,6 +65,10 @@ const xDefaultUrl = alternates.find(({ language }) => language === "en")?.url ??
|
|
|
60
65
|
<meta name="author" content="jjlmoya" />
|
|
61
66
|
<meta name="robots" content="index, follow, max-image-preview:large" />
|
|
62
67
|
<meta name="referrer" content="strict-origin-when-cross-origin" />
|
|
68
|
+
<link rel="icon" type="image/x-icon" href={brandFavicon} />
|
|
69
|
+
<link rel="icon" type="image/webp" sizes={brand === "jjlmoya" ? "32x32" : "48x48"} href={brandSizedFavicon} />
|
|
70
|
+
<link rel="apple-touch-icon" href={brandAppleTouchIcon} />
|
|
71
|
+
{manifestPath && <link rel="manifest" href={manifestPath} />}
|
|
63
72
|
<link rel="canonical" href={canonical} />
|
|
64
73
|
{alternates.map(({ language, url }) => <link rel="alternate" hreflang={language} href={absoluteUrl(language, url)} />)}
|
|
65
74
|
<link rel="alternate" hreflang="x-default" href={absoluteUrl("en", xDefaultUrl)} />
|
|
@@ -4,10 +4,11 @@ import { FAQSection, UtilityHeader } from "@jjlmoya/utils-shared";
|
|
|
4
4
|
import { Icon } from "astro-icon/components";
|
|
5
5
|
import ProductionBreadcrumb from "../components/ProductionBreadcrumb.astro";
|
|
6
6
|
import ProductionWidget from "../components/ProductionWidget.astro";
|
|
7
|
+
import ProductionStructuredData from "../components/ProductionStructuredData.astro";
|
|
7
8
|
import type { KnownLocale, ToolLocaleContent } from "../types";
|
|
8
9
|
import { getCategoryUi } from "../mfe/category-ui";
|
|
9
10
|
import { getCategoryPath, getUtilityPath } from "../mfe/routes";
|
|
10
|
-
import { getUtilityCssPath } from "../mfe/assets";
|
|
11
|
+
import { getUtilityCssPath, TABLETOP_ASSET_VERSION } from "../mfe/assets";
|
|
11
12
|
import type { AstroComponentFactory } from "astro/runtime/server/index.js";
|
|
12
13
|
|
|
13
14
|
interface RelatedTool { title: string; description: string; href: string; icon: string; }
|
|
@@ -21,24 +22,24 @@ const publicCategoryPath = getCategoryPath(locale, categorySlug);
|
|
|
21
22
|
const ui = getCategoryUi(locale);
|
|
22
23
|
---
|
|
23
24
|
|
|
24
|
-
<ProductionPage title={content.title} description={content.description} {locale} {publicPath} {alternates} {image} toolCss={getUtilityCssPath(englishSlug)}>
|
|
25
|
+
<ProductionPage title={content.title} description={content.description} {locale} {publicPath} manifestPath={`${publicPath}manifest.json?version=${TABLETOP_ASSET_VERSION}`} {alternates} {image} toolCss={getUtilityCssPath(englishSlug)}>
|
|
25
26
|
<div class="utility-production">
|
|
26
27
|
<div class="utility-production-inner">
|
|
27
28
|
<ProductionBreadcrumb locale={locale} categoryTitle={categoryTitle} categoryHref={categoryHref || publicCategoryPath} currentTitle={content.title} />
|
|
28
29
|
<UtilityHeader titleHighlight={titleHighlight} titleBase={titleBase} description={content.description} gradientFrom="#10b981" gradientTo="#0d9488" />
|
|
29
30
|
<section class="utility-tool-production"><Component ui={content.ui} locale={locale} /></section>
|
|
30
|
-
<div class="utility-zoom-production" aria-label=
|
|
31
|
-
<span class="utility-zoom-label">
|
|
32
|
-
<div class="utility-zoom-controls"><button type="button" data-zoom="out" aria-label=
|
|
31
|
+
<div class="utility-zoom-production" aria-label={ui.zoomControls}>
|
|
32
|
+
<span class="utility-zoom-label">{ui.zoom}</span>
|
|
33
|
+
<div class="utility-zoom-controls"><button type="button" data-zoom="out" aria-label={ui.zoomOut}>−</button><button type="button" data-zoom="reset" aria-label={ui.resetZoom}>100%</button><button type="button" data-zoom="in" aria-label={ui.zoomIn}>+</button></div>
|
|
33
34
|
</div>
|
|
34
35
|
<ProductionWidget locale={locale} slug={content.slug} />
|
|
35
36
|
{content.faq.length > 0 && <section class="utility-section-production"><FAQSection items={content.faq} /></section>}
|
|
36
37
|
<Fragment slot="head">
|
|
37
|
-
{
|
|
38
|
+
<ProductionStructuredData locale={locale} {content} {publicPath} categoryTitle={categoryTitle} categoryHref={categoryHref || publicCategoryPath} />
|
|
38
39
|
</Fragment>
|
|
39
40
|
<section class="utility-section-production"><SEOComponent locale={locale} /></section>
|
|
40
41
|
{content.bibliography.length > 0 && <section class="utility-section-production"><BibliographyComponent locale={locale} /></section>}
|
|
41
|
-
{relatedTools.length > 0 && <section class="utility-related-production" aria-labelledby="related-tools-title"><div class="utility-related-heading"><span class="utility-related-eyebrow">
|
|
42
|
+
{relatedTools.length > 0 && <section class="utility-related-production" aria-labelledby="related-tools-title"><div class="utility-related-heading"><span class="utility-related-eyebrow">{ui.relatedEyebrow}</span><h2 id="related-tools-title">{ui.moreToolsIn} {categoryTitle}</h2></div><div class="utility-related-grid">{relatedTools.map((tool, index) => <a href={tool.href} class="utility-related-card"><span class="utility-related-index">{String(index + 1).padStart(2, "0")}</span><span class="utility-related-icon"><Icon name={tool.icon} /></span><h3>{tool.title}</h3><p>{tool.description}</p><span class="utility-related-cta">{ui.openTool} <Icon name="mdi:arrow-top-right" /></span></a>)}</div></section>}
|
|
42
43
|
</div>
|
|
43
44
|
</div>
|
|
44
45
|
</ProductionPage>
|
package/src/mfe/assets.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import packageMetadata from "../../package.json";
|
|
2
|
+
import type { Brand } from "../identity/brands";
|
|
3
|
+
|
|
4
|
+
const UTILITY_ASSET_ROOT = "/_utilities/tabletop";
|
|
2
5
|
|
|
3
6
|
export const TABLETOP_ASSET_VERSION = encodeURIComponent(
|
|
4
7
|
import.meta.env.PUBLIC_APP_VERSION ?? packageMetadata.version,
|
|
@@ -6,6 +9,27 @@ export const TABLETOP_ASSET_VERSION = encodeURIComponent(
|
|
|
6
9
|
|
|
7
10
|
const withAssetVersion = (path: string): string => `${path}?version=${TABLETOP_ASSET_VERSION}`;
|
|
8
11
|
|
|
12
|
+
export const getUtilityAssetPath = (assetName: string): string =>
|
|
13
|
+
withAssetVersion(`${UTILITY_ASSET_ROOT}/${assetName}`);
|
|
14
|
+
|
|
15
|
+
const BRAND_ASSETS = {
|
|
16
|
+
gamebob: {
|
|
17
|
+
favicon: "favicon.ico",
|
|
18
|
+
faviconSized: "favicon-48.webp",
|
|
19
|
+
appleTouchIcon: "apple-touch-icon-brand.webp",
|
|
20
|
+
},
|
|
21
|
+
jjlmoya: {
|
|
22
|
+
favicon: "favicon-jjlmoya.ico",
|
|
23
|
+
faviconSized: "favicon-jjlmoya-32.webp",
|
|
24
|
+
appleTouchIcon: "apple-touch-icon-jjlmoya.webp",
|
|
25
|
+
},
|
|
26
|
+
} as const satisfies Record<Brand, Record<"favicon" | "faviconSized" | "appleTouchIcon", string>>;
|
|
27
|
+
|
|
28
|
+
export const getBrandAssetPath = (
|
|
29
|
+
brand: Brand,
|
|
30
|
+
asset: keyof (typeof BRAND_ASSETS)[Brand],
|
|
31
|
+
): string => getUtilityAssetPath(BRAND_ASSETS[brand][asset]);
|
|
32
|
+
|
|
9
33
|
export const getUtilityOgImage = (englishSlug: string): string =>
|
|
10
34
|
withAssetVersion(`/_utilities/tabletop/images/${englishSlug}.webp`);
|
|
11
35
|
|
package/src/mfe/category-ui.ts
CHANGED
|
@@ -3,24 +3,32 @@ import type { KnownLocale } from '../types';
|
|
|
3
3
|
export interface CategoryUi {
|
|
4
4
|
useTool: string;
|
|
5
5
|
openTool: string;
|
|
6
|
+
relatedEyebrow: string;
|
|
7
|
+
moreToolsIn: string;
|
|
8
|
+
zoom: string;
|
|
9
|
+
zoomControls: string;
|
|
10
|
+
zoomOut: string;
|
|
11
|
+
resetZoom: string;
|
|
12
|
+
zoomIn: string;
|
|
13
|
+
breadcrumb: string;
|
|
6
14
|
}
|
|
7
15
|
|
|
8
16
|
export const CATEGORY_UI: Record<KnownLocale, CategoryUi> = {
|
|
9
|
-
es: { useTool: 'Usar herramienta', openTool: 'Abrir herramienta' },
|
|
10
|
-
en: { useTool: 'Use tool', openTool: 'Open tool' },
|
|
11
|
-
fr: { useTool: "Utiliser l'outil", openTool: "Ouvrir l'outil" },
|
|
12
|
-
de: { useTool: 'Werkzeug verwenden', openTool: 'Werkzeug öffnen' },
|
|
13
|
-
it: { useTool: 'Usa lo strumento', openTool: 'Apri lo strumento' },
|
|
14
|
-
pt: { useTool: 'Usar ferramenta', openTool: 'Abrir ferramenta' },
|
|
15
|
-
nl: { useTool: 'Tool gebruiken', openTool: 'Tool openen' },
|
|
16
|
-
sv: { useTool: 'Använd verktyget', openTool: 'Öppna verktyget' },
|
|
17
|
-
pl: { useTool: 'Użyj narzędzia', openTool: 'Otwórz narzędzie' },
|
|
18
|
-
id: { useTool: 'Gunakan alat', openTool: 'Buka alat' },
|
|
19
|
-
tr: { useTool: 'Aracı kullan', openTool: 'Aracı aç' },
|
|
20
|
-
ru: { useTool: 'Использовать инструмент', openTool: 'Открыть инструмент' },
|
|
21
|
-
ja: { useTool: 'ツールを使う', openTool: 'ツールを開く' },
|
|
22
|
-
ko: { useTool: '도구 사용', openTool: '도구 열기' },
|
|
23
|
-
zh: { useTool: '使用工具', openTool: '打开工具' },
|
|
17
|
+
es: { useTool: 'Usar herramienta', openTool: 'Abrir herramienta', relatedEyebrow: 'Sigue explorando', moreToolsIn: 'Más herramientas en', zoom: 'Zoom', zoomControls: 'Controles de zoom', zoomOut: 'Reducir zoom', resetZoom: 'Restablecer zoom', zoomIn: 'Aumentar zoom', breadcrumb: 'Migas de pan' },
|
|
18
|
+
en: { useTool: 'Use tool', openTool: 'Open tool', relatedEyebrow: 'Keep exploring', moreToolsIn: 'More tools in', zoom: 'Zoom', zoomControls: 'Zoom controls', zoomOut: 'Zoom out', resetZoom: 'Reset zoom', zoomIn: 'Zoom in', breadcrumb: 'Breadcrumb' },
|
|
19
|
+
fr: { useTool: "Utiliser l'outil", openTool: "Ouvrir l'outil", relatedEyebrow: 'Continuez à explorer', moreToolsIn: "Plus d'outils dans", zoom: 'Zoom', zoomControls: 'Commandes de zoom', zoomOut: 'Réduire le zoom', resetZoom: 'Réinitialiser le zoom', zoomIn: 'Augmenter le zoom', breadcrumb: 'Fil d’Ariane' },
|
|
20
|
+
de: { useTool: 'Werkzeug verwenden', openTool: 'Werkzeug öffnen', relatedEyebrow: 'Mehr entdecken', moreToolsIn: 'Weitere Werkzeuge in', zoom: 'Zoom', zoomControls: 'Zoom-Steuerung', zoomOut: 'Verkleinern', resetZoom: 'Zoom zurücksetzen', zoomIn: 'Vergrößern', breadcrumb: 'Brotkrümelnavigation' },
|
|
21
|
+
it: { useTool: 'Usa lo strumento', openTool: 'Apri lo strumento', relatedEyebrow: 'Continua a esplorare', moreToolsIn: 'Altri strumenti in', zoom: 'Zoom', zoomControls: 'Controlli zoom', zoomOut: 'Riduci zoom', resetZoom: 'Reimposta zoom', zoomIn: 'Aumenta zoom', breadcrumb: 'Breadcrumb' },
|
|
22
|
+
pt: { useTool: 'Usar ferramenta', openTool: 'Abrir ferramenta', relatedEyebrow: 'Continue a explorar', moreToolsIn: 'Mais ferramentas em', zoom: 'Zoom', zoomControls: 'Controlos de zoom', zoomOut: 'Reduzir zoom', resetZoom: 'Repor zoom', zoomIn: 'Aumentar zoom', breadcrumb: 'Trilho de navegação' },
|
|
23
|
+
nl: { useTool: 'Tool gebruiken', openTool: 'Tool openen', relatedEyebrow: 'Blijf ontdekken', moreToolsIn: 'Meer tools in', zoom: 'Zoom', zoomControls: 'Zoomknoppen', zoomOut: 'Uitzoomen', resetZoom: 'Zoom herstellen', zoomIn: 'Inzoomen', breadcrumb: 'Broodkruimelnavigatie' },
|
|
24
|
+
sv: { useTool: 'Använd verktyget', openTool: 'Öppna verktyget', relatedEyebrow: 'Utforska mer', moreToolsIn: 'Fler verktyg i', zoom: 'Zoom', zoomControls: 'Zoomkontroller', zoomOut: 'Zooma ut', resetZoom: 'Återställ zoom', zoomIn: 'Zooma in', breadcrumb: 'Brödsmulenavigering' },
|
|
25
|
+
pl: { useTool: 'Użyj narzędzia', openTool: 'Otwórz narzędzie', relatedEyebrow: 'Odkrywaj dalej', moreToolsIn: 'Więcej narzędzi w', zoom: 'Powiększenie', zoomControls: 'Sterowanie powiększeniem', zoomOut: 'Pomniejsz', resetZoom: 'Resetuj powiększenie', zoomIn: 'Powiększ', breadcrumb: 'Okruszki nawigacji' },
|
|
26
|
+
id: { useTool: 'Gunakan alat', openTool: 'Buka alat', relatedEyebrow: 'Jelajahi lebih lanjut', moreToolsIn: 'Alat lainnya di', zoom: 'Zoom', zoomControls: 'Kontrol zoom', zoomOut: 'Perkecil', resetZoom: 'Atur ulang zoom', zoomIn: 'Perbesar', breadcrumb: 'Breadcrumb' },
|
|
27
|
+
tr: { useTool: 'Aracı kullan', openTool: 'Aracı aç', relatedEyebrow: 'Keşfetmeye devam edin', moreToolsIn: 'Diğer araçlar:', zoom: 'Yakınlaştırma', zoomControls: 'Yakınlaştırma denetimleri', zoomOut: 'Uzaklaştır', resetZoom: 'Yakınlaştırmayı sıfırla', zoomIn: 'Yakınlaştır', breadcrumb: 'İçerik haritası' },
|
|
28
|
+
ru: { useTool: 'Использовать инструмент', openTool: 'Открыть инструмент', relatedEyebrow: 'Продолжить изучение', moreToolsIn: 'Другие инструменты в', zoom: 'Масштаб', zoomControls: 'Управление масштабом', zoomOut: 'Уменьшить', resetZoom: 'Сбросить масштаб', zoomIn: 'Увеличить', breadcrumb: 'Навигационная цепочка' },
|
|
29
|
+
ja: { useTool: 'ツールを使う', openTool: 'ツールを開く', relatedEyebrow: 'さらに探索', moreToolsIn: 'その他のツール:', zoom: 'ズーム', zoomControls: 'ズーム操作', zoomOut: '縮小', resetZoom: 'ズームをリセット', zoomIn: '拡大', breadcrumb: 'パンくずリスト' },
|
|
30
|
+
ko: { useTool: '도구 사용', openTool: '도구 열기', relatedEyebrow: '더 탐색하기', moreToolsIn: '카테고리의 다른 도구:', zoom: '확대/축소', zoomControls: '확대/축소 컨트롤', zoomOut: '축소', resetZoom: '확대/축소 초기화', zoomIn: '확대', breadcrumb: '탐색 경로' },
|
|
31
|
+
zh: { useTool: '使用工具', openTool: '打开工具', relatedEyebrow: '继续探索', moreToolsIn: '更多工具:', zoom: '缩放', zoomControls: '缩放控件', zoomOut: '缩小', resetZoom: '重置缩放', zoomIn: '放大', breadcrumb: '面包屑导航' },
|
|
24
32
|
};
|
|
25
33
|
|
|
26
34
|
export const getCategoryUi = (locale: KnownLocale): CategoryUi => CATEGORY_UI[locale];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { getUtilityOgImage } from "./assets";
|
|
2
|
+
|
|
3
|
+
export interface UtilityManifestInput {
|
|
4
|
+
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
startUrl: string;
|
|
7
|
+
englishSlug: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const buildUtilityManifest = ({
|
|
11
|
+
title,
|
|
12
|
+
description,
|
|
13
|
+
startUrl,
|
|
14
|
+
englishSlug,
|
|
15
|
+
}: UtilityManifestInput) => {
|
|
16
|
+
const shortName = title.length > 12
|
|
17
|
+
? title.split(/\s+/).map((word) => word[0]).join("")
|
|
18
|
+
: title;
|
|
19
|
+
const manifest = {
|
|
20
|
+
name: title,
|
|
21
|
+
short_name: shortName,
|
|
22
|
+
description,
|
|
23
|
+
start_url: startUrl,
|
|
24
|
+
scope: startUrl,
|
|
25
|
+
icons: [{
|
|
26
|
+
src: getUtilityOgImage(englishSlug),
|
|
27
|
+
sizes: "512x512",
|
|
28
|
+
type: "image/webp",
|
|
29
|
+
purpose: "any",
|
|
30
|
+
}],
|
|
31
|
+
theme_color: "#0f172a",
|
|
32
|
+
background_color: "#0f172a",
|
|
33
|
+
display: "standalone",
|
|
34
|
+
orientation: "portrait",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return manifest;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const createUtilityManifestResponse = (input: UtilityManifestInput): Response => new Response(JSON.stringify(buildUtilityManifest(input), null, 2), {
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/manifest+json",
|
|
43
|
+
"Cache-Control": "public, max-age=31536000, immutable",
|
|
44
|
+
},
|
|
45
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { APIRoute } from "astro";
|
|
2
|
+
import { ALL_TOOLS, tabletopCategory } from "../../../../../../index";
|
|
3
|
+
import type { CategoryLocaleContent, ToolLocaleContent } from "../../../../../../types";
|
|
4
|
+
import { LANGUAGE_CODES, type Language } from "../../../../../../i18n/languages";
|
|
5
|
+
import { getCategoryNamespace, getUtilityNamespace, getUtilityPath } from "../../../../../../mfe/routes";
|
|
6
|
+
import { createUtilityManifestResponse, type UtilityManifestInput } from "../../../../../../mfe/manifest";
|
|
7
|
+
|
|
8
|
+
const loadCategories = async () => Object.fromEntries(await Promise.all(LANGUAGE_CODES.map(async (language) => [
|
|
9
|
+
language,
|
|
10
|
+
await tabletopCategory.i18n[language]!(),
|
|
11
|
+
]))) as Record<Language, CategoryLocaleContent>;
|
|
12
|
+
|
|
13
|
+
const loadContents = async (entry: (typeof ALL_TOOLS)[number]["entry"]) => Object.fromEntries(await Promise.all(LANGUAGE_CODES.map(async (language) => {
|
|
14
|
+
const loader = entry.i18n[language] ?? entry.i18n.en;
|
|
15
|
+
if (!loader) throw new Error(`Missing ${language} locale for ${entry.id}`);
|
|
16
|
+
return [language, await loader()];
|
|
17
|
+
}))) as Record<Language, ToolLocaleContent>;
|
|
18
|
+
|
|
19
|
+
const createManifestPath = (locale: Exclude<Language, "es">, category: CategoryLocaleContent, content: ToolLocaleContent, englishContent: ToolLocaleContent) => ({
|
|
20
|
+
params: {
|
|
21
|
+
locale,
|
|
22
|
+
utilities: getUtilityNamespace(locale),
|
|
23
|
+
categories: getCategoryNamespace(locale),
|
|
24
|
+
category: category.slug,
|
|
25
|
+
slug: content.slug,
|
|
26
|
+
},
|
|
27
|
+
props: {
|
|
28
|
+
title: content.title,
|
|
29
|
+
description: content.description,
|
|
30
|
+
startUrl: getUtilityPath(locale, category.slug, content.slug),
|
|
31
|
+
englishSlug: englishContent.slug,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export async function getStaticPaths() {
|
|
36
|
+
const categories = await loadCategories();
|
|
37
|
+
const paths = [];
|
|
38
|
+
for (const { entry } of ALL_TOOLS) {
|
|
39
|
+
const contents = await loadContents(entry);
|
|
40
|
+
for (const locale of LANGUAGE_CODES.filter((candidate) => candidate !== "es")) {
|
|
41
|
+
const content = contents[locale];
|
|
42
|
+
const category = categories[locale];
|
|
43
|
+
paths.push(createManifestPath(locale, category, content, contents.en));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return paths;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const GET: APIRoute = ({ props }) => createUtilityManifestResponse(props as unknown as UtilityManifestInput);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { APIRoute } from "astro";
|
|
2
|
+
import { ALL_TOOLS, tabletopCategory } 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 tabletopCategory.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);
|
|
@@ -7,10 +7,16 @@ describe('category UI translations', () => {
|
|
|
7
7
|
for (const locale of UTILITY_LOCALES) {
|
|
8
8
|
expect(getCategoryUi(locale).useTool.trim()).not.toBe('');
|
|
9
9
|
expect(getCategoryUi(locale).openTool.trim()).not.toBe('');
|
|
10
|
+
expect(getCategoryUi(locale).relatedEyebrow.trim()).not.toBe('');
|
|
11
|
+
expect(getCategoryUi(locale).moreToolsIn.trim()).not.toBe('');
|
|
12
|
+
expect(getCategoryUi(locale).zoomControls.trim()).not.toBe('');
|
|
13
|
+
expect(getCategoryUi(locale).breadcrumb.trim()).not.toBe('');
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
expect(Object.keys(CATEGORY_UI).sort()).toEqual([...UTILITY_LOCALES].sort());
|
|
13
17
|
expect(UTILITY_LOCALES.filter((locale) => locale !== 'en').every((locale) => getCategoryUi(locale).useTool !== 'Use tool')).toBe(true);
|
|
14
18
|
expect(UTILITY_LOCALES.filter((locale) => locale !== 'en').every((locale) => getCategoryUi(locale).openTool !== 'Open tool')).toBe(true);
|
|
19
|
+
expect(UTILITY_LOCALES.filter((locale) => locale !== 'en').every((locale) => getCategoryUi(locale).relatedEyebrow !== 'Keep exploring')).toBe(true);
|
|
20
|
+
expect(UTILITY_LOCALES.filter((locale) => locale !== 'en').every((locale) => getCategoryUi(locale).moreToolsIn !== 'More tools in')).toBe(true);
|
|
15
21
|
});
|
|
16
22
|
});
|
|
@@ -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/tabletop/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/tabletop/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
|
+
});
|