hexo-theme-stellar 1.24.1 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/_config.yml +122 -50
  2. package/_data/icons.yml +33 -0
  3. package/_data/widgets.yml +2 -16
  4. package/languages/en.yml +2 -1
  5. package/languages/zh-CN.yml +3 -2
  6. package/languages/zh-TW.yml +3 -2
  7. package/layout/404.ejs +2 -4
  8. package/layout/_partial/cover/index.ejs +5 -5
  9. package/layout/_partial/cover/post_cover.ejs +1 -1
  10. package/layout/_partial/cover/wiki_cover.ejs +2 -2
  11. package/layout/_partial/head.ejs +6 -9
  12. package/layout/_partial/main/article/article_footer.ejs +16 -24
  13. package/layout/_partial/main/article/read_next.ejs +13 -13
  14. package/layout/_partial/main/article/related_posts.ejs +1 -1
  15. package/layout/_partial/main/footer.ejs +1 -1
  16. package/layout/_partial/main/navbar/article_top_area.ejs +35 -0
  17. package/layout/_partial/main/navbar/author_banner.ejs +1 -3
  18. package/layout/_partial/main/navbar/breadcrumb/blog.ejs +34 -0
  19. package/layout/_partial/main/navbar/breadcrumb/page.ejs +10 -0
  20. package/layout/_partial/main/navbar/breadcrumb/wiki.ejs +20 -0
  21. package/layout/_partial/main/navbar/dateinfo.ejs +32 -0
  22. package/layout/_partial/main/navbar/ghinfo.ejs +25 -0
  23. package/layout/_partial/main/navbar/{list_post.ejs → nav_tabs_blog.ejs} +15 -7
  24. package/layout/_partial/main/navbar/{list_wiki.ejs → nav_tabs_wiki.ejs} +15 -1
  25. package/layout/_partial/main/post_list/paginator.ejs +1 -1
  26. package/layout/_partial/main/post_list/post_card.ejs +4 -15
  27. package/layout/_partial/main/post_list/topic_card.ejs +16 -0
  28. package/layout/_partial/menubtn.ejs +1 -1
  29. package/layout/_partial/plugins/ai/tianli_gpt.ejs +4 -3
  30. package/layout/_partial/plugins/comments/artalk/layout.ejs +1 -1
  31. package/layout/_partial/plugins/comments/artalk/script.ejs +1 -1
  32. package/layout/_partial/plugins/comments/beaudar/layout.ejs +1 -1
  33. package/layout/_partial/plugins/comments/giscus/layout.ejs +1 -1
  34. package/layout/_partial/plugins/comments/layout.ejs +3 -3
  35. package/layout/_partial/plugins/comments/twikoo/layout.ejs +1 -1
  36. package/layout/_partial/plugins/comments/utterances/layout.ejs +1 -1
  37. package/layout/_partial/plugins/comments/waline/layout.ejs +1 -1
  38. package/layout/_partial/sidebar/index.ejs +92 -83
  39. package/layout/_partial/sidebar/logo.ejs +87 -0
  40. package/layout/_partial/sidebar/menu.ejs +23 -18
  41. package/layout/_partial/sidebar/search.ejs +42 -0
  42. package/layout/_partial/widgets/components/link.ejs +21 -0
  43. package/layout/_partial/widgets/components/linklist.ejs +27 -0
  44. package/layout/_partial/widgets/ghissues.ejs +7 -9
  45. package/layout/_partial/widgets/ghrepo.ejs +10 -12
  46. package/layout/_partial/widgets/ghuser.ejs +2 -6
  47. package/layout/_partial/widgets/linklist.ejs +17 -0
  48. package/layout/_partial/widgets/markdown.ejs +5 -2
  49. package/layout/_partial/widgets/recent.ejs +12 -8
  50. package/layout/_partial/widgets/related.ejs +51 -20
  51. package/layout/_partial/widgets/search.ejs +0 -40
  52. package/layout/_partial/widgets/tagcloud.ejs +2 -2
  53. package/layout/_partial/widgets/timeline.ejs +2 -2
  54. package/layout/_partial/widgets/toc.ejs +61 -53
  55. package/layout/archive.ejs +3 -3
  56. package/layout/categories.ejs +2 -2
  57. package/layout/index.ejs +10 -62
  58. package/layout/index_topic.ejs +28 -0
  59. package/layout/index_wiki.ejs +42 -0
  60. package/layout/layout.ejs +53 -21
  61. package/layout/page.ejs +60 -13
  62. package/layout/tags.ejs +2 -2
  63. package/package.json +2 -2
  64. package/scripts/events/index.js +5 -0
  65. package/scripts/events/lib/authors.js +1 -1
  66. package/scripts/events/lib/config.js +28 -24
  67. package/scripts/events/lib/doc_tree.js +27 -19
  68. package/scripts/events/lib/merge_posts.js +46 -0
  69. package/scripts/events/lib/topic_tree.js +45 -0
  70. package/scripts/generators/404.js +8 -3
  71. package/scripts/generators/author.js +4 -2
  72. package/scripts/generators/categories.js +4 -4
  73. package/scripts/generators/tags.js +4 -4
  74. package/scripts/generators/topic.js +21 -0
  75. package/scripts/generators/wiki.js +30 -28
  76. package/scripts/helpers/category_color.js +1 -1
  77. package/scripts/helpers/icon.js +16 -0
  78. package/scripts/helpers/parse_config.js +20 -18
  79. package/scripts/helpers/scrollreveal.js +6 -6
  80. package/scripts/tags/lib/audio.js +9 -4
  81. package/scripts/tags/lib/navbar.js +1 -1
  82. package/scripts/tags/lib/toc.js +1 -1
  83. package/scripts/tags/lib/video.js +8 -8
  84. package/source/css/_common/blur.styl +5 -9
  85. package/source/css/_common/cap.styl +1 -1
  86. package/source/css/_common/device.styl +2 -2
  87. package/source/css/_common/highlight.styl +3 -2
  88. package/source/css/_common/layout.styl +6 -0
  89. package/source/css/_common/svg.styl +3 -0
  90. package/source/css/_custom.styl +9 -2
  91. package/source/css/_defines/theme.styl +10 -0
  92. package/source/css/_layout/layout.styl +17 -4
  93. package/source/css/_layout/list.styl +5 -2
  94. package/source/css/_layout/main.styl +5 -4
  95. package/source/css/_layout/md.styl +12 -11
  96. package/source/css/_layout/partial/paginator.styl +2 -2
  97. package/source/css/_layout/partial/related.styl +3 -0
  98. package/source/css/_layout/sidebar/footer.styl +4 -31
  99. package/source/css/_layout/sidebar/{header.styl → logo.styl} +11 -41
  100. package/source/css/_layout/sidebar/menu.styl +53 -0
  101. package/source/css/_layout/sidebar/nav-area.styl +2 -0
  102. package/source/css/_layout/sidebar/search.styl +106 -0
  103. package/source/css/_layout/sidebar/sidebar.styl +21 -31
  104. package/source/css/_layout/tag-plugins/banner.styl +9 -7
  105. package/source/css/_layout/tag-plugins/frame.styl +1 -1
  106. package/source/css/_layout/tag-plugins/okr.styl +0 -1
  107. package/source/css/_layout/tag-plugins/tabs.styl +2 -2
  108. package/source/css/_layout/tag-plugins/toc.styl +1 -1
  109. package/source/css/_layout/widgets/components.styl +49 -0
  110. package/source/css/_layout/widgets/ghrepo.styl +0 -1
  111. package/source/css/_layout/widgets/ghuser.styl +0 -23
  112. package/source/css/_layout/widgets/list.styl +28 -0
  113. package/source/css/_layout/widgets/markdown.styl +20 -0
  114. package/source/css/_layout/widgets/related.styl +36 -5
  115. package/source/css/_layout/widgets/timeline.styl +21 -2
  116. package/source/css/_layout/widgets/toc_blog.styl +1 -1
  117. package/source/css/_layout/widgets/toc_common.styl +12 -12
  118. package/source/css/_layout/widgets/toc_wiki.styl +38 -25
  119. package/source/css/_layout/widgets/widgets.styl +25 -20
  120. package/source/css/_plugins/comments/twikoo.styl +9 -9
  121. package/source/css/_plugins/scrollreveal.styl +1 -1
  122. package/source/css/_plugins/tianli_gpt.styl +12 -14
  123. package/source/js/main.js +5 -2
  124. package/source/js/plugins/copycode.js +3 -3
  125. package/source/js/plugins/fcircle.js +1 -1
  126. package/source/js/plugins/friends.js +1 -1
  127. package/source/js/plugins/memos.js +1 -1
  128. package/source/js/plugins/sites.js +2 -2
  129. package/source/js/plugins/weibo.js +1 -1
  130. package/layout/_partial/main/header/index.ejs +0 -3
  131. package/layout/_partial/main/navbar/breadcrumb.ejs +0 -139
  132. package/layout/_partial/sidebar/header.ejs +0 -59
  133. package/layout/post.ejs +0 -33
  134. package/layout/wiki.ejs +0 -43
  135. package/source/css/_layout/widgets/recent.styl +0 -15
  136. package/source/css/_layout/widgets/search.styl +0 -102
