aboutsummaryrefslogtreecommitdiffstats
path: root/partials/head_meta.php
blob: 4f1bbd40c29d276f39f4db493d79519456135fa6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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" />