diff options
| author | sillylaird <sillyfanboy@gmail.com> | 2026-09-03 00:33:59 +0000 |
|---|---|---|
| committer | sillylaird <sillyfanboy@gmail.com> | 2026-09-03 00:33:59 +0000 |
| commit | 898b52edcb47bcb3e9d6106e74ca73e74ea01e70 (patch) | |
| tree | 85c6ee5ad58b860144551184d4cf86b560c62b91 /partials/head_meta.php | |
| download | www-898b52edcb47bcb3e9d6106e74ca73e74ea01e70.tar.gz www-898b52edcb47bcb3e9d6106e74ca73e74ea01e70.zip | |
Diffstat (limited to 'partials/head_meta.php')
| -rw-r--r-- | partials/head_meta.php | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/partials/head_meta.php b/partials/head_meta.php new file mode 100644 index 0000000..4f1bbd4 --- /dev/null +++ b/partials/head_meta.php @@ -0,0 +1,103 @@ +<?php +// partials/head_meta.php — render the OG / Twitter / canonical / hreflang +// boilerplate that every triplicated page needs. +// +// Caller passes in: +// $meta = [ +// 'lang' => 'en'|'ja'|'zh', // current locale +// 'title' => 'Page title', // og/twitter title +// 'desc' => 'Page description', // og/twitter description +// 'base' => 'Laird_Lonergan_profile', // filename without lang suffix or .php +// 'image' => 'https://www.sillylaird.ca/...', // optional, default og-default.png +// 'image_alt' => 'alt text for the OG image', // optional +// 'image_width' => 1200, 'image_height' => 630, // optional, override defaults +// 'twitter_desc' => '...', // optional, defaults to $desc +// 'type' => 'website'|'article'|'profile', // optional, default website +// 'author' => 'Laird Lonergan', // optional, for articles +// 'published' => '2026-05-26', // optional ISO date for articles +// 'updated' => '2026-05-26', // optional ISO date +// 'og_url' => 'https://www.sillylaird.ca/', // optional; defaults to self_url +// ] + +$_lang = $meta['lang'] ?? 'en'; +$_title = $meta['title'] ?? ''; +$_desc = $meta['desc'] ?? ''; +$_base = $meta['base'] ?? 'index'; +$_image = $meta['image'] ?? 'https://www.sillylaird.ca/assets/img/og-default.png'; +$_imgW = (int)($meta['image_width'] ?? 1200); +$_imgH = (int)($meta['image_height'] ?? 630); +$_imgAlt = $meta['image_alt'] ?? ($_title !== '' ? $_title : 'SillyLaird'); +$_twDesc = $meta['twitter_desc'] ?? $_desc; +$_type = $meta['type'] ?? 'website'; +$_author = $meta['author'] ?? ''; +$_published= $meta['published'] ?? ''; +$_updated = $meta['updated'] ?? ''; + +$_suffix = ['en' => '', 'ja' => '_jp', 'zh' => '_zh'][$_lang] ?? ''; +$_self = '/' . $_base . $_suffix . '.php'; +// URL overrides let pages with non-default canonicals (e.g. the homepage, +// whose EN canonical is the root "/" not "/index.php") reuse this partial. +$_selfUrl = $meta['self_url'] ?? ('https://www.sillylaird.ca' . $_self); +$_ogUrl = $meta['og_url'] ?? $_selfUrl; +$_enUrl = $meta['en_url'] ?? ('https://www.sillylaird.ca/' . $_base . '.php'); +$_jaUrl = $meta['ja_url'] ?? ('https://www.sillylaird.ca/' . $_base . '_jp.php'); +$_zhUrl = $meta['zh_url'] ?? ('https://www.sillylaird.ca/' . $_base . '_zh.php'); +$_xDefault = $meta['x_default'] ?? $_enUrl; +$_ogLocale = ['en' => 'en_US', 'ja' => 'ja_JP', 'zh' => 'zh_CN'][$_lang]; + +$_h = fn(string $s) => htmlspecialchars($s, ENT_QUOTES, 'UTF-8'); +?> + <meta name="description" content="<?= $_h($_desc) ?>" /> + <meta name="author" content="<?= $_h($_author !== '' ? $_author : 'Laird Lonergan (SillyLaird)') ?>" /> + <meta name="theme-color" content="#000000" /> + <meta name="apple-mobile-web-app-capable" content="yes" /> + <meta name="apple-mobile-web-app-title" content="SillyLaird" /> + <meta name="mobile-web-app-capable" content="yes" /> + <meta name="referrer" content="strict-origin-when-cross-origin" /> + + <meta property="og:site_name" content="SillyLaird" /> + <meta property="og:title" content="<?= $_h($_title) ?>" /> + <meta property="og:description" content="<?= $_h($_desc) ?>" /> + <meta property="og:image" content="<?= $_h($_image) ?>" /> + <meta property="og:image:width" content="<?= $_imgW ?>" /> + <meta property="og:image:height" content="<?= $_imgH ?>" /> + <meta property="og:image:alt" content="<?= $_h($_imgAlt) ?>" /> + <meta property="og:type" content="<?= $_h($_type) ?>" /> + <meta property="og:url" content="<?= $_h($_ogUrl) ?>" /> + <meta property="og:locale" content="<?= $_ogLocale ?>" /> +<?php foreach (['en_US', 'ja_JP', 'zh_CN'] as $_alt): if ($_alt !== $_ogLocale): ?> + <meta property="og:locale:alternate" content="<?= $_alt ?>" /> +<?php endif; endforeach; ?> +<?php if ($_type === 'article'): ?> +<?php if ($_published): ?> + <meta property="article:published_time" content="<?= $_h($_published) ?>" /> +<?php endif; ?> +<?php if ($_updated): ?> + <meta property="article:modified_time" content="<?= $_h($_updated) ?>" /> +<?php endif; ?> +<?php if ($_author): ?> + <meta property="article:author" content="<?= $_h($_author) ?>" /> +<?php endif; ?> +<?php endif; ?> + + <meta name="twitter:card" content="summary_large_image" /> + <meta name="twitter:title" content="<?= $_h($_title) ?>" /> + <meta name="twitter:description" content="<?= $_h($_twDesc) ?>" /> + <meta name="twitter:image" content="<?= $_h($_image) ?>" /> + <meta name="twitter:image:alt" content="<?= $_h($_imgAlt) ?>" /> + + <link rel="canonical" href="<?= $_h($_selfUrl) ?>" /> + <link rel="alternate" hreflang="x-default" href="<?= $_h($_xDefault) ?>" /> + <link rel="alternate" hreflang="en" href="<?= $_h($_enUrl) ?>" /> + <link rel="alternate" hreflang="zh" href="<?= $_h($_zhUrl) ?>" /> + <link rel="alternate" hreflang="ja" href="<?= $_h($_jaUrl) ?>" /> + + <link rel="alternate" type="application/rss+xml" title="SillyLaird Blog (RSS)" href="https://blog.sillylaird.ca/feed.xml.php" /> + <link rel="alternate" type="application/atom+xml" title="SillyLaird Changelog (Atom)" href="https://www.sillylaird.ca/changelog/feed.xml.php" /> + <link rel="alternate" type="application/atom+xml" title="SillyLaird Journal (Atom)" href="https://www.sillylaird.ca/journal/feed.xml.php" /> + + <link rel="icon" type="image/x-icon" href="/favicon.ico" /> + <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" /> + <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" /> + <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" /> + <link rel="manifest" href="/site.webmanifest" /> |
