From 870bfd1051bb1da47651d9fa0593af9c13c07c09 Mon Sep 17 00:00:00 2001 From: pcodedynamics Date: Tue, 1 Dec 2026 01:44:21 +0700 Subject: [PATCH] feat(i18n): add English landing and download pages --- scripts/check_seo.py | 70 ++++- src/components/DesktopPlatform.astro | 151 +++++++---- src/components/HomeExperience.astro | 313 +++++++++++----------- src/components/MicrosoftStoreButton.astro | 9 +- src/components/MobilePlatform.astro | 213 ++++++++------- src/components/PlatformLinks.astro | 18 +- src/components/StoreDownloadButton.astro | 15 +- src/components/layout/Footer.astro | 65 +++-- src/components/layout/Header.astro | 97 +++++-- src/components/seo/SeoHead.astro | 23 +- src/layouts/BaseLayout.astro | 20 +- src/lib/desktop.ts | 158 +++++++++++ src/lib/home-copy.ts | 266 ++++++++++++++++++ src/lib/locales.ts | 29 ++ src/lib/mobile.ts | 90 +++++++ src/lib/seo.ts | 51 +++- src/pages/en/[platform].astro | 20 ++ src/pages/en/index.astro | 19 ++ src/pages/index.astro | 6 +- 19 files changed, 1242 insertions(+), 391 deletions(-) create mode 100644 src/lib/home-copy.ts create mode 100644 src/lib/locales.ts create mode 100644 src/lib/mobile.ts create mode 100644 src/pages/en/[platform].astro create mode 100644 src/pages/en/index.astro diff --git a/scripts/check_seo.py b/scripts/check_seo.py index aea3dc3..0d2512d 100644 --- a/scripts/check_seo.py +++ b/scripts/check_seo.py @@ -8,6 +8,9 @@ ROOT = Path(__file__).resolve().parents[1] DIST = ROOT / "dist" SITE = "https://funput.app" +PLATFORMS = ("macos", "windows", "linux", "ios", "android") +LANDING_ROUTES = ("/", *(f"/{platform}/" for platform in PLATFORMS)) +ENGLISH_ROUTES = {f"/en{route}" for route in LANDING_ROUTES} class Page(HTMLParser): @@ -16,7 +19,9 @@ def __init__(self, path): self.path = path self.meta = {} self.canonicals = [] + self.alternates = {} self.links = [] + self.language_links = set() self.ids = set() self.h1 = 0 self.titles = [] @@ -41,8 +46,14 @@ def handle_starttag(self, tag, attrs): self.meta[key] = attrs.get("content", "") if tag == "link" and attrs.get("rel") == "canonical": self.canonicals.append(attrs.get("href")) + if tag == "link" and attrs.get("rel") == "alternate" and attrs.get("hreflang"): + language = attrs["hreflang"] + assert language not in self.alternates, f"Duplicate alternate {language}: {self.path}" + self.alternates[language] = attrs.get("href") if tag == "a" and attrs.get("href"): self.links.append(attrs["href"]) + if attrs.get("hreflang") == attrs.get("lang") and attrs.get("lang"): + self.language_links.add((attrs["lang"], attrs["href"])) if tag == "title" or (tag == "script" and attrs.get("type") == "application/ld+json"): self.capture = tag self.buffer = "" @@ -67,6 +78,8 @@ def handle_endtag(self, tag): route = "/" + relative.removesuffix("index.html") if relative.endswith("index.html") else "/" + relative pages[route] = Page(path) +assert {route for route in pages if route.startswith("/en/")} == ENGLISH_ROUTES + index = ET.parse(DIST / "sitemap-index.xml") ns = {"s": "http://www.sitemaps.org/schemas/sitemap/0.9"} sitemap_urls = set() @@ -76,12 +89,16 @@ def handle_endtag(self, tag): titles = set() for route, page in pages.items(): - assert page.lang == "vi", f"Missing Vietnamese lang: {route}" + language = "en" if route in ENGLISH_ROUTES else "vi" + assert page.lang == language, f"Wrong document language: {route}" + assert page.meta["og:locale"] == ("en_US" if language == "en" else "vi_VN"), route assert page.h1 == 1, f"Expected one h1: {route}" assert len(page.titles) == 1 and page.titles[0], f"Missing/duplicate title: {route}" assert page.titles[0] not in titles, f"Duplicate title across pages: {route}" titles.add(page.titles[0]) assert page.meta.get("description"), f"Missing description: {route}" + if route not in LANDING_ROUTES and route not in ENGLISH_ROUTES: + assert not page.alternates, f"Unexpected language alternates: {route}" if route == "/404.html": assert "noindex" in page.meta["robots"] assert not page.canonicals @@ -98,7 +115,12 @@ def handle_endtag(self, tag): image = urlsplit(page.meta["og:image"]) if image.netloc == "funput.app": assert (DIST / image.path.lstrip("/")).is_file(), f"Missing OG image: {route}" - assert any(node["@type"] in ("WebPage", "CollectionPage") for node in page.schemas) + webpage = next(node for node in page.schemas if node["@type"] in ("WebPage", "CollectionPage")) + assert webpage["@id"] == f"{expected}#webpage" and webpage["url"] == expected, route + assert webpage["inLanguage"] == language, route + assert webpage["description"] == page.meta["description"], route + if route in LANDING_ROUTES or route in ENGLISH_ROUTES: + assert webpage["name"] == page.titles[0], route for href in page.links: url = urlsplit(href) if url.scheme in ("mailto", "tel") or (url.netloc and url.netloc != "funput.app"): @@ -111,6 +133,23 @@ def handle_endtag(self, tag): if url.fragment: assert unquote(url.fragment) in pages[target].ids, f"Broken anchor: {route} -> {href}" +# The language switch and search alternates must point to the matching page in each language. +for vi_route in LANDING_ROUTES: + en_route = f"/en{vi_route}" + vi_page, en_page = pages[vi_route], pages[en_route] + alternates = {"vi": SITE + vi_route, "en": SITE + en_route, "x-default": SITE + vi_route} + assert vi_page.alternates == en_page.alternates == alternates, vi_route + assert vi_page.meta["og:locale:alternate"] == "en_US", vi_route + assert en_page.meta["og:locale:alternate"] == "vi_VN", en_route + assert vi_page.meta["description"] != en_page.meta["description"], en_route + assert ("en", en_route) in vi_page.language_links, vi_route + assert ("vi", vi_route) in en_page.language_links, en_route + +for home in ("/", "/en/"): + assert {"experience", "platforms"} <= pages[home].ids, home + for platform in PLATFORMS: + assert f"{home}{platform}/" in pages[home].links, home + # Published articles must be discoverable and have complete article metadata. llms = (DIST / "llms.txt").read_text() for route, page in pages.items(): @@ -135,6 +174,7 @@ def handle_endtag(self, tag): assert app["downloadUrl"] == app["installUrl"] == store assert app["offers"]["url"] == store assert store in page.links + assert store in pages["/en/"].links assert app["@id"] == f"{SITE}/{platform}/#app" home_app = next(node for node in pages["/"].schemas if node.get("@id") == app["@id"]) assert home_app == app, f"App identity differs across pages: {platform}" @@ -148,10 +188,10 @@ def handle_endtag(self, tag): assert windows_app["identifier"] == "9NR3WL5PD4ZS" assert windows_store in windows_app["sameAs"] assert "Microsoft Store" in windows_page.meta["description"] -for route in ("/", "/windows/", "/blog/cai-funput-windows-10-11/", "/blog/funput-la-gi/"): +for route in ("/", "/en/", "/windows/", "/en/windows/", "/blog/cai-funput-windows-10-11/", "/blog/funput-la-gi/"): assert windows_store in pages[route].links, f"Missing Microsoft Store link: {route}" assert windows_store in (DIST / "llms.txt").read_text() -for platform in ("macos", "windows", "linux", "ios", "android"): +for platform in PLATFORMS: page = pages[f"/{platform}/"] app_id = f"{SITE}/{platform}/#app" app = next(node for node in page.schemas if node.get("@id") == app_id) @@ -162,17 +202,31 @@ def handle_endtag(self, tag): assert (DIST / urlsplit(app["screenshot"]).path.lstrip("/")).is_file() assert f"/{platform}/" in pages["/"].links assert f"{SITE}/{platform}/" in (DIST / "llms.txt").read_text() - for other in ("macos", "windows", "linux", "ios", "android"): + english_route = f"/en/{platform}/" + english_page = pages[english_route] + english_app = next(node for node in english_page.schemas if node.get("@id") == app_id) + assert english_app == app == next(node for node in pages["/en/"].schemas if node.get("@id") == app_id) + english_webpage = next(node for node in english_page.schemas if node["@type"] == "WebPage") + assert english_webpage["mainEntity"]["@id"] == app_id + breadcrumb = next(node for node in english_page.schemas if node["@type"] == "BreadcrumbList") + assert [item["item"] for item in breadcrumb["itemListElement"]] == [SITE + "/en/", SITE + english_route] + assert "/en/#platforms" in english_page.links, english_route + for other in PLATFORMS: if other != platform: assert f"/{other}/" in page.links + assert f"/en/{other}/" in english_page.links, english_route if platform not in stores: assert app["@type"] == "SoftwareApplication" assert app["softwareRequirements"] and app["operatingSystem"] assert app["installUrl"] in page.links assert app["downloadUrl"] in page.links assert app["offers"]["price"] == "0" -assert len({pages[f"/{p}/"].meta["description"] for p in ("macos", "windows", "linux", "ios", "android")}) == 5 -assert pages["/ios/"].meta["apple-itunes-app"] == "app-id=6788829996" + else: + assert stores[platform] in english_page.links, english_route +for home in ("/", "/en/"): + assert len({pages[f"{home}{platform}/"].meta["description"] for platform in PLATFORMS}) == len(PLATFORMS) + assert pages[f"{home}ios/"].meta["apple-itunes-app"] == "app-id=6788829996" +assert "https://docs.funput.app/en/docs/install/linux/" in pages["/en/linux/"].links assert not any(node["@type"] == "FAQPage" for page in pages.values() for node in page.schemas) assert not any("welcome" in url or "design-verification" in url for url in sitemap_urls) -print(f"SEO OK: {len(pages)} HTML pages, {len(sitemap_urls)} sitemap URLs; canonical, metadata, JSON-LD, internal links, app stores and robots verified.") +print(f"SEO OK: {len(pages)} HTML pages, {len(sitemap_urls)} sitemap URLs; canonical, language alternates, metadata, JSON-LD, internal links, app stores and robots verified.") diff --git a/src/components/DesktopPlatform.astro b/src/components/DesktopPlatform.astro index 63e4aec..9a0df98 100644 --- a/src/components/DesktopPlatform.astro +++ b/src/components/DesktopPlatform.astro @@ -3,61 +3,84 @@ import BaseLayout from '../layouts/BaseLayout.astro'; import PlatformLinks from './PlatformLinks.astro'; import MicrosoftStoreButton from './MicrosoftStoreButton.astro'; import { PLATFORMS } from '../lib/platforms'; -import { DESKTOP } from '../lib/desktop'; +import { DESKTOP, DESKTOP_EN } from '../lib/desktop'; import { platformPageJsonLd } from '../lib/seo'; import { FUNPUT_CONSTANTS as links } from '../lib/constants'; +import { + localizedInstallDocs, + localizedLandingAlternates, + localizedLandingPath, + type Locale, +} from '../lib/locales'; interface Props { id: keyof typeof DESKTOP; + locale?: Locale; } -const { id } = Astro.props; -const content = DESKTOP[id]; +const { id, locale = 'vi' } = Astro.props; +const en = locale === 'en'; +const content = (en ? DESKTOP_EN : DESKTOP)[id]; const platform = PLATFORMS.find((p) => p.id === id)!; -const docs = `${links.INSTALL_DOCS_URL}${id}/`; +const docs = localizedInstallDocs(locale, id); +const downloadHref = id === 'linux' ? docs : platform.ctaHref; +const downloadLabel = en + ? id === 'linux' + ? 'View the Linux installation guide' + : 'Download for Mac on GitHub' + : platform.ctaLabel; ---
- - ← Tất cả nền tảng + + {en ? '← All platforms' : '← Tất cả nền tảng'} -
+

