Skip to content

Commit 45bc01d

Browse files
committed
添加子页面
1 parent 1ead276 commit 45bc01d

File tree

12 files changed

+233
-76
lines changed

12 files changed

+233
-76
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
.vscode
3+
.history

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,17 @@ hotTools:
299299
```
300300

301301
Either of the above two methods can be selected. The second method is recommended.
302+
303+
## Subpage configuration
304+
305+
### Create subpage
306+
307+
Use `hexo new page xxx` to create a child page, including the following descriptions, using `hexo new page child` as an example.
308+
309+
### Modify the subpage configuration file
310+
311+
After using the above command to generate the subpage, open the `root directory/source/child/index.md` file (subpage configuration file), and add a line `type:'child'` between the two `---` This configuration file takes effect. The sub-page uses the configuration of the homepage by default, and the sub-page preferentially uses the configuration between the two `---` sub-page configuration files. Each configuration item has the same configuration function as the homepage.
312+
313+
See the example[https://github.com/HCLonely/hexo-theme-webstack/tree/gh-pages/source/child/index.md](https://github.com/HCLonely/hexo-theme-webstack/tree/gh-pages/source/child/index.md)
314+
315+
> Since the subpage was basically completed a long time ago, it was later put on hold when it was busy. There may be some configuration or bugs that have been forgotten. If you have any questions, please feedback in time!

README_CN.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,17 @@ hotTools:
299299
> 以上两种方式任选一种即可,建议使用第二种。
300300

301301
[配置详情](https://blog.hclonely.com/posts/3cd4fb34/)
302+
303+
## 子页面配置
304+
305+
### 创建子页面
306+
307+
使用`hexo new page xxx`创建子页面,这里包括下面的说明都以`hexo new page child`为例。
308+
309+
### 修改子页面配置文件
310+
311+
使用上面的命令生成子页面后,打开`根目录/source/child/index.md`文件(子页面配置文件),在两个`---`之间添加一行`type: 'child'`使此配置文件生效,子页面默认使用主页的配置,子页面优先使用子页面配置文件两个`---`之间的配置,各配置项和主页的配置功能相同。
312+
313+
示例请看[https://github.com/HCLonely/hexo-theme-webstack/tree/gh-pages/source/child/index.md](https://github.com/HCLonely/hexo-theme-webstack/tree/gh-pages/source/child/index.md)
314+
315+
> 由于子页面在很久之前就基本做完了,后来比较忙就鸽了,可能有些配置或 bug 给忘了,有问题请及时反馈!

_config.yml

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ search: true
1515
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>'
1616

1717
menu:
18+
- name: 测试页面
19+
icon: far fa-star
20+
config: testPage
1821
- name: 常用工具
1922
icon: far fa-star
2023
config: hotTools
@@ -28,6 +31,11 @@ menu:
2831
icon: fas fa-blog
2932
config: myBlog
3033

34+
testPage:
35+
- name: Child Page
36+
url: /child
37+
img: /images/logos/myblog.png
38+
description: 子页面测试
3139
devTools:
3240
- name: Github
3341
url: https://github.com/
@@ -37,24 +45,6 @@ devTools:
3745
url: https://github.com/
3846
img: /images/logos/github.png
3947
description: 面向开源及私有软件项目的托管平台。
40-
- name: Github
41-
url: https://github.com/
42-
img: /images/logos/github.png
43-
description: 面向开源及私有软件项目的托管平台。
44-
45-
hotTools:
46-
- name: Github
47-
url: https://github.com/
48-
img: /images/logos/github.png
49-
description: 面向开源及私有软件项目的托管平台。
50-
- name: Github
51-
url: https://github.com/
52-
img: /images/logos/github.png
53-
description: 面向开源及私有软件项目的托管平台。
54-
- name: Github
55-
url: https://github.com/
56-
img: /images/logos/github.png
57-
description: 面向开源及私有软件项目的托管平台。
5848

5949
myBlog:
6050
- name: HCLonely Blog

layout/common/footer.ejs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<!-- Add your copyright text here -->
44
<p>
55
<% var now = new Date().getFullYear(); %>
6-
&copy; <%- theme.since === now ? theme.since : (theme.since + " - " + now) %>
6+
&copy; <%- setting.since === now ? setting.since : (setting.since + " - " + now) %>
77
<a href="javascript:void(0);"><strong><%- config.author %></strong></a> | Design by <a href="http://viggoz.com" target="_blank"><strong>Viggo</strong></a> | Power by <a href="https://hexo.io/" target="_blank"><strong>Hexo</strong></a> & <a href="https://github.com/HCLonely/hexo-theme-webstack/" target="_blank"><strong>hexo-theme-webstack</strong></a>
88
</p>
9-
<% if (theme.busuanzi.enable && theme.busuanzi.position === 'footer') { %>
9+
<% if (setting.busuanzi.enable && setting.busuanzi.position === 'footer') { %>
1010
<p>
11-
<span id="busuanzi_container_site_pv"><%- theme.busuanzi.pv.replace(/\$pv/i,'<span id="busuanzi_value_site_pv"></span>') %></span> |
12-
<span id="busuanzi_container_site_uv"><%- theme.busuanzi.uv.replace(/\$uv/i,'<span id="busuanzi_value_site_uv"></span>') %></span>
11+
<span id="busuanzi_container_site_pv"><%- setting.busuanzi.pv.replace(/\$pv/i,'<span id="busuanzi_value_site_pv"></span>') %></span> |
12+
<span id="busuanzi_container_site_uv"><%- setting.busuanzi.uv.replace(/\$uv/i,'<span id="busuanzi_value_site_uv"></span>') %></span>
1313
</p>
1414
<% } %>
1515
<div class="go-up">
@@ -21,12 +21,12 @@
2121
</footer>
2222
</div>
2323
</div>
24-
<%- js([theme.js.bootstrap, theme.js.TweenMax, theme.js.resizeable, theme.js.joinable, theme.js.xenonApi, theme.js.xenonToggles, theme.js.xenonCustom]) %>
25-
<% if (theme.busuanzi.enable) { %>
26-
<script async src="<%- theme.js.busuanzi %>"></script>
24+
<%- js([setting.js.bootstrap, setting.js.TweenMax, setting.js.resizeable, setting.js.joinable, setting.js.xenonApi, setting.js.xenonToggles, setting.js.xenonCustom]) %>
25+
<% if (setting.busuanzi.enable) { %>
26+
<script async src="<%- setting.js.busuanzi %>"></script>
2727
<% } %>
28-
<% if (is_home()) { %>
29-
<%- js(theme.js.lozad) %>
28+
<% if (setting.type!=="about") { %>
29+
<%- js(setting.js.lozad) %>
3030
<% } else { %>
3131
<textarea tabindex="-1" style="position: absolute; top: -999px; left: 0px; right: auto; bottom: auto; border: 0px; padding: 0px; box-sizing: content-box; word-wrap: break-word; overflow: hidden; transition: none; height: 0px !important; min-height: 0px !important; font-family: Arimo, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: 400; font-style: normal; letter-spacing: 0px; text-transform: none; word-spacing: 0px; text-indent: 0px; line-height: 18.5714px; width: 53px;" class="autosizejs" id="autosizejs"></textarea>
3232
<% } %>

layout/common/head.ejs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@
33
<meta http-equiv="X-UA-Compatible" content="IE=edge">
44
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
55
<meta name="author" content="viggo" />
6-
<title><%= config.title %> - <%= config.subtitle %></title>
7-
<meta name="keywords" content="<%= config.keywords %>">
8-
<meta name="description" content="<%= config.description %>">
9-
<link rel="shortcut icon" href="<%= theme.favicon %>">
10-
<%- css(Object.values(theme.css)) %>
11-
<%- js(theme.js.jquery) %>
12-
<%- js(theme.js.header) %>
6+
<title><%= setting.tittle || config.title %> - <%= setting.subtitle || config.subtitle %></title>
7+
<meta name="keywords" content="<%= setting.keywords || config.keywords %>">
8+
<meta name="description" content="<%= setting.description || config.description %>">
9+
<link rel="shortcut icon" href="<%= setting.favicon %>">
10+
<%- css(Object.values(setting.css)) %>
11+
<%- js(setting.js.jquery) %>
12+
<%- js(setting.js.header) %>
1313
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
1414
<!--[if lt IE 9]>
15-
<%- js(theme.js.html5shiv) %>
16-
<%- js(theme.js.respond) %>
15+
<%- js(setting.js.html5shiv) %>
16+
<%- js(setting.js.respond) %>
1717
<![endif]-->
1818
<!-- / FB Open Graph -->
1919
<meta property="og:type" content="article">
2020
<meta property="og:url" content="<%= url %>">
21-
<meta property="og:title" content="<%= config.title %> - <%= config.subtitle %>">
22-
<meta property="og:description" content="<%= config.description %>">
23-
<meta property="og:site_name" content="<%= config.title %> - <%= config.subtitle %>">
24-
<% if (theme.banner) { %>
25-
<meta property="og:image" content="<%= theme.banner %>">
21+
<meta property="og:title" content="<%= setting.tittle || config.title %> - <%= setting.subtitle || config.subtitle %>">
22+
<meta property="og:description" content="<%= setting.description || config.description %>">
23+
<meta property="og:site_name" content="<%= setting.tittle || config.title %> - <%= setting.subtitle || config.subtitle %>">
24+
<% if (setting.banner) { %>
25+
<meta property="og:image" content="<%= setting.banner %>">
2626
<% } %>
2727
<!-- / Twitter Cards -->
2828
<meta name="twitter:card" content="summary_large_image">
29-
<meta name="twitter:title" content="<%= config.title %> - <%= config.subtitle %>">
30-
<meta name="twitter:description" content="<%= config.description %>">
31-
<% if (theme.banner) { %>
32-
<meta name="twitter:image" content="<%= theme.banner %>">
29+
<meta name="twitter:title" content="<%= setting.tittle || config.title %> - <%= setting.subtitle || config.subtitle %>">
30+
<meta name="twitter:description" content="<%= setting.description || config.description %>">
31+
<% if (setting.banner) { %>
32+
<meta name="twitter:image" content="<%= setting.banner %>">
3333
<% } %>
34-
<% if (theme.custom && theme.custom.head) { %>
35-
<%- theme.custom.head %>
34+
<% if (setting.custom && setting.custom.head) { %>
35+
<%- setting.custom.head %>
3636
<% } %>
3737
</head>

layout/common/header.ejs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<header class="logo-env">
44
<div class="logo">
55
<a href="/index.html" class="logo-expanded">
6-
<img src="<%= theme.logo.expanded %>" width="100%" alt="" />
6+
<img src="<%= setting.logo.expanded %>" width="100%" alt="" />
77
</a>
88
<a href="/index.html" class="logo-collapsed">
9-
<img src="<%= theme.logo.collapsed %>" width="40" alt="" />
9+
<img src="<%= setting.logo.collapsed %>" width="40" alt="" />
1010
</a>
1111
</div>
1212
<div class="mobile-menu-toggle visible-xs">
@@ -19,7 +19,7 @@
1919
</div>
2020
</header>
2121
<ul id="main-menu" class="main-menu">
22-
<% for( let e of theme.menu ) { %>
22+
<% for( let e of setting.menu ) { %>
2323
<li>
2424
<% if (e.submenu) { %>
2525
<a class="fas fa-angle-down" style="cursor: pointer;">
@@ -43,25 +43,25 @@
4343
<% } %>
4444
</li>
4545
<% } %>
46-
<% if (theme.about) { %>
46+
<% if (setting.about) { %>
4747
<li class="submit-tag">
48-
<a href="<%= url_for(theme.about.url) %>">
49-
<i class="<%= theme.about.icon %>"></i>
50-
<span class="tooltip-blue"><%= theme.about.name %></span>
48+
<a href="<%= url_for(setting.about.url) %>">
49+
<i class="<%= setting.about.icon %>"></i>
50+
<span class="tooltip-blue"><%= setting.about.name %></span>
5151
</a>
5252
</li>
5353
<% } %>
54-
<% if (theme.busuanzi.enable && theme.busuanzi.position === 'sidebar') { %>
54+
<% if (setting.busuanzi.enable && setting.busuanzi.position === 'sidebar') { %>
5555
<li>
5656
<a href="javascript:void(0)">
5757
<i class="fas fa-eye"></i>
58-
<span id="busuanzi_container_site_pv"><%- theme.busuanzi.pv.replace(/\$pv/i,'<span id="busuanzi_value_site_pv"></span>') %></span>
58+
<span id="busuanzi_container_site_pv"><%- setting.busuanzi.pv.replace(/\$pv/i,'<span id="busuanzi_value_site_pv"></span>') %></span>
5959
</a>
6060
</li>
6161
<li>
6262
<a href="javascript:void(0)">
6363
<i class="fas fa-users"></i>
64-
<span id="busuanzi_container_site_uv"><%- theme.busuanzi.uv.replace(/\$uv/i,'<span id="busuanzi_value_site_uv"></span>') %></span>
64+
<span id="busuanzi_container_site_uv"><%- setting.busuanzi.uv.replace(/\$uv/i,'<span id="busuanzi_value_site_uv"></span>') %></span>
6565
</a>
6666
</li>
6767
<% } %>

layout/index.ejs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
<% const isChildPage = page.type === 'child' %>
2+
<% const setting = isChildPage ? Object.assign(theme, page) : theme %>
3+
<% console.log(page.path) %>
14
<body class="page-body">
25
<div class="page-container">
3-
<%- partial('common/header') %>
6+
<%- partial('common/header', {setting:setting}) %>
47

58
<div class="main-content">
69
<nav class="navbar user-info-navbar" role="navigation">
@@ -12,12 +15,12 @@
1215
</li>
1316
<li class="dropdown hover-line language-switcher">
1417
<a href="/index.html" class="dropdown-toggle" data-toggle="dropdown">
15-
<img src="/images/flags/<%= theme.flag.icon %>.png" alt="<%= theme.flag.icon %>" /> <%= theme.flag.name %>
18+
<img src="/images/flags/<%= setting.flag.icon %>.png" alt="<%= setting.flag.icon %>" /> <%= setting.flag.name %>
1619
</a>
1720
<ul class="dropdown-menu languages">
1821
<li class="active">
1922
<a href="/index.html">
20-
<img src="/images/flags/<%= theme.flag.icon %>.png" alt="<%= theme.flag.icon %>" alt="<%= theme.flag.icon %>" /> <%= theme.flag.name %>
23+
<img src="/images/flags/<%= setting.flag.icon %>.png" alt="<%= setting.flag.icon %>" alt="<%= setting.flag.icon %>" /> <%= setting.flag.name %>
2124
</a>
2225
</li>
2326
</ul>
@@ -30,11 +33,11 @@
3033
</a>
3134
</li>
3235
</ul>
33-
<% if (theme.githubCorner) { %>
34-
<%- theme.githubCorner %>
36+
<% if (setting.githubCorner) { %>
37+
<%- setting.githubCorner %>
3538
<% } %>
3639
</nav>
37-
<% if(theme.search){ %>
40+
<% if(setting.search){ %>
3841
<section class="sousuo">
3942
<div class="search">
4043
<div class="search-box">
@@ -58,15 +61,23 @@
5861
</section>
5962
<script>search()</script>
6063
<% } %>
61-
<% theme.menu.forEach(function(e) { %>
64+
<% if(is_home() || isChildPage){ %>
65+
<% const menuSetting = isChildPage ? page : theme; %>
66+
<% menuSetting.menu.forEach(function(e) { %>
6267
<% if (e.submenu) { %>
6368
<% e.submenu.forEach(function(e) { %>
64-
<% var menus = site.data && site.data[e.config] ? site.data[e.config] : theme[e.config]; %>
65-
<%- partial('common/group.ejs', {e: e, menus: menus}); %>
69+
<% const childPath = page.path.replace('index.html', '') + e.config; %>
70+
<% const key = isChildPage?childPath:e.config; %>
71+
<% var menus = site.data && site.data[key] ? site.data[key] : menuSetting[e.config]; %>
72+
<%- partial('common/group.ejs', {e: e, menus: menus || []}); %>
6673
<% }) %>
6774
<% } else { %>
68-
<% var menus = site.data && site.data[e.config] ? site.data[e.config] : theme[e.config]; %>
69-
<%- partial('common/group.ejs', {e: e, menus: menus}); %>
75+
<% const childPath = page.path.replace('index.html', '') + e.config; %>
76+
<% const key = isChildPage?childPath:e.config; %>
77+
<% var menus = site.data && site.data[key] ? site.data[key] : menuSetting[e.config]; %>
78+
<% console.log(page.path,childPath,key); %>
79+
<%- partial('common/group.ejs', {e: e, menus: menus || []}); %>
7080
<% } %>
7181
<% }) %>
72-
<%- js(theme.js.footer) %>
82+
<% } %>
83+
<%- js(setting.js.footer) %>

layout/layout.ejs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<!DOCTYPE html>
22
<html lang="<%= config.language %>">
3-
3+
<% const setting = page ? Object.assign(theme, page) : theme %>
44
<head>
5-
<%- partial('common/head') %>
5+
<%- partial('common/head', {setting:setting}) %>
66
</head>
77

88
<%- body %>
9-
<%- partial('common/footer') %>
10-
<% if (theme.custom && theme.custom.body) { %>
11-
<%- theme.custom.body %>
9+
<%- partial('common/footer', {setting:setting}) %>
10+
<% if (setting.custom && setting.custom.body) { %>
11+
<%- setting.custom.body %>
1212
<% } %>
1313
</body>
1414

layout/page.ejs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
<%- partial('about') %>
1+
<% if(page.type==="about"){ %>
2+
<%- partial('about') %>
3+
<% }else if(page.type==="child"){ %>
4+
<%- partial('index') %>
5+
<% }else{ %>
6+
<% } %>

0 commit comments

Comments
 (0)