Skip to content

Commit 39c975e

Browse files
committed
website: real SEO/i18n head — hreflang, OG/Twitter, canonical, favicon
The <head> was minimal and not multilingual-aware. Add, per page and per language: a self-referential canonical; rel=alternate hreflang zh-CN/en/ x-default linking each page to its translation (computed with the same zh-cn<->en-us / about<->about/en logic the visible switcher uses); Open Graph + Twitter Card tags with og:locale/og:locale:alternate; a per-language meta description (was one mixed-language string site-wide). Replace the 1.6 MB cover-PNG favicon with a real 32x32 favicon + 180x180 apple-touch-icon (the book mascot). Drop maximum-scale/user-scalable from viewport (a WCAG 1.4.4 pinch-zoom failure).
1 parent ee052b3 commit 39c975e

8 files changed

Lines changed: 57 additions & 14 deletions

File tree

20.8 KB
Loading
-264 Bytes
Binary file not shown.
-603 Bytes
Binary file not shown.
1.76 KB
Loading
-724 Bytes
Binary file not shown.

website/src/modern-cpp/assets/lang/de.svg

Lines changed: 0 additions & 10 deletions
This file was deleted.
-722 Bytes
Binary file not shown.

website/themes/moderncpp/layout/layout.ejs

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
<%
22
var isEn = page.type == 'book-en-us' || page.type == 'about-en';
33
var isIndex = page.layout === 'index' || page.path === 'index.html';
4+
5+
// Absolute URLs for this page and its other-language twin. Book chapters and
6+
// About pages have a same-path twin; everything else maps to the landing.
7+
// Shared with the visible language switcher so the two never drift.
8+
var SITE = 'https://changkun.de';
9+
var ROOT = '/modern-cpp/';
10+
var _p = page.path || '';
11+
var zhUrl, enUrl;
12+
if (_p.indexOf('zh-cn/') !== -1) {
13+
zhUrl = SITE + '/' + _p.replace(/index\.html$/, '');
14+
enUrl = SITE + '/' + _p.replace('zh-cn/', 'en-us/').replace(/index\.html$/, '');
15+
} else if (_p.indexOf('en-us/') !== -1) {
16+
enUrl = SITE + '/' + _p.replace(/index\.html$/, '');
17+
zhUrl = SITE + '/' + _p.replace('en-us/', 'zh-cn/').replace(/index\.html$/, '');
18+
} else if (_p.indexOf('/about/en/') !== -1) {
19+
enUrl = SITE + '/' + _p.replace(/index\.html$/, '');
20+
zhUrl = SITE + '/' + _p.replace('/about/en/', '/about/');
21+
} else if (_p.indexOf('/about/') !== -1) {
22+
zhUrl = SITE + '/' + _p.replace(/index\.html$/, '');
23+
enUrl = SITE + '/' + _p.replace('/about/', '/about/en/');
24+
} else {
25+
zhUrl = SITE + ROOT;
26+
enUrl = SITE + ROOT + 'en/';
27+
}
28+
var canonicalUrl = isEn ? enUrl : zhUrl;
29+
30+
var siteName = isEn ? 'Modern C++ Tutorial' : '现代 C++ 教程';
31+
var siteTagline = isEn ? 'Modern C++ Tutorial: C++11 to C++26 On the Fly' : '现代 C++ 教程: 高速上手 C++11 到 C++26';
32+
var pageTitle = (page.title ? page.title + ' - ' : '') + siteTagline;
33+
var pageDesc = page.description ? page.description : (isEn
34+
? 'A fast, comprehensive guide to the features of modern C++, from C++11 through C++26.'
35+
: '高速上手现代 C++ 特性的全面教程,覆盖 C++11 到 C++26。');
36+
var ogImage = SITE + ROOT + 'assets/' + (isEn ? 'cover-2nd-en.png' : 'cover-2nd.png');
437
%>
538
<!DOCTYPE html>
639
<html lang="<%- isEn ? 'en' : 'zh-CN' %>">
@@ -22,13 +55,33 @@
2255
})();
2356
</script>
2457
<% } %>
25-
<title><%- page.title ? page.title + ' - ' : '' %><%- isEn ? 'Modern C++ Tutorial: C++11 to C++26 On the Fly' : '现代 C++ 教程: 高速上手 C++11 到 C++26' %></title>
26-
<meta name="description" content="<%- theme.site_description %>">
27-
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
28-
<link rel="shortcut icon" type="image/x-icon" href="/modern-cpp/assets/cover-2nd.png">
58+
<title><%- pageTitle %></title>
59+
<meta name="description" content="<%- pageDesc %>">
60+
<meta name="viewport" content="width=device-width, initial-scale=1">
61+
62+
<link rel="canonical" href="<%- canonicalUrl %>">
63+
<link rel="alternate" hreflang="zh-CN" href="<%- zhUrl %>">
64+
<link rel="alternate" hreflang="en" href="<%- enUrl %>">
65+
<link rel="alternate" hreflang="x-default" href="<%- SITE + ROOT %>">
66+
67+
<link rel="icon" type="image/png" sizes="32x32" href="/modern-cpp/assets/favicon.png">
68+
<link rel="apple-touch-icon" sizes="180x180" href="/modern-cpp/assets/apple-touch-icon.png">
2969
<meta name="msapplication-TileColor" content="#7e2d36">
3070
<meta name="theme-color" content="#7e2d36">
3171

72+
<meta property="og:type" content="<%- isIndex ? 'website' : 'article' %>">
73+
<meta property="og:site_name" content="<%- siteName %>">
74+
<meta property="og:title" content="<%- pageTitle %>">
75+
<meta property="og:description" content="<%- pageDesc %>">
76+
<meta property="og:url" content="<%- canonicalUrl %>">
77+
<meta property="og:image" content="<%- ogImage %>">
78+
<meta property="og:locale" content="<%- isEn ? 'en_US' : 'zh_CN' %>">
79+
<meta property="og:locale:alternate" content="<%- isEn ? 'zh_CN' : 'en_US' %>">
80+
<meta name="twitter:card" content="summary_large_image">
81+
<meta name="twitter:title" content="<%- pageTitle %>">
82+
<meta name="twitter:description" content="<%- pageDesc %>">
83+
<meta name="twitter:image" content="<%- ogImage %>">
84+
3285
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600|Roboto Mono' rel='stylesheet' type='text/css'>
3386
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
3487

0 commit comments

Comments
 (0)