Skip to content

Commit fc2ec5e

Browse files
committed
添加多语言支持(#15);增加侧边栏全部展开选项(#7)
1 parent 8eb497c commit fc2ec5e

9 files changed

Lines changed: 51 additions & 17 deletions

File tree

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,20 @@ logo:
7777

7878
### flag
7979

80-
> 语言标识
80+
> Language identifier, multi-language please cooperate with [Subpage](#Subpage-configuration) use.
8181

8282
- icon: Language icons, by default only `flag-cn` and `flag-us`, other icons please look for and store in `theme directory/source/images/flags/`.
8383
- name: Language name
84+
- default: Whether the language is the default language
85+
- index: The page link
8486

8587
Examples:
8688
```yml
8789
flag:
88-
icon: flag-cn
89-
name: Chinese
90+
- name: Chinese
91+
default: true
92+
icon: flag-cn
93+
index: /index.html
9094
```
9195

9296
### search
@@ -171,6 +175,16 @@ menu:
171175
config: myBlog
172176
```
173177

178+
### expandAll
179+
180+
> Whether to expand the sidebar.
181+
182+
示例:
183+
184+
```yml
185+
expandAll: true
186+
```
187+
174188
### about
175189

176190
> About this site in the sidebar.

README_CN.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,20 @@ logo:
7575

7676
### flag
7777

78-
> 语言标识
78+
> 语言标识,多语言请配合[子页面](#子页面配置)使用
7979

8080
- icon: 语言图标,默认仅有`flag-cn`和`flag-us`, 其他图标自行寻找存放于`主题目录/source/images/flags/`
8181
- name: 语言名称
82+
- default: 该语言是否为默认语言
83+
- index: 页面链接
8284

8385
示例:
8486
```yml
8587
flag:
86-
icon: flag-cn
87-
name: Chinese
88+
- name: Chinese
89+
default: true
90+
icon: flag-cn
91+
index: /index.html
8892
```
8993

9094
### search
@@ -169,6 +173,16 @@ menu:
169173
config: myBlog
170174
```
171175

176+
### expandAll
177+
178+
> 是否将侧边栏全部展开
179+
180+
示例:
181+
182+
```yml
183+
expandAll: true
184+
```
185+
172186
### about
173187

174188
> 侧边栏的关于本站

_config.example.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ logo:
77
dark: /images/logo_dark@2x.png
88

99
flag:
10-
icon: flag-cn
11-
name: Chinese
10+
- name: Chinese
11+
default: true
12+
icon: flag-cn
13+
index: /index.html
1214

1315
search: true
1416

@@ -24,6 +26,7 @@ userDefinedSearchData:
2426

2527
githubCorner: '<a href="https://github.com/HCLonely/hexo-theme-webstack" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>'
2628

29+
expandAll: false
2730
menu:
2831
- name: 测试页面
2932
icon: far fa-star

layout/common/head.ejs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
<link rel="shortcut icon" href="<%= url_for(setting.favicon) %>">
1010
<%- css(Object.values(setting.css)) %>
1111
<%- js(setting.js.jquery) %>
12-
<script>var userDefinedSearchData = <%- JSON.stringify(setting.userDefinedSearchData) %>;</script>
12+
<script>
13+
var userDefinedSearchData = <%- JSON.stringify(setting.userDefinedSearchData || {}) %>;
14+
var expandAll = <%- setting.expandAll ? 'true' : 'false' %>;
15+
</script>
1316
<%- js(setting.js.header) %>
1417
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
1518
<!--[if lt IE 9]>

layout/common/header.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</header>
2121
<ul id="main-menu" class="main-menu">
2222
<% for( let e of setting.menu ) { %>
23-
<li>
23+
<li class="<%= (e.submenu && setting.expandAll) ? "expanded" : "" %>">
2424
<% if (e.submenu) { %>
2525
<a class="fas fa-angle-down" style="cursor: pointer;">
2626
<% } else { %>
@@ -30,7 +30,7 @@
3030
<span class="title"><%= e.name %></span>
3131
</a>
3232
<% if (e.submenu) { %>
33-
<ul>
33+
<ul style="display: <%= setting.expandAll ? "block" : "none" %>;">
3434
<% e.submenu.forEach(function(e) { %>
3535
<li>
3636
<a href="#<%= e.name %>" class="smooth">

layout/index.ejs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
</li>
1616
<li class="dropdown hover-line language-switcher">
1717
<% const defaultFlag = Array.isArray(setting.flag) ? (setting.flag.find(flag => flag.default) || setting.flag[0]) : setting.flag; %>
18-
<a href="<%= url_for('/index.html') %>" class="dropdown-toggle" data-toggle="dropdown">
18+
<a href="<%= url_for(defaultFlag.index || '/index.html') %>" class="dropdown-toggle" data-toggle="dropdown">
1919
<img src="<%- url_for('images/flags/' + defaultFlag.icon + '.png') %>" alt="<%= defaultFlag.icon %>" /> <%= defaultFlag.name %>
2020
</a>
2121
<ul class="dropdown-menu languages">
2222
<% if (Array.isArray(setting.flag)) { %>
2323
<% setting.flag.forEach(flag => { %>
2424
<li class="<%= flag.default ? 'active' : '' %>">
25-
<a href="<%= url_for('/index.html') %>">
25+
<a href="<%= url_for(flag.index) %>">
2626
<img src="<%- url_for('images/flags/' + flag.icon + '.png') %>" alt="<%= flag.icon %>" alt="<%= flag.icon %>" /> <%= flag.name %>
2727
</a>
2828
</li>
2929
<% }) %>
3030
<% } else { %>
3131
<li class="active">
32-
<a href="<%= url_for('/index.html') %>">
32+
<a href="<%= url_for(defaultFlag.index || '/index.html') %>">
3333
<img src="<%- url_for('images/flags/' + defaultFlag.icon + '.png') %>" alt="<%= defaultFlag.icon %>" alt="<%= defaultFlag.icon %>" /> <%= defaultFlag.name %>
3434
</a>
3535
</li>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hexo-theme-webstack",
3-
"version": "2.0.8",
3+
"version": "2.1.0",
44
"description": "A hexo theme based on webstack.",
55
"keywords": [
66
"hexo",

source/js/footer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $(document).ready(function () {
1414
} else {
1515
$('.has-sub ul').each(function (id, ele) {
1616
var _that = $(this)
17-
if (_this.find('ul')[0] != ele) {
17+
if (_this.find('ul')[0] != ele && !expandAll) {
1818
setTimeout(function () {
1919
_that.attr("style", "")
2020
}, 300);

source/js/xenon-custom.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)