| --- | |
| import '../styles/global.css'; | |
| import { BASE, SITE_DESCRIPTION, SITE_TITLE, SITE_URL, type Lang } from '../lib/site'; | |
| export interface Props { | |
| title?: string; | |
| description?: string; | |
| lang?: Lang; | |
| /** Routes (without the base) of this page in each locale, for hreflang. */ | |
| alternates?: { en?: string; 'zh-CN'?: string }; | |
| robots?: string; | |
| } | |
| const { title, description = SITE_DESCRIPTION, lang = 'en', alternates, robots } = Astro.props; | |
| // A title that already names the site (the home pages') is used as it is. | |
| const pageTitle = !title || title === SITE_TITLE | |
| ? `${SITE_TITLE} — Build once, native everywhere | Rust UI framework` | |
| : title.startsWith(SITE_TITLE) ? title : `${title} · ${SITE_TITLE}`; | |
| const canonical = new URL(Astro.url.pathname.replace(/\/+$/, '') || '/', SITE_URL).href; | |
| const abs = (route: string) => new URL(`${BASE.replace(/\/$/, '')}${route}`, SITE_URL).href; | |
| --- | |
| <!doctype html> | |
| <html lang={lang} class="dark" data-theme-pref="system"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | |
| <title>{pageTitle}</title> | |
| <meta name="description" content={description} /> | |
| {robots && <meta name="robots" content={robots} />} | |
| <meta name="color-scheme" content="dark light" /> | |
| <meta name="theme-color" content="#101113" media="(prefers-color-scheme: dark)" /> | |
| <meta name="theme-color" content="#f4f4f2" media="(prefers-color-scheme: light)" /> | |
| <!-- Before first paint: `theme` in localStorage is "light" or "dark"; | |
| absent follows the system. <html> gets `dark` or `light`. --> | |
| <script is:inline> | |
| (function () { | |
| var stored = null; | |
| try { stored = localStorage.getItem('theme'); } catch (e) {} | |
| var pref = stored === 'light' || stored === 'dark' ? stored : 'system'; | |
| var media = window.matchMedia('(prefers-color-scheme: dark)'); | |
| var root = document.documentElement; | |
| var apply = function () { | |
| var p = root.dataset.themePref; | |
| var dark = p === 'dark' || (p === 'system' && media.matches); | |
| root.classList.toggle('dark', dark); | |
| root.classList.toggle('light', !dark); | |
| }; | |
| root.dataset.themePref = pref; | |
| apply(); | |
| media.addEventListener('change', apply); | |
| window.__applyTheme = apply; | |
| })(); | |
| </script> | |
| <link rel="icon" type="image/svg+xml" href={`${BASE}favicon.svg`} /> | |
| <link rel="apple-touch-icon" href={`${BASE}apple-touch-icon.png`} /> | |
| <link rel="canonical" href={canonical} /> | |
| {alternates?.en && <link rel="alternate" hreflang="en" href={abs(alternates.en)} />} | |
| {alternates?.['zh-CN'] && <link rel="alternate" hreflang="zh-CN" href={abs(alternates['zh-CN'])} />} | |
| {alternates?.en && <link rel="alternate" hreflang="x-default" href={abs(alternates.en)} />} | |
| <meta property="og:type" content="website" /> | |
| <meta property="og:locale" content={lang === 'zh-CN' ? 'zh_CN' : 'en_US'} /> | |
| <meta property="og:site_name" content={SITE_TITLE} /> | |
| <meta property="og:title" content={pageTitle} /> | |
| <meta property="og:description" content={description} /> | |
| <meta property="og:url" content={canonical} /> | |
| <meta property="og:image" content={abs('/icon-512.png')} /> | |
| <meta name="twitter:card" content="summary" /> | |
| <link rel="alternate" type="text/plain" title="llms.txt" href={`${BASE}llms.txt`} /> | |
| </head> | |
| <body> | |
| <a class="skip-link" href="#main">{lang === 'zh-CN' ? '跳到正文' : 'Skip to content'}</a> | |
| <slot /> | |
| </body> | |
| </html> |