package/layout/page.ejs CHANGED
@@ -1,28 +1,75 @@
1
1
  <%
2
+ const { layout } = page
3
+ // 是否使用 Heti 布局插件
4
+ const isUsingHeti = theme.plugins.heti && theme.plugins.heti.enable
5
+ // 是否使用 TianliGPT 插件
6
+ const isUsingTianliGPT = theme.plugins.tianli_gpt.enable && ['all', page.layout].includes(theme.plugins.tianli_gpt.field)
7
+
8
+ // 默认的 menu_id
9
+ if (page.menu_id == null) {
10
+ if (page.wiki?.length > 0) {
11
+ page.menu_id = theme.site_tree.wiki.menu_id
12
+ } else if (page.topic?.length > 0) {
13
+ page.menu_id = theme.site_tree.topic.menu_id
14
+ } else {
15
+ page.menu_id = theme.site_tree.post.menu_id
16
+ }
17
+ }
18
+ // 默认的 title
19
+ if (page.title == null) {
20
+ if (page.wiki) {
21
+ page.title = __('btn.wiki')
22
+ }
23
+ }
24
+
2
25
  function layoutTitle() {
3
- const title = page.h1 != null ? page.h1 : page.title;
26
+ const title = page.h1 != null ? page.h1 : page.title
4
27
  if (title && title.length > 0) {
5
- return '<h1 class="article-title"><span>' + title + '</span></h1>';
28
+ return `<h1 class="article-title"><span>${title}</span></h1>`
6
29
  } else {
7
- return '';
30
+ return ''
31
+ }
32
+ }
33
+
34
+ function articleClass() {
35
+ var str = `md-text content${scrollreveal(' ')}`
36
+ if (isUsingHeti) {
37
+ str += ' heti'
8
38
  }
39
+ if (isUsingTianliGPT) {
40
+ str += ' '
41
+ }
42
+ return str
9
43
  }
