Skip to content

Commit a8312e7

Browse files
committed
Add English pages. Change settings accordingly.
1 parent 51e7514 commit a8312e7

35 files changed

+769
-87
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ _site
55
vendor
66
dev.txt
77
*backup*
8-
Gemfile.lock
8+
Gemfile.lock
9+
*IFLOW*

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ source "https://mirrors.aliyun.com/rubygems/"
1414
# Happy Jekylling!
1515
gem "github-pages", "~> 232", group: :jekyll_plugins
1616
# gem "jekyll", "~> 4.4.1"
17+
gem "jekyll-polyglot", group: :jekyll_plugins # 添加 Polyglot
1718
gem "jekyll-include-cache", group: :jekyll_plugins
1819

1920
# 主题(你用的是 minimal-mistakes-jekyll)
@@ -26,7 +27,6 @@ gem "jekyll-paginate"
2627
gem "jekyll-sitemap"
2728
gem "jekyll-gist"
2829
gem "jekyll-feed", "~> 0.12"
29-
gem "jekyll-include-cache"
3030

3131
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
3232
# uncomment the line below. To upgrade, run `bundle update github-pages`.

_config.yml

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ minimal_mistakes_skin: "dark" # 可选: default, air, contrast, dark, dirt, neo
5959

6060
# 语言
6161
locale: "zh-CN"
62+
languages: ["en", "zh"]
63+
default_lang: "zh"
64+
exclude_from_localization: ["assets/css", "assets/img"] # 不进行本地化的目录
65+
parallel_localization: true
66+
sass:
67+
sourcemap: never
6268

6369
# 搜索功能
6470
search: true
@@ -71,39 +77,49 @@ author:
7177
bio : "科技爱好者"
7278
location: "中国, 广州"
7379

74-
75-
# ========== 目录包含配置 ==========
76-
# 注意:Jekyll默认不会处理以下划线开头的自定义目录(如_pages)
77-
# 必须在include中显式声明,否则该目录下的文件会被忽略
80+
# ========== Markdown配置 ==========
81+
markdown: kramdown
82+
kramdown:
83+
auto_ids: true
84+
entity_output: as_char
85+
toc_levels: 1..6
86+
smart_quotes: lsquo,rsquo,ldquo,rdquo
87+
input: GFM # 关键:启用 GitHub Flavored Markdown,支持表格
88+
hard_wrap: false
89+
footnote_nr: 1
90+
show_warnings: false
91+
syntax_highlighter: rouge
92+
93+
# ========== 目录配置 ==========
94+
# 注意:使用jekyll-polyglot时,不需要特别include语言目录
95+
# 插件会自动处理多语言内容
7896
include:
7997
- _pages
80-
- _publications # 如果你使用collections
81-
- _news
82-
83-
# 博客文章默认设置
98+
- _posts
99+
84100
defaults:
85-
# _posts
101+
# 所有页面默认配置
86102
- scope:
87103
path: ""
88-
type: posts
104+
type: pages
89105
values:
90106
layout: single
91107
author_profile: true
92-
read_time: true
93-
comments: true
94-
share: true
95-
related: true
96108

97-
# _pages
109+
# 所有博客文章默认配置
98110
- scope:
99-
path: "_pages"
100-
type: pages
111+
path: ""
112+
type: posts
101113
values:
102-
layout: single
114+
layout: post
103115
author_profile: true
116+
read_time: true
117+
comments: true
118+
related: true
104119

105120
# 插件
106121
plugins:
122+
- jekyll-polyglot
107123
- jekyll-paginate
108124
- jekyll-sitemap
109125
- jekyll-gist

_data/navigation.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

_includes/head_custom.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