FUNPUT / {platform.name}

{id === 'windows' && (

- Đã có trên Microsoft Store + {' '} + {en ? 'Available on the Microsoft Store' : 'Đã có trên Microsoft Store'}

)}

{content.headline}
{content.accent} - Bộ gõ tiếng Việt cho {platform.name} + {!en && Bộ gõ tiếng Việt cho {platform.name}}

{content.lead}

{id === 'windows' ? ( ) : ( - - {platform.ctaLabel} + + {downloadLabel} )} -

Miễn phí | Mã nguồn mở | Telex & VNI

+

+ {en ? 'Free | Open source | Telex & VNI' : 'Miễn phí | Mã nguồn mở | Telex & VNI'} +

- GÕ LÀ FUN, INPUT LÀ CHUẨN + {en ? 'FUNPUT SETTINGS' : 'GÕ LÀ FUN, INPUT LÀ CHUẨN'}
{platform.screenshotAlt}
- {id === 'windows' - ? 'Thiết kế riêng cho Windows. Tải miễn phí trên Microsoft Store.' - : `Thiết kế riêng cho ${platform.name}. Quen ngay từ lần gõ đầu.`} + {en + ? `Funput on ${platform.name}, with the interface shown in Vietnamese.` + : id === 'windows' + ? 'Thiết kế riêng cho Windows. Tải miễn phí trên Microsoft Store.' + : `Thiết kế riêng cho ${platform.name}. Quen ngay từ lần gõ đầu.`}
-
-

