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

+10 -3
View File
@@ -57,7 +57,8 @@ with tempfile.TemporaryDirectory() as directory:
links = [attrs for tag, attrs in page.tags if tag == 'link']
assert {link['href'] for link in links if link.get('rel') == 'icon'} == {'/favicon.ico', '/favicon.png', '/favicon.svg'}
assert {link['hreflang'] for link in links if link.get('rel') == 'alternate'} == supported | {'x-default'}
assert next(link['href'] for link in links if link.get('rel') == 'canonical') == f'https://www.opencadstudio.com/{locale}/'
expected_path = '/' if locale == 'en-US' else f'/{locale}/'
assert next(link['href'] for link in links if link.get('rel') == 'canonical') == f'https://www.opencadstudio.com{expected_path}'
choices = [attrs for tag, attrs in page.tags if tag == 'a' and 'hreflang' in attrs]
assert {choice['hreflang'] for choice in choices} == supported
assert [choice['hreflang'] for choice in choices if choice.get('aria-current') == 'page'] == [locale]
@@ -74,7 +75,7 @@ with tempfile.TemporaryDirectory() as directory:
path = output / urlsplit(target).path.lstrip('/')
assert path.exists(), (locale, target)
manifest = json.loads((output / locale / 'site.webmanifest').read_text())
assert manifest['lang'] == locale and manifest['start_url'] == f'/{locale}/'
assert manifest['lang'] == locale and manifest['start_url'] == expected_path
for icon in manifest['icons']:
assert (output / icon['src'].lstrip('/')).exists()
if locale != 'en-US':
@@ -87,7 +88,13 @@ with tempfile.TemporaryDirectory() as directory:
assert icon == '/favicon.svg'
assert (output / icon.lstrip('/')).read_bytes() == (ROOT / 'site/favicon.svg').read_bytes()
sitemap = ET.parse(output / 'sitemap.xml')
assert len(sitemap.getroot()) == len(supported) + 1
locations = {url[0].text for url in sitemap.getroot()}
assert len(locations) == len(supported)
assert 'https://www.opencadstudio.com/' in locations
assert 'https://www.opencadstudio.com/en-US/' not in locations
assert (output / 'index.html').read_bytes() == (output / 'en-US/index.html').read_bytes()
homepage_schemas = [json.loads(value) for value in re.findall(r'<script type="application/ld\+json">(.*?)</script>', (output / 'index.html').read_text())]
website = next(schema for schema in homepage_schemas if schema['@type'] == 'WebSite')
assert website['url'] == 'https://www.opencadstudio.com/' and 'OpenCADStudio' in website['alternateName']
subprocess.run(['node', 'scripts/test_site.cjs', str(output / 'site.js')], cwd=ROOT, check=True)
print(f'All {len(supported)} translations, metadata, local links, charts, manifests and icons passed')