fix(site): consolidate homepage search signals

This commit is contained in:
Hakan Seven committed 2026-09-09 21:58:38 +03:00
1 parent f69f0b32be
commit cf70d60944
3 files changed
+27 -8

No files matched your search

+16 -5
View File
@@ -18,6 +18,10 @@ def locale_path(locale):
return f"/{locale}/"
def public_path(locale):
return "/" if locale == "en-US" else locale_path(locale)
def load_catalogs():
catalogs = {p.stem: json.loads(p.read_text()) for p in sorted((ROOT / "site/locales").glob("*.json"))}
supported = {p.parent.name for p in (ROOT / "locales").glob("*/opencadstudio.ftl")}
@@ -65,14 +69,14 @@ def build(output):
script = "const SITE_LOCALES = " + json.dumps(list(catalogs)) + ";\n" + (ROOT / "site/site.js").read_text()
(output / "site.js").write_text(script, encoding="utf-8")
js_version = hashlib.sha256(script.encode()).hexdigest()[:12]
alternates = '\n'.join(f'<link rel="alternate" hreflang="{lang}" href="{BASE}{locale_path(lang)}" />' for lang in catalogs)
alternates = '\n'.join(f'<link rel="alternate" hreflang="{lang}" href="{BASE}{public_path(lang)}" />' for lang in catalogs)
alternates += f'\n<link rel="alternate" hreflang="x-default" href="{BASE}/" />'
for locale, messages in catalogs.items():
path = locale_path(locale)
destination = output / path.lstrip("/")
path = public_path(locale)
destination = output / locale_path(locale).lstrip("/")
destination.mkdir(parents=True, exist_ok=True)
language_links = '\n'.join(
f'<a href="{locale_path(lang)}" lang="{lang}" hreflang="{lang}" dir="auto"'
f'<a href="{public_path(lang)}" lang="{lang}" hreflang="{lang}" dir="auto"'
+ (' aria-current="page"' if lang == locale else '')
+ f'>{escape(labels["name"])}</a>' for lang, labels in catalogs.items()
)
@@ -85,6 +89,11 @@ def build(output):
"downloadUrl": REPO + "/releases/latest", "installUrl": BASE + "/app/",
"offers": {"@type": "Offer", "price": "0", "priceCurrency": "USD"},
}
website_schema = {
"@context": "https://schema.org", "@type": "WebSite",
"name": "Open CAD Studio", "alternateName": ["OpenCADStudio", "opencadstudio.com"],
"url": BASE + "/",
}
values = {key: escape(value) for key, value in messages.items()}
values.update(locale=locale, direction="rtl" if locale == "ar-SA" else "ltr",
path=path, url=BASE + path, og_locale=locale.replace("-", "_"),
@@ -92,6 +101,8 @@ def build(output):
css_version=css_version, js_version=js_version, alternates=alternates,
languages=escape(messages["languages"].format(count=len(catalogs))),
language_links=language_links,
website_schema=(f'<script type="application/ld+json">{json.dumps(website_schema)}</script>'
if locale == "en-US" else ""),
schema=json.dumps(schema, ensure_ascii=False).replace("<", "\\u003c"))
rendered = re.sub(r"\{\{(\w+)\}\}", lambda match: values[match[1]], template)
(destination / "index.html").write_text(rendered, encoding="utf-8")
@@ -101,7 +112,7 @@ def build(output):
(destination / "site.webmanifest").write_text(json.dumps(localized_manifest, ensure_ascii=False, indent=2) + '\n', encoding="utf-8")
for filename in ("index.html", "site.webmanifest"):
shutil.copyfile(output / "en-US" / filename, output / filename)
urls = f'<url><loc>{BASE}/</loc></url>\n' + ''.join(f'<url><loc>{BASE}{locale_path(locale)}</loc></url>\n' for locale in catalogs)
urls = ''.join(f'<url><loc>{BASE}{public_path(locale)}</loc></url>\n' for locale in catalogs)
(output / "sitemap.xml").write_text('<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' + urls + '</urlset>\n')
app = output / "app/index.html"