DÀNH CHO MÁY CỦA BẠN

+
+

{en ? 'SYSTEM REQUIREMENTS' : 'DÀNH CHO MÁY CỦA BẠN'}

{content.os}

{content.requirements}

-
+
{content.features.map(([title, body], i) => (
0{i + 1} @@ -93,16 +123,26 @@ const docs = `${links.INSTALL_DOCS_URL}${id}/`;
-

BẮT ĐẦU CÙNG FUNPUT

+

{en ? 'GETTING STARTED' : 'BẮT ĐẦU CÙNG FUNPUT'}

- Cài một lần. -
- Gõ vui mỗi ngày. + {en ? ( + 'Install and start typing.' + ) : ( + <> + Cài một lần. +
+ Gõ vui mỗi ngày. + + )}

- Hướng dẫn cài đặt {platform.name} ↗ + + {en ? `${platform.name} installation guide` : `Hướng dẫn cài đặt ${platform.name}`} ↗ + {id === 'windows' && ( )}
@@ -116,7 +156,9 @@ const docs = `${links.INSTALL_DOCS_URL}${id}/`;
-

Về Funput cho {platform.name}

+

+ {en ? `Questions about Funput for ${platform.name}` : `Về Funput cho ${platform.name}`} +

{content.questions.map(([q, a]) => (
@@ -126,26 +168,45 @@ const docs = `${links.INSTALL_DOCS_URL}${id}/`;

{a}

))} -

- Funput là bộ gõ tiếng Việt miễn phí, phát hành theo giấy phép MIT.{' '} - {id === 'windows' && ( - <> - Tải trên Microsoft Store,{' '} - - )} - Các bản phát hành,{' '} - xem mã nguồn hoặc đọc{' '} - chính sách quyền riêng tư. -

+ {en ? ( +

+ Funput is free and open source under the MIT license. Find it on{' '} + {id === 'windows' && ( + <> + the Microsoft Store or{' '} + + )} + GitHub Releases. You can also{' '} + browse the source code or read the{' '} + + privacy policy (Vietnamese) + + . +

+ ) : ( +

+ Funput là bộ gõ tiếng Việt miễn phí, phát hành theo giấy phép MIT.{' '} + {id === 'windows' && ( + <> + Tải trên Microsoft Store,{' '} + + )} + Các bản phát hành,{' '} + xem mã nguồn hoặc đọc{' '} + chính sách quyền riêng tư. +

+ )}
{id === 'windows' && (

- - Đọc hướng dẫn cài Funput trên Windows 10/11 và xử lý lỗi thường gặp → + + {en + ? 'Troubleshoot Funput on Windows →' + : 'Đọc hướng dẫn cài Funput trên Windows 10/11 và xử lý lỗi thường gặp →'}

)} - +