Skip to content

Commit 726fd10

Browse files
committed
website: make landing single-language with a link switcher
The landing page rendered both Chinese and English heroes into one HTML document and toggled between them with client-side JS. Mirror the single-language model the book pages and the reference sites already use: index.ejs now renders one hero/footer chosen by page.type, the switcher is a plain link, and a dedicated English landing lives at /modern-cpp/en/. Also fix stale shell copy: <html lang> was hardcoded to en on every page (now follows page.type), the README purpose lines said C++ 'before 2020s' (now C++11 through C++26), and _config.yml description was the author name.
1 parent a88a18a commit 726fd10

8 files changed

Lines changed: 59 additions & 80 deletions

File tree

README-zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## 本书目的
88

9-
本书号称『高速上手』,从内容上对二十一世纪二十年代之前产生 C++ 的相关特性做了非常相对全面的介绍,读者可以自行根据下面的目录选取感兴趣的内容进行学习,快速熟悉需要了解的内容。这些特性并不需要全部掌握,只需针对自己的使用需求和特定的应用场景,学习、查阅最适合自己的新特性即可。
9+
本书号称『高速上手』,从内容上对现代 C++(从 C++11 到 C++26)的相关特性做了相对全面的介绍,读者可以自行根据下面的目录选取感兴趣的内容进行学习,快速熟悉需要了解的内容。这些特性并不需要全部掌握,只需针对自己的使用需求和特定的应用场景,学习、查阅最适合自己的新特性即可。
1010