44
+
10
45
  function layoutDiv() {
11
- var el = '';
12
- if (page.post_list) {
13
- el += partial('_partial/main/navbar/list_post');
46
+ var el = ''
47
+ if (page.nav_tabs) {
48
+ el += partial('_partial/main/navbar/nav_tabs_blog')
14
49
  }
15
50
  if (page.h1 || page.title || (page.content && page.content.length > 0)) {
16
- el += partial('_partial/main/navbar/breadcrumb');
51
+ el += partial('_partial/main/navbar/article_top_area')
17
52
  }
18
- el += '<article class="md-text content ' + page.layout + (page.indent ? ' indent' : '') + scrollreveal() + '">';
19
- el += layoutTitle();
53
+ el += `<article class="${articleClass()}">`
54
+ el += layoutTitle()
20
55
  if (page.content && page.content.length > 0) {
21
- el += page.content;
56
+ el += page.content
57
+ }
58
+ if (layout === 'post') {
59
+ el += partial('_partial/main/article/article_footer')
60
+ }
61
+ el += `</article>`
62
+ if (layout === 'post' || page.wiki) {
63
+ el += partial('_partial/main/article/read_next')
64
+ }
65
+ if (isUsingTianliGPT) {
66
+ el += partial('_partial/plugins/ai/tianli_gpt')
67
+ }
68
+ if (layout === 'post') {
69
+ el += partial('_partial/main/article/related_posts')
22
70
  }
23
- el += '</article>';
24
- el += partial('_partial/plugins/comments/layout');
25
- return el;
71
+ el += partial('_partial/plugins/comments/layout')
72
+ return el
26
73
  }
27
74
  %>
28
75
 
package/layout/tags.ejs CHANGED
@@ -7,9 +7,9 @@ if (page.menu_id == undefined) {
7
7
  <% if (site.tags.length) { %>
8
8
  <% page.title = __('btn.tags'); %>
9
9
  <% page.layout = 'tags'; %>
10
- <%- partial('_partial/main/navbar/list_post') %>
10
+ <%- partial('_partial/main/navbar/nav_tabs_blog') %>
11
11
  <div class='post-list'>
12
- <article class='<%- scrollreveal() %>' id='tags'>
12
+ <article class='<%- scrollreveal("") %>' id='tags'>
13
13
  <% site.tags.sort('length', -1).each(function(tag){ %>
14
14
  <a class='tag' href="<%= url_for(tag.path) %>">
15
15
  <span class='name'><%= tag.name %></span>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-theme-stellar",
3
- "version": "1.24.1",
3
+ "version": "1.26.0",
4
4
  "description": "Elegant and powerful theme for Hexo.",
5
5
  "main": "package.json",
6
6
  "scripts": {
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "hexo-renderer-ejs": "^2.0.0",
25
- "hexo-renderer-stylus": "^2.1.0"
25
+ "hexo-renderer-stylus": "^3.0.1"
26
26
  },
27
27
  "homepage": "https://xaoxuu.com/wiki/stellar/",
28
28
  "devDependencies": {
@@ -8,9 +8,14 @@ hexo.on('generateBefore', () => {
8
8
  require('./lib/links')(hexo);
9
9
  require('./lib/authors')(hexo);
10
10
  require('./lib/doc_tree')(hexo);
11
+ require('./lib/topic_tree')(hexo);
11
12
  require('./lib/utils')(hexo);
12
13
  });
13
14
 
15
+ hexo.on('generateAfter', () => {
16
+ require('./lib/merge_posts')(hexo);
17
+ });
18
+
14
19
  hexo.on('ready', () => {
15
20
  const { version, homepage, repository } = require('../../package.json');
16
21
  hexo.log.info(`Welcome to Stellar ${version}
@@ -6,7 +6,7 @@
6
6
 
7
7
  module.exports = ctx => {
8
8
  var authors = ctx.locals.get('data').authors || {}
9
- let basePath = ctx.config.author_dir || 'author'
9
+ let basePath = ctx.theme.config.site_tree.author.base_dir
10
10
  // url
11
11
  for (let key of Object.keys(authors)) {
12
12
  let author = authors[key]
@@ -7,57 +7,61 @@
7
7
 
8
8
  'use strict';
9
9
 
10
- const path = require('path');
10
+ const path = require('path')
11
11
 
12
- module.exports = hexo => {
12
+ module.exports = ctx => {
13
13
 
14
- const { cache, language_switcher } = hexo.theme.config;
14
+ const { cache, language_switcher } = ctx.theme.config
15
15
  const warning = function(...args) {
16
- hexo.log.warn(`Since ${args[0]} is turned on, the ${args[1]} is disabled to avoid potential hazards.`);
17
- };
16
+ ctx.log.warn(`Since ${args[0]} is turned on, the ${args[1]} is disabled to avoid potential hazards.`)
17
+ }
18
18
 
19
19
  if (cache && cache.enable && language_switcher) {
20
- warning('language_switcher', 'caching');
21
- cache.enable = false;
20
+ warning('language_switcher', 'caching')
21
+ cache.enable = false
22
22
  }
23
23
 
24
- if (cache && cache.enable && hexo.config.relative_link) {
25
- warning('caching', '`relative_link` option in Hexo `_config.yml`');
26
- hexo.config.relative_link = false;
24
+ if (cache && cache.enable && ctx.config.relative_link) {
25
+ warning('caching', '`relative_link` option in Hexo `_config.yml`')
26
+ ctx.config.relative_link = false
27
27
  }
28
- // hexo.config.meta_generator = false;
28
+ // ctx.config.meta_generator = false;
29
29
 
30
30
  // merge data
31
- const data = hexo.locals.get('data');
32
- // merge widgets
33
- var widgets = hexo.render.renderSync({ path: path.join(hexo.theme_dir, '_data/widgets.yml'), engine: 'yaml' });
31
+ const data = ctx.locals.get('data')
32
+ // merge widgets: 可覆盖删除的合并
33
+ var widgets = ctx.render.renderSync({ path: path.join(ctx.theme_dir, '_data/widgets.yml'), engine: 'yaml' })
34
34
  if (data.widgets) {
35
35
  for (let i of Object.keys(data.widgets)) {
36
- let widget = data.widgets[i];
36
+ let widget = data.widgets[i]
37
37
  if (widget == null || widget.length == 0) {
38
38
  // delete
39
- delete widgets[i];
39
+ delete widgets[i]
40
40
  } else {
41
41
  // create
42
42
  if (widgets[i] == null) {
43
- widgets[i] = widget;
43
+ widgets[i] = widget
44
44
  } else {
45
45
  // merge
46
46
  for (let j of Object.keys(widget)) {
47
- widgets[i][j] = widget[j];
47
+ widgets[i][j] = widget[j]
48
48
  }
49
49
  }
50
50
  }
51
51
  }
52
52
  }
53
- if (hexo.theme.config.data == undefined) {
54
- hexo.theme.config.data = {};
53
+ ctx.theme.config.widgets = widgets
54
+
55
+ // merge icons: 简单覆盖合并
56
+ var icons = ctx.render.renderSync({ path: path.join(ctx.theme_dir, '_data/icons.yml'), engine: 'yaml' })
57
+ if (data.icons) {
58
+ icons = Object.assign({}, icons, data.icons)
55
59
  }
56
- hexo.theme.config.data['widgets'] = widgets;
60
+ ctx.theme.config.icons = icons
57
61
 
58
62
  // default menu
59
- if (hexo.theme.config.sidebar.menu == undefined) {
60
- hexo.theme.config.sidebar.menu = [];
63
+ if (ctx.theme.config.menubar == undefined) {
64
+ ctx.theme.config.menubar = {}
61
65
  }
62
66
 
63
- };
67
+ }
@@ -9,7 +9,6 @@ class WikiPage {
9
9
  this.id = page._id
10
10
  this.wiki = page.wiki
11
11
  this.title = page.title
12
- this.seo_title = page.seo_title
13
12
  this.path = page.path
14
13
  this.path_key = page.path.replace('.html', '')
15
14
  this.layout = page.layout
@@ -35,11 +34,15 @@ function getWikiObject(ctx) {
35
34
  if (obj.sort == null) {
36
35
  obj.sort = 0
37
36
  }
38
- if (obj.path?.startsWith('/')) {
39
- obj.path = obj.path.substring(1)
40
- }
41
- if (obj.path?.endsWith('/') == false) {
42
- obj.path = obj.path + '/'
37
+ if (obj.base_dir) {
38
+ if (obj.base_dir.startsWith('/')) {
39
+ obj.base_dir = obj.base_dir.substring(1)
40
+ }
41
+ if (obj.base_dir.length > 1 && obj.base_dir.endsWith('/') == false) {
42
+ obj.base_dir = obj.base_dir + '/'
43
+ }
44
+ } else {
45
+ obj.base_dir = ''
43
46
  }
44
47
  list.push(obj)
45
48
  }
@@ -56,7 +59,7 @@ module.exports = ctx => {
56
59
  var wiki = getWikiObject(ctx)
57
60
  const pages = ctx.locals.get('pages')
58
61
  // wiki 所有页面
59
- const wiki_pages = pages.filter(p => (p.layout === 'wiki')).map(p => new WikiPage(p))
62
+ const wiki_pages = pages.filter(p => (p.wiki != null)).map(p => new WikiPage(p))
60
63
  const wiki_list = Object.keys(wiki.tree)
61
64
  // 上架的项目列表
62
65
  wiki.shelf = ctx.locals.get('data').wiki || []
@@ -101,25 +104,30 @@ module.exports = ctx => {
101
104
 
102
105
  // 首页
103
106
  // 未特别指定首页时,获取TOC第一页作为首页
104
- if (item.homepage == null && item.toc != null) {
107
+ var homepage = item.homepage
108
+ if (homepage == null && item.toc != null) {
105
109
  for (let id of Object.keys(item.toc)) {
106
110
  const sec = item.toc[id]
107
111
  for (let key of sec) {
108
- let hs = sub_pages.filter(p => p.path_key == item.path + key)
112
+ let hs = sub_pages.filter(p => p.path_key == item.base_dir + key)
109
113
  if (hs.length > 0) {
110
- item.homepage = hs[0]
114
+ homepage = hs[0]
111
115
  break
112
116
  }
113
117
  }
114
- if (item.homepage != null) {
118
+ if (homepage != null) {
115
119
  break
116
120
  }
117
121
  }
118
122
  }
119
- if (item.homepage == null) {
120
- item.homepage = sub_pages[0]
123
+ if (homepage == null) {
124
+ homepage = sub_pages[0]
125
+ }
126
+ if (typeof homepage == 'string') {
127
+ homepage = {path: homepage}
121
128
  }
122
- item.homepage.is_homepage = true
129
+ homepage.is_homepage = true
130
+ item.homepage = homepage
123
131
  // 内页分组
124
132
  var sections = []
125
133
  var others = sub_pages
@@ -128,21 +136,21 @@ module.exports = ctx => {
128
136
  for (let title of Object.keys(item.toc)) {
129
137
  var sec = { title: title, pages: []}
130
138
  for (let key of item.toc[title]) {
131
- sec.pages = sec.pages.concat(sub_pages.filter(p => p.path_key == item.path + key))
132
- others = others.filter(p => p.path_key != item.path + key)
139
+ sec.pages = sec.pages.concat(sub_pages.filter(p => p.path_key == item.base_dir + key))
140
+ others = others.filter(p => p.path_key != item.base_dir + key)
133
141
  }
134
142
  sections.push(sec)
135
143
  }
136
144
  if (others.length > 0 && others.filter(p => p.title?.length > 0).length > 0) {
137
145
  sections.push({
138
146
  title: '...',
139
- pages: others.sort((p1, p2) => p1.path - p2.path)
147
+ pages: others.sort((p1, p2) => p1.title - p2.title)
140
148
  })
141
149
  }
142
150
  } else {
143
151
  // 自动设置顺序
144
152
  sections.push({
145
- pages: sub_pages.sort((p1, p2) => p1.path - p2.path)
153
+ pages: sub_pages.sort((p1, p2) => p1.title - p2.title)
146
154
  })
147
155
  }
148
156
 
@@ -177,7 +185,7 @@ module.exports = ctx => {
177
185
  }
178
186
  all_tags[tag_name] = {
179
187
  name: tag_name,
180
- path: (ctx.config.wiki_dir || 'wiki') + '/tags/' + tag_name + '/index.html',
188
+ path: (ctx.theme.config.site_tree.index_wiki.base_dir) + '/tags/' + tag_name + '/index.html',
181
189
  items: items
182
190
  }
183
191
  })
@@ -0,0 +1,46 @@
1
+ /**
2
+ * merge_posts.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
3
+ *
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ class RelatedPage {
9
+ constructor(page) {
10
+ this.id = page._id
11
+ this.wiki = page.wiki
12
+ this.topic = page.topic
13
+ this.title = page.title
14
+ this.path = page.path
15
+ this.path_key = page.path.replace('.html', '')
16
+ this.layout = page.layout
17
+ this.date = page.date
18
+ this.updated = page.updated
19
+ }
20
+ }
21
+
22
+ module.exports = ctx => {
23
+ var topic = ctx.theme.config.topic
24
+ const posts = ctx.locals.get('posts')
25
+ posts.sort('date').each(function(post) {
26
+ let obj = new RelatedPage(post)
27
+ // 合并拥有共同 topic 的文章到 topic.tree
28
+ if (post.topic?.length > 0) {
29
+ var topicObject = topic.tree[post.topic]
30
+ if (topicObject) {
31
+ obj.page_number = topicObject.pages.length + 1
32
+ topicObject.pages.push(obj)
33
+ }
34
+ }
35
+ })
36
+
37
+ // topic homepage
38
+ for (let tid of Object.keys(topic.tree)) {
39
+ let topicObject = topic.tree[tid]
40
+ if (topicObject.order_by == '-date') {
41
+ topicObject.pages = topicObject.pages.reverse()
42
+ }
43
+ topicObject.homepage = topicObject.pages[0]
44
+ }
45
+
46
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * topic.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
3
+ * 用于专栏/专题文章,一个专栏类似于 wiki 模块中的一个项目文档
4
+ * 区别是:
5
+ * 1. 按发布日期排序,无需手动排序
6
+ *
7
+ */
8
+
9
+ 'use strict';
10
+
11
+ function getTopicTree(ctx) {
12
+ var tree = {}
13
+ const data = ctx.locals.get('data')
14
+ var list = []
15
+ for (let key of Object.keys(data)) {
16
+ if (key.startsWith('topic/') && key.length > 5) {
17
+ let newKey = key.replace('topic/', '')
18
+ let obj = data[key]
19
+ obj.id = newKey
20
+ if (obj.order_by == null) {
21
+ obj.order_by = '-date'
22
+ }
23
+ if (obj.path == null) {
24
+ obj.path = `/topic/${newKey}/`
25
+ }
26
+ obj.pages = []
27
+ list.push(obj)
28
+ }
29
+ }
30
+ for (let item of list) {
31
+ tree[item.id] = item
32
+ }
33
+ return tree
34
+ }
35
+
36
+ module.exports = ctx => {
37
+ var topic = ctx.locals.get('data').topic || {}
38
+ // 专栏结构树
39
+ topic.tree = getTopicTree(ctx)
40
+ // 索引页显示的专栏列表
41
+ if (topic.publish_list == null) {
42
+ topic.publish_list = Object.keys(topic.tree)
43
+ }
44
+ ctx.theme.config.topic = topic
45
+ }
@@ -3,8 +3,13 @@
3
3
  */
4
4
 
5
5
  hexo.extend.generator.register('404', function (locals) {
6
+ const { site_tree } = hexo.theme.config
6
7
  return {
7
- path: '/404.html',
8
- layout: ['404']
8
+ path: site_tree.error_page['404'],
9
+ layout: ['404'],
10
+ data: {
11
+ layout: '404',
12
+ menu_id: site_tree.error_page.menu_id
13
+ }
9
14
  }
10
- });
15
+ })
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  hexo.extend.generator.register('author', function (locals) {
6
- const { authors } = hexo.theme.config
6
+ const { site_tree, authors } = hexo.theme.config
7
7
  var pages = []
8
8
  for (let key of Object.keys(authors)) {
9
9
  const author = authors[key]
@@ -14,7 +14,9 @@ hexo.extend.generator.register('author', function (locals) {
14
14
  path: author.path,
15
15
  layout: ['archive'],
16
16
  data: {
17
- 'author': author
17
+ author: author,
18
+ sidebar: site_tree.author.sidebar,
19
+ menu_id: site_tree.author.menu_id
18
20
  }
19
21
  })
20
22
  }
@@ -6,10 +6,10 @@ hexo.extend.generator.register('categories', function (locals) {
6
6
  if (locals.categories && locals.categories.length > 0) {
7
7
  return {
8
8
  path: hexo.config.category_dir + '/index.html',
9
- data: locals.posts,
10
- layout: ['categories']
9
+ layout: ['categories'],
10
+ data: locals.posts
11
11
  }
12
12
  } else {
13
- return {};
13
+ return {}
14
14
  }
15
- });
15
+ })
@@ -6,10 +6,10 @@ hexo.extend.generator.register('tags', function (locals) {
6
6
  if (locals.tags && locals.tags.length > 0) {
7
7
  return {
8
8
  path: hexo.config.tag_dir + '/index.html',
9
- data: locals.posts,
10
- layout: ['tags']
9
+ layout: ['tags'],
10
+ data: locals.posts
11
11
  }
12
12
  } else {
13
- return {};
13
+ return {}
14
14
  }
15
- });
15
+ })
@@ -0,0 +1,21 @@
1
+ /**
2
+ * topic v1 | https://github.com/xaoxuu/hexo-theme-stellar/
3
+ */
4
+
5
+ hexo.extend.generator.register('index_topic', function (locals) {
6
+ const { site_tree, topic } = hexo.theme.config
7
+ const topicIdList = Object.keys(topic.tree)
8
+ if (topicIdList.length == 0) {
9
+ return {}
10
+ }
11
+ var ret = []
12
+ ret.push({
13
+ path: site_tree.index_topic.base_dir + '/index.html',
14
+ layout: ['index_topic'],
15
+ data: {
16
+ layout: 'index_topic',
17
+ menu_id: site_tree.index_topic.menu_id
18
+ }
19
+ })
20
+ return ret
21
+ })
@@ -3,34 +3,36 @@
3
3
  */
4
4
 
5
5
  hexo.extend.generator.register('wiki', function (locals) {
6
- var hasWiki = false;
7
- locals.pages.forEach((page, i) => {
8
- if (page.layout == 'wiki') {
9
- hasWiki = true;
6
+ const { site_tree, wiki } = hexo.theme.config
7
+ const wikiIdList = Object.keys(wiki.tree)
8
+ if (wikiIdList.length == 0) {
9
+ return {}
10
+ }
11
+ var ret = []
12
+ ret.push({
13
+ path: site_tree.index_wiki.base_dir + '/index.html',
14
+ layout: ['index_wiki'],
15
+ data: {
16
+ layout: 'index_wiki',
17
+ menu_id: site_tree.index_wiki.menu_id,
18
+ filter: false
10
19
  }
11
- });
12
- if (hasWiki) {
13
- var ret = [];
14
- ret.push({
15
- path: (hexo.config.wiki_dir || 'wiki') + '/index.html',
16
- data: {'filter': false},
17
- layout: ['wiki']
18
- });
19
- if (hexo.theme.config.wiki && hexo.theme.config.wiki.all_tags) {
20
- for (let id of Object.keys(hexo.theme.config.wiki.all_tags)) {
21
- let tag = hexo.theme.config.wiki.all_tags[id];
22
- ret.push({
23
- path: tag.path,
24
- data: {
25
- 'filter': true,
26
- 'tagName': tag.name
27
- },
28
- layout: ['wiki']
29
- });
30
- }
20
+ })
21
+ if (wiki.all_tags) {
22
+ for (let id of Object.keys(wiki.all_tags)) {
23
+ let tag = wiki.all_tags[id]
24
+ ret.push({
25
+ path: tag.path,
26
+ layout: ['index_wiki'],
27
+ data: {
28
+ layout: 'index_wiki',
29
+ menu_id: site_tree.index_wiki.menu_id,
30
+ filter: true,
31
+ tagName: tag.name,
32
+ title: tag.name
33
+ }
34
+ })
31
35
  }
32
- return ret;
33
- } else {
34
- return {};
35
36
  }
36
- });
37
+ return ret
38
+ })
@@ -16,7 +16,7 @@ hexo.extend.helper.register('category_color', function(cat){
16
16
  } else if (textColor.length == (1+6)) { // #ffffff
17
17
  bgColor += '20'
18
18
  }
19
- return ` style="--text-p3:${textColor};--theme-block:${bgColor}"`;
19
+ return ` style="--text-p2:${textColor};--theme-block:${bgColor}"`;
20
20
  }
21
21
  return ''
22
22
  })
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ hexo.extend.helper.register('icon', function(key) {
4
+ const { icons } = hexo.theme.config
5
+ var result = ''
6
+ if (icons[key]) {
7
+ result = icons[key]
8
+ } else {
9
+ result = key
10
+ }
11
+ if (result.startsWith('/') || result.startsWith('https://') || result.startsWith('http://')) {
12
+ return `<img src="${result}" />`
13
+ } else {
14
+ return result
15
+ }
16
+ })