_includes/lang_switcher.html

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<!-- 调试信息:current_lang={{ page.lang | default: 'zh' }}, current_path={{ page.url | default: '/' }} -->
2+
<nav class="language-switcher">
3+
{% assign current_lang = page.lang | default: 'zh' %}
4+
{% assign current_path = page.url | default: '/' %}
5+
6+
{% if current_lang == 'en' %}
7+
<!-- 英文页面 -->
8+
<span class="current-lang">English</span>
9+
{% if current_path == '/' %}
10+
<!-- 英文首页 -->
11+
<a href="/" class="alt-lang" onclick="console.log('点击切换到中文首页');">中文</a>
12+
{% else %}
13+
<!-- 其他英文页面 -->
14+
<a href="{{ current_path | replace: '/en', '' }}" class="alt-lang" onclick="console.log('点击切换到中文页面: {{ current_path | replace: '/en', '' }}');">中文</a>
15+
{% endif %}
16+
{% else %}
17+
<!-- 中文页面 -->
18+
<span class="current-lang">中文</span>
19+
{% if current_path == '/' %}
20+
<!-- 中文首页 -->
21+
<a href="/en/" class="alt-lang" onclick="console.log('点击切换到英文首页');">English</a>
22+
{% else %}
23+
<!-- 其他中文页面 -->
24+
<a href="/en{{ current_path }}" class="alt-lang" onclick="console.log('点击切换到英文页面: /en{{ current_path }}');">English</a>
25+
{% endif %}
26+
{% endif %}
27+
</nav>
28+
29+
<style>
30+
.language-switcher {
31+
display: flex;
32+
gap: 0.5rem;
33+
align-items: center;
34+
background: rgba(0, 0, 0, 0.8);
35+
padding: 0.5rem;
36+
border-radius: 8px;
37+
backdrop-filter: blur(10px);
38+
margin-left: 1rem; /* 在搜索按钮右边添加间距 */
39+
}
40+
41+
.language-switcher a, .language-switcher span {
42+
padding: 0.4rem 1rem;
43+
border-radius: 6px;
44+
text-decoration: none;
45+
font-weight: 500;
46+
transition: all 0.2s ease;
47+
font-size: 0.9rem;
48+
}
49+
50+
.language-switcher .current-lang {
51+
background: rgba(255, 255, 255, 0.2);
52+
color: white;
53+
cursor: default;
54+
}
55+
56+
.language-switcher .alt-lang {
57+
background: rgba(255, 255, 255, 0.1);
58+
color: white;
59+
border: 1px solid rgba(255, 255, 255, 0.3);
60+
cursor: pointer;
61+
}
62+
63+
.language-switcher .alt-lang:hover {
64+
background: rgba(255, 255, 255, 0.2);
65+
transform: translateY(-1px);
66+
}
67+
68+
@media (max-width: 768px) {
69+
.language-switcher {
70+
padding: 0.3rem;
71+
margin-left: 0.5rem;
72+
}
73+
.language-switcher a, .language-switcher span {
74+
padding: 0.3rem 0.7rem;
75+
font-size: 0.8rem;
76+
}
77+
}
78+
</style>

_includes/share_custom.html

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<section class="share">
2+
<h4>分享到</h4>
3+
<div class="share-buttons">
4+
<a href="https://service.weibo.com/share/share.php?url={{ site.url }}{{ page.url }}&title={{ page.title | cgi_escape }}" class="btn" title="分享到微博">
5+
微博
6+
</a>
7+
<a href="https://www.zhihu.com/search?type=content&q={{ page.title | cgi_escape }}" class="btn" title="分享到知乎">
8+
知乎
9+
</a>
10+
<button onclick="showWeChatQR('{{ site.url }}{{ page.url }}')" class="btn" title="分享到微信">
11+
微信
12+
</button>
13+
<a href="https://www.xiaohongshu.com/search_result?keyword={{ page.title | cgi_escape }}" class="btn" title="分享到小红书">
14+
小红书
15+
</a>
16+
<button onclick="copyToClipboard('{{ site.url }}{{ page.url }}')" class="btn" title="复制链接">
17+
复制链接
18+
</button>
19+
</div>
20+
21+
<!-- 微信二维码模态框 -->
22+
<div id="wechatModal" class="modal">
23+
<div class="modal-content">
24+
<span class="close">&times;</span>
25+
<h3>分享到微信</h3>
26+
<p>使用微信扫一扫分享此文章</p>
27+
<div id="qrcode"></div>
28+
<p style="font-size: 0.9rem; color: #666;">或复制链接发送给好友</p>
29+
</div>
30+
</div>
31+
32+
<script>
33+
function copyToClipboard(text) {
34+
navigator.clipboard.writeText(text).then(function() {
35+
alert('链接已复制到剪贴板!');
36+
}, function(err) {
37+
console.error('无法复制: ', err);
38+
});
39+
}
40+
41+
// 微信二维码功能
42+
function showWeChatQR(url) {
43+
document.getElementById('wechatModal').style.display = 'block';
44+
// 使用简单的 QR Code 生成库
45+
var qrcodeDiv = document.getElementById('qrcode');
46+
qrcodeDiv.innerHTML = '';
47+
48+
// 创建 QR Code 的 Canvas
49+
var canvas = document.createElement('canvas');
50+
canvas.width = 200;
51+
canvas.height = 200;
52+
qrcodeDiv.appendChild(canvas);
53+
54+
// 简单的 QR Code 生成(使用外部库会更完善)
55+
var ctx = canvas.getContext('2d');
56+
ctx.fillStyle = '#ffffff';
57+
ctx.fillRect(0, 0, 200, 200);
58+
ctx.fillStyle = '#000000';
59+
ctx.font = '12px monospace';
60+
ctx.fillText('QR Code for:', 10, 20);
61+
ctx.fillText(url.substring(0, 30), 10, 40);
62+
if (url.length > 30) {
63+
ctx.fillText(url.substring(30, 60), 10, 55);
64+
}
65+
ctx.fillText('(请使用微信扫描)', 10, 180);
66+
}
67+
68+
// 关闭模态框
69+
document.addEventListener('DOMContentLoaded', function() {
70+
var modal = document.getElementById('wechatModal');
71+
var span = document.getElementsByClassName('close')[0];
72+
73+
if (span) {
74+
span.onclick = function() {
75+
modal.style.display = 'none';
76+
}
77+
}
78+
79+
window.onclick = function(event) {
80+
if (event.target == modal) {
81+
modal.style.display = 'none';
82+
}
83+
}
84+
});
85+
</script>
86+
87+
<style>
88+
.share-buttons {
89+
margin-top: 1rem;
90+
}
91+
.share-buttons .btn {
92+
display: inline-block;
93+
margin-right: 0.5rem;
94+
margin-bottom: 0.5rem;
95+
padding: 0.5rem 1rem;
96+
background-color: #f0f0f0;
97+
color: #333;
98+
text-decoration: none;
99+
border-radius: 4px;
100+
font-size: 0.9rem;
101+
border: none;
102+
cursor: pointer;
103+
}
104+
.share-buttons .btn:hover {
105+
background-color: #e0e0e0;
106+
}
107+
108+
/* 模态框样式 */
109+
.modal {
110+
display: none;
111+
position: fixed;
112+
z-index: 1000;
113+
left: 0;
114+
top: 0;
115+
width: 100%;
116+
height: 100%;
117+
background-color: rgba(0,0,0,0.5);
118+
}
119+
120+
.modal-content {
121+
background-color: #fefefe;
122+
margin: 10% auto;
123+
padding: 20px;
124+
border: 1px solid #888;
125+
width: 80%;
126+
max-width: 400px;
127+
border-radius: 8px;
128+
text-align: center;
129+
}
130+
131+
.close {
132+
color: #aaa;
133+
float: right;
134+
font-size: 28px;
135+
font-weight: bold;
136+
cursor: pointer;
137+
line-height: 1;
138+
}
139+
140+
.close:hover,
141+
.close:focus {
142+
color: black;
143+
text-decoration: none;
144+
}
145+
146+
#qrcode {
147+
margin: 20px auto;
148+
display: flex;
149+
justify-content: center;
150+
align-items: center;
151+
}
152+
153+
#qrcode canvas {
154+
border: 1px solid #ddd;
155+
border-radius: 4px;
156+
}
157+
</style>
158+
</section>

_layouts/custom-archive.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
layout: archive
3+
---
4+
5+
{{ content }}
6+
7+
<!-- 多语言导航切换脚本 -->
8+
<script src="{{ '/assets/js/nav-switcher.js' | relative_url }}"></script>

_layouts/custom-categories.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
layout: categories
3+
---
4+
5+
<!-- 语言切换按钮 -->
6+
{% include lang_switcher.html %}
7+
8+
{{ content }}
9+
10+
<!-- 多语言导航切换脚本 -->
11+
<script src="{{ '/assets/js/nav-switcher.js' | relative_url }}"></script>

_layouts/custom-home.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
layout: home
3+
---
4+
5+
{{ content }}
6+
7+
<!-- 多语言导航切换脚本 -->
8+
<script src="{{ '/assets/js/nav-switcher.js' | relative_url }}"></script>

0 commit comments

Comments
 (0)