1111
同时,本书在介绍这些特性的过程中,尽可能简单明了的介绍了这些特性产生的历史背景和技术需求,这为理解这些特性、运用这些特性提供了很大的帮助。
1212

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![](https://img.shields.io/github/actions/workflow/status/changkun/modern-cpp-tutorial/website.yml?branch=master&style=flat-square)](https://github.com/changkun/modern-cpp-tutorial/actions/workflows/website.yml) [![](https://img.shields.io/badge/language-English-blue.svg?style=flat-square)](./README.md) [![](https://img.shields.io/badge/language-简体中文-red.svg?style=flat-square)](./README-zh-cn.md) [![](https://img.shields.io/badge/€-donate-ff69b4.svg?style=flat-square)](./assets/donate.md)
66
## Purpose
77

8-
The book claims to be "On the Fly". Its intent is to provide a comprehensive introduction to the relevant features regarding modern C++ (before 2020s).
8+
The book claims to be "On the Fly". Its intent is to provide a comprehensive introduction to the relevant features of modern C++ (from C++11 through C++26).
99
Readers can choose interesting content according to the following table of content to learn and quickly familiarize the new features you would like to learn.
1010
Readers should be aware that not all of these features are required. Instead, it should be learned when you really need it.
1111

website/_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Site Configuration
22
title: "现代 C++ 教程: 高速上手 C++11 到 C++26"
33
subtitle: C++11 to C++26 On the Fly
4-
description: "欧长坤"
4+
description: "现代 C++ 教程:高速上手 C++11 到 C++26 | Modern C++ Tutorial: C++11 to C++26 On the Fly"
55
author: 欧长坤
66
email: hi[at]changkun.de
77
language: zh-CN

website/src/_posts/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
index: true
3+
type: book-zh-cn
34
---
4-

website/src/modern-cpp/en/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
layout: index
3+
type: book-en-us
4+
---
Lines changed: 47 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
<% var isEn = page.type == 'book-en-us' %>
2+
13
<div class="sidebar">
24
<div class="sidebar-inner-index">
35
<ul class="main-menu">
4-
<% if (page.type == 'book-en-us') { %>
6+
<% if (isEn) { %>
57
<%- partial('partials/main_menu_en', { context: 'nav' }) %>
68
<% } else {%>
79
<%- partial('partials/main_menu', { context: 'nav' }) %>
@@ -11,35 +13,20 @@
1113
</div>
1214

1315
<div id="lang-switch">
14-
<button type="button" class="lang-btn" data-set="zh">
15-
<span class="flag" style="content: url(/modern-cpp/assets/lang/cn.svg);"></span>中文
16-
</button>
17-
<button type="button" class="lang-btn" data-set="en">
18-
<span class="flag" style="content: url(/modern-cpp/assets/lang/en.svg);"></span>English
19-
</button>
20-
</div>
21-
22-
<div id="hero" class="lang" data-lang="zh">
23-
<div class="inner">
24-
<div class="left">
25-
<img class="hero-logo" src="<%- url_for("/modern-cpp/assets/cover-2nd.png") %>">
26-
</div><div class="right">
27-
<h4>欧长坤 著</h4>
28-
<h1>
29-
现代 C++ 教程<br>
30-
</h1>
31-
<h2>高速上手 C++11 到 C++26</h2>
32-
<h3>第二版</h3>
33-
<p>
34-
<a class="button white" href="<%- url_for("/modern-cpp/zh-cn/00-preface/") %>">🇨🇳 在线阅读</a>
35-
<a class="button download" href="<%- url_for("/modern-cpp/pdf/modern-cpp-tutorial-zh-cn.pdf") %>">🇨🇳 下载</a>
36-
</p>
37-
</div>
38-
</div>
16+
<% if (isEn) { %>
17+
<a class="lang-btn" href="<%- url_for("/modern-cpp/") %>">
18+
<span class="flag" style="content: url(/modern-cpp/assets/lang/cn.svg);"></span>中文
19+
</a>
20+
<% } else { %>
21+
<a class="lang-btn" href="<%- url_for("/modern-cpp/en/") %>">
22+
<span class="flag" style="content: url(/modern-cpp/assets/lang/en.svg);"></span>English
23+
</a>
24+
<% } %>
3925
</div>
4026

41-
<div id="hero" class="lang" data-lang="en">
42-
<div class="inner">
27+
<% if (isEn) { %>
28+
<div id="hero">
29+
<div class="inner">
4330
<div class="left">
4431
<img class="hero-logo" src="<%- url_for("/modern-cpp/assets/cover-2nd-en.png") %>">
4532
</div><div class="right">
@@ -54,45 +41,39 @@
5441
<a class="button download" href="<%- url_for("/modern-cpp/pdf/modern-cpp-tutorial-en-us.pdf") %>">🇬🇧 Download</a>
5542
</p>
5643
</div>
44+
</div>
5745
</div>
58-
</div>
46+
<% } else { %>
47+
<div id="hero">
48+
<div class="inner">
49+
<div class="left">
50+
<img class="hero-logo" src="<%- url_for("/modern-cpp/assets/cover-2nd.png") %>">
51+
</div><div class="right">
52+
<h4>欧长坤 著</h4>
53+
<h1>
54+
现代 C++ 教程<br>
55+
</h1>
56+
<h2>高速上手 C++11C++26</h2>
57+
<h3>第二版</h3>
58+
<p>
59+
<a class="button white" href="<%- url_for("/modern-cpp/zh-cn/00-preface/") %>">🇨🇳 在线阅读</a>
60+
<a class="button download" href="<%- url_for("/modern-cpp/pdf/modern-cpp-tutorial-zh-cn.pdf") %>">🇨🇳 下载</a>
61+
</p>
62+
</div>
63+
</div>
64+
</div>
65+
<% } %>
5966

6067
<div id="footer">
61-
<p class="lang" data-lang="zh">
62-
<a href="https://changkun.de">欧长坤</a> &copy; 2016-<%- new Date().getFullYear() %> 版权所有,
63-
采用<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/">知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议许可</a>,代码使用 <a href="https://opensource.org/licenses/MIT" target="_blank">MIT</a> 协议开源。</a>
64-
</p>
65-
<p class="lang" data-lang="en">
66-
<a href="https://changkun.de">Changkun Ou</a> &copy; 2016-<%- new Date().getFullYear() %>.
67-
The book is licensed under <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/">Creative Commons Attribution-NonCommercial-NoDerivatives 4.0</a>, code is open sourced under the <a href="https://opensource.org/licenses/MIT" target="_blank">MIT</a> License. </a>
68-
</p>
68+
<% if (isEn) { %>
69+
<p>
70+
<a href="https://changkun.de">Changkun Ou</a> &copy; 2016-<%- new Date().getFullYear() %>.
71+
The book is licensed under <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/">Creative Commons Attribution-NonCommercial-NoDerivatives 4.0</a>, code is open sourced under the <a href="https://opensource.org/licenses/MIT" target="_blank">MIT</a> License.
72+
</p>
73+
<% } else { %>
74+
<p>
75+
<a href="https://changkun.de">欧长坤</a> &copy; 2016-<%- new Date().getFullYear() %> 版权所有,
76+
采用<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/">知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议许可</a>,代码使用 <a href="https://opensource.org/licenses/MIT" target="_blank">MIT</a> 协议开源。
77+
</p>
78+
<% } %>
6979
</div>
70-
71-
<script>
72-
(function () {
73-
var sections = document.querySelectorAll('.lang');
74-
var buttons = document.querySelectorAll('.lang-btn');
75-
function apply(lang) {
76-
for (var i = 0; i < sections.length; i++) {
77-
sections[i].style.display = sections[i].getAttribute('data-lang') === lang ? '' : 'none';
78-
}
79-
for (var j = 0; j < buttons.length; j++) {
80-
var on = buttons[j].getAttribute('data-set') === lang;
81-
buttons[j].className = on ? 'lang-btn active' : 'lang-btn';
82-
}
83-
document.documentElement.lang = lang === 'zh' ? 'zh-CN' : 'en';
84-
}
85-
var stored = null;
86-
try { stored = localStorage.getItem('mcpp-lang'); } catch (e) {}
87-
var nav = (navigator.language || navigator.userLanguage || 'en').toLowerCase();
88-
var lang = stored || (nav.indexOf('zh') === 0 ? 'zh' : 'en');
89-
apply(lang);
90-
for (var k = 0; k < buttons.length; k++) {
91-
buttons[k].addEventListener('click', function () {
92-
var l = this.getAttribute('data-set');
93-
try { localStorage.setItem('mcpp-lang', l); } catch (e) {}
94-
apply(l);
95-
});
96-
}
97-
})();
98-
</script>

website/themes/moderncpp/layout/layout.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<% var isIndex = page.path === 'index.html' %>
1+
<% var isIndex = page.layout === 'index' || page.path === 'index.html' %>
22

33
<!DOCTYPE html>
4-
<html lang="en">
4+
<html lang="<%- page.type == 'book-en-us' ? 'en' : 'zh-CN' %>">
55
<head>
66
<title><%- page.title ? page.title : '' %> 现代 C++ 教程: 高速上手 C++11 到 C++26 - Modern C++ Tutorial: C++11 to C++26 On the Fly</title>
77
<meta charset="utf-8">

website/themes/moderncpp/source/modern-cpp/css/index.styl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ body
2222
.logo
2323
display: none
2424

25-
// Before JS runs, show only the Chinese sections to avoid a flash of both
26-
// languages; the toggle script reveals the right one on load.
27-
.lang[data-lang="en"]
28-
display: none
29-
3025
#lang-switch
3126
text-align: center
3227
padding: 90px 40px 0 200px
33-
button.lang-btn
28+
a.lang-btn
29+
display: inline-block
3430
background: transparent
3531
border: 1px solid rgba(126, 45, 54, 0.4)
3632
color: $theme
@@ -43,8 +39,6 @@ body
4339
cursor: pointer
4440
transition: all .2s ease
4541
&:hover
46-
border-color: $theme
47-
&.active
4842
background: $theme
4943
color: #fff
5044
border-color: $theme

0 commit comments

Comments
 (0)