hexo-theme-stellar 1.17.1 → 1.17.2
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.
- package/_config.yml +19 -6
- package/_data/widgets.yml +11 -0
- package/layout/_partial/sidebar/index.ejs +9 -3
- package/layout/_partial/widgets/search.ejs +13 -5
- package/layout/index.ejs +1 -1
- package/layout/wiki.ejs +2 -2
- package/package.json +1 -1
- package/scripts/generators/search.js +91 -87
- package/source/css/_plugins/search/local-search.styl +1 -3
- package/source/js/search/local-search.js +6 -21
package/_config.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
######## Stellar info ########
|
|
2
2
|
stellar:
|
|
3
|
-
version: '1.17.
|
|
3
|
+
version: '1.17.2'
|
|
4
4
|
homepage: 'https://xaoxuu.com/wiki/stellar/'
|
|
5
5
|
repo: 'https://github.com/xaoxuu/hexo-theme-stellar'
|
|
6
6
|
cdn_css: # Use cdn links instead of /css/main.css
|
|
@@ -25,10 +25,22 @@ sidebar:
|
|
|
25
25
|
# about: '[关于](/about/)'
|
|
26
26
|
# Sidebar widgets
|
|
27
27
|
widgets:
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
#### 自动生成的页面 ####
|
|
29
|
+
# 主页
|
|
30
|
+
home: search, welcome, recent, timeline # for home
|
|
31
|
+
# 博客索引页
|
|
32
|
+
blog_index: search_blog, recent, timeline # for categories/tags/archives
|
|
33
|
+
# 文档索引页
|
|
34
|
+
wiki_index: search_docs, recent, timeline # for wiki
|
|
35
|
+
# 其它(404)
|
|
36
|
+
others: search, welcome, recent, timeline # for 404 and ...
|
|
37
|
+
#### 手动创建的页面 ####
|
|
38
|
+
# 文章内页
|
|
30
39
|
post: toc, ghrepo, search, ghissues # for pages using 'layout:post'
|
|
40
|
+
# 文档内页
|
|
31
41
|
wiki: search, ghrepo, toc, ghissues, related # for pages using 'layout:wiki'
|
|
42
|
+
# 其它 layout:page 的页面
|
|
43
|
+
page: welcome, toc, search # for custom pages using 'layout:page'
|
|
32
44
|
|
|
33
45
|
######## Index ########
|
|
34
46
|
post-index: # 近期发布 分类 标签 归档 and ...
|
|
@@ -63,10 +75,11 @@ article:
|
|
|
63
75
|
|
|
64
76
|
search:
|
|
65
77
|
service: local_search # local_search, todo...
|
|
66
|
-
local_search:
|
|
78
|
+
local_search: # 在 front-matter 中设置 indexing:false 来避免被搜索索引
|
|
67
79
|
field: all # post, page, all
|
|
68
|
-
path: /search.json
|
|
69
|
-
content: true
|
|
80
|
+
path: /search.json # 搜索文件存放位置
|
|
81
|
+
content: true # 是否搜索内容
|
|
82
|
+
codeblock: true # 是否搜索代码块(需要content: true)
|
|
70
83
|
|
|
71
84
|
|
|
72
85
|
######## Comments ########
|
package/_data/widgets.yml
CHANGED
|
@@ -5,6 +5,17 @@
|
|
|
5
5
|
search:
|
|
6
6
|
layout: search
|
|
7
7
|
filter: auto # auto or 'path'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
search_blog:
|
|
11
|
+
layout: search
|
|
12
|
+
filter: /blog/ # auto or 'path'
|
|
13
|
+
placeholder: 文章搜索
|
|
14
|
+
|
|
15
|
+
search_docs:
|
|
16
|
+
layout: search
|
|
17
|
+
filter: /wiki/ # auto or 'path'
|
|
18
|
+
placeholder: 文档搜索
|
|
8
19
|
|
|
9
20
|
ghrepo:
|
|
10
21
|
layout: ghrepo
|
|
@@ -14,8 +14,14 @@ if (page.sidebar == undefined) {
|
|
|
14
14
|
} else {
|
|
15
15
|
page.sidebar = theme.sidebar.widgets.wiki;
|
|
16
16
|
}
|
|
17
|
-
} else if (is_home()
|
|
18
|
-
page.sidebar = theme.sidebar.widgets.
|
|
17
|
+
} else if (is_home()) {
|
|
18
|
+
page.sidebar = theme.sidebar.widgets.home;
|
|
19
|
+
} else if (is_category() || is_tag() || is_archive() || ['categories', 'tags', 'archives'].includes(page.layout)) {
|
|
20
|
+
page.sidebar = theme.sidebar.widgets.blog_index;
|
|
21
|
+
} else if (['wiki_index'].includes(page.layout)) {
|
|
22
|
+
page.sidebar = theme.sidebar.widgets.wiki_index;
|
|
23
|
+
} else if (['404', undefined].includes(page.layout)) {
|
|
24
|
+
page.sidebar = theme.sidebar.widgets.others;
|
|
19
25
|
} else if (page.layout == 'page') {
|
|
20
26
|
page.sidebar = theme.sidebar.widgets.page;
|
|
21
27
|
} else {
|
|
@@ -83,7 +89,7 @@ function layoutWidgets() {
|
|
|
83
89
|
if (name in theme.data.widgets) {
|
|
84
90
|
Object.assign(widget, theme.data.widgets[name])
|
|
85
91
|
}
|
|
86
|
-
if (typeof w == 'object' && w.override) {
|
|
92
|
+
if (typeof w == 'object' && (w.override || w.layout)) {
|
|
87
93
|
Object.assign(widget, w)
|
|
88
94
|
}
|
|
89
95
|
if (widget && widget.layout) {
|
|
@@ -5,15 +5,23 @@ function layoutDiv() {
|
|
|
5
5
|
el += '<div class="search-wrapper" id="search">'
|
|
6
6
|
el += '<form class="search-form">'
|
|
7
7
|
var filter = ''
|
|
8
|
-
if (item.filter == 'auto'
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
if (item.filter == 'auto') {
|
|
9
|
+
if (page.layout == 'wiki') {
|
|
10
|
+
let matches = page.path.match(/(.*?)\/(.*?)\//i)
|
|
11
|
+
if (matches?.length > 0) {
|
|
12
|
+
filter = matches[0]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
} else {
|
|
16
|
+
if (item.filter?.length > 0) {
|
|
17
|
+
filter = item.filter
|
|
12
18
|
}
|
|
13
19
|
}
|
|
14
20
|
el += '<input type="text" class="search-input" id="search-input"'
|
|
15
21
|
if (filter.length > 0) {
|
|
16
|
-
filter
|
|
22
|
+
if (!filter.startsWith('/')) {
|
|
23
|
+
filter = '/' + filter
|
|
24
|
+
}
|
|
17
25
|
el += ' data-filter="' + filter + '"'
|
|
18
26
|
el += ' placeholder="' + (item.placeholder || __('search.search_in', filter)) + '">'
|
|
19
27
|
} else {
|
package/layout/index.ejs
CHANGED
package/layout/wiki.ejs
CHANGED
|
@@ -3,7 +3,7 @@ if (page.menu_id == undefined) {
|
|
|
3
3
|
page.menu_id = 'wiki';
|
|
4
4
|
}
|
|
5
5
|
if (page.layout == undefined) {
|
|
6
|
-
page.layout = '
|
|
6
|
+
page.layout = 'wiki_index';
|
|
7
7
|
}
|
|
8
8
|
if (page.title == undefined) {
|
|
9
9
|
if (page.tagName) {
|
|
@@ -21,7 +21,7 @@ function layoutTitle() {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
%>
|
|
24
|
-
<% if (page.layout === '
|
|
24
|
+
<% if (page.layout === 'wiki_index') { %>
|
|
25
25
|
<%- partial('index') %>
|
|
26
26
|
<% } else { %>
|
|
27
27
|
<%
|
package/package.json
CHANGED
|
@@ -3,101 +3,105 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
hexo.extend.generator.register('search_json_generator', function (locals) {
|
|
6
|
-
if (this.theme.config.search.service != 'local_search') {
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var searchfield = local_search.field
|
|
13
|
-
var content = local_search.content
|
|
6
|
+
if (this.theme.config.search.service != 'local_search') { return {} }
|
|
7
|
+
const { root } = this.config
|
|
8
|
+
const { local_search: cfg } = this.theme.config.search
|
|
9
|
+
cfg.sort = '-date'
|
|
10
|
+
cfg.field = cfg.field?.trim()
|
|
14
11
|
|
|
15
12
|
var posts, pages
|
|
13
|
+
if (cfg.field == 'post') {
|
|
14
|
+
posts = locals.posts?.filter(p => p.content?.length > 0).sort(cfg.sort)
|
|
15
|
+
} else if (cfg.field == 'page') {
|
|
16
|
+
pages = locals.pages?.filter(p => p.content?.length > 0)
|
|
17
|
+
} else {
|
|
18
|
+
posts = locals.posts?.filter(p => p.content?.length > 0).sort(cfg.sort)
|
|
19
|
+
pages = locals.pages?.filter(p => p.content?.length > 0)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var res = new Array()
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
function generateJson(post) {
|
|
25
|
+
var temp_post = new Object()
|
|
26
|
+
if (post.title) {
|
|
27
|
+
temp_post.title = post.title.trim()
|
|
28
|
+
}
|
|
29
|
+
if (post.path) {
|
|
30
|
+
temp_post.path = root + post.path
|
|
31
|
+
}
|
|
32
|
+
if (cfg.content != false && post._content) {
|
|
33
|
+
var content = post._content.trim()
|
|
34
|
+
// 过滤掉标签和注释
|
|
35
|
+
if (content.includes('{%')) {
|
|
36
|
+
// 需要保留内容的的标签
|
|
37
|
+
content = content.replace(/{%\s*mark\s*(.*?)\s*%}/g, '$1')
|
|
38
|
+
content = content.replace(/{%\s*folding\s*(.*?)\s*%}/g, '$1')
|
|
39
|
+
content = content.replace(/{%\s*copy\s*(.*?)\s*%}/g, '$1')
|
|
40
|
+
content = content.replace(/{%\s*note\s*(.*?)\s*%}/g, '$1')
|
|
41
|
+
content = content.replace(/{%\s*kbd\s*(.*?)\s*%}/g, '$1')
|
|
42
|
+
content = content.replace(/{%\s*emp\s*(.*?)\s*%}/g, '$1')
|
|
43
|
+
content = content.replace(/{%\s*wavy\s*(.*?)\s*%}/g, '$1')
|
|
44
|
+
content = content.replace(/{%\s*sub\s*(.*?)\s*%}/g, '$1')
|
|
45
|
+
content = content.replace(/{%\s*sup\s*(.*?)\s*%}/g, '$1')
|
|
46
|
+
content = content.replace(/<!--\s*folder(.*?)\s*-->/g, '$1')
|
|
47
|
+
content = content.replace(/<!--\s*tab(.*?)\s*-->/g, '$1')
|
|
48
|
+
content = content.replace(/<!--\s*node(.*?)\s*-->/g, '$1')
|
|
49
|
+
// 不保留内容的标签
|
|
50
|
+
content = content.replace(/{%\s*(.*?)\s*%}/g, '')
|
|
51
|
+
// 注释
|
|
52
|
+
content = content.replace(/<!--\s*(.*?)\s*-->/g, '')
|
|
53
|
+
// ## 标题
|
|
54
|
+
content = content.replace(/[#]{2,} /g, '')
|
|
55
|
+
// 部分HTML标签
|
|
56
|
+
content = content.replace(/<iframe[\s|\S]+iframe>/g, '')
|
|
57
|
+
// 图片
|
|
58
|
+
content = content.replace(/\!\[(.*?)\]\((.*?)\)/g, '')
|
|
59
|
+
// 链接
|
|
60
|
+
content = content.replace(/\[(.*?)\]\((.*?)\)/g, '$1')
|
|
61
|
+
// 过滤代码块
|
|
62
|
+
if (cfg.codeblock == false) {
|
|
63
|
+
content = content.replace(/```([^`]+)```/g, '')
|
|
64
|
+
}
|
|
65
|
+
// 多个连续空格换成单个空格
|
|
66
|
+
content = content.replace(/[\s]{2,} /g, ' ')
|
|
67
|
+
// 特殊字符
|
|
68
|
+
content = content.replace(/[\r|\n]+/g, '')
|
|
26
69
|
}
|
|
27
|
-
|
|
28
|
-
|
|
70
|
+
temp_post.content = content.trim()
|
|
71
|
+
}
|
|
72
|
+
if (post.tags && post.tags.length > 0) {
|
|
73
|
+
var tags = []
|
|
74
|
+
post.tags.forEach(function (tag) {
|
|
75
|
+
tags.push(tag.name)
|
|
76
|
+
})
|
|
77
|
+
temp_post.tags = tags
|
|
78
|
+
}
|
|
79
|
+
if (post.categories && post.categories.length > 0) {
|
|
80
|
+
var categories = []
|
|
81
|
+
post.categories.forEach(function (cate) {
|
|
82
|
+
categories.push(cate.name)
|
|
83
|
+
})
|
|
84
|
+
temp_post.categories = categories
|
|
85
|
+
}
|
|
86
|
+
return temp_post
|
|
29
87
|
}
|
|
30
88
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (post.indexing != undefined && !post.indexing) return
|
|
37
|
-
var temp_post = new Object()
|
|
38
|
-
if (post.title) {
|
|
39
|
-
temp_post.title = post.title
|
|
40
|
-
}
|
|
41
|
-
if (post.path) {
|
|
42
|
-
temp_post.url = config.root + post.path
|
|
43
|
-
}
|
|
44
|
-
if (content != false && post._content) {
|
|
45
|
-
temp_post.content = post._content
|
|
46
|
-
}
|
|
47
|
-
if (post.tags && post.tags.length > 0) {
|
|
48
|
-
var tags = []
|
|
49
|
-
post.tags.forEach(function (tag) {
|
|
50
|
-
tags.push(tag.name)
|
|
51
|
-
})
|
|
52
|
-
temp_post.tags = tags
|
|
53
|
-
}
|
|
54
|
-
if (post.categories && post.categories.length > 0) {
|
|
55
|
-
var categories = []
|
|
56
|
-
post.categories.forEach(function (cate) {
|
|
57
|
-
categories.push(cate.name)
|
|
58
|
-
})
|
|
59
|
-
temp_post.categories = categories
|
|
60
|
-
}
|
|
61
|
-
res[index] = temp_post
|
|
62
|
-
index += 1
|
|
89
|
+
if (posts) {
|
|
90
|
+
posts.each(function(post) {
|
|
91
|
+
if (post.indexing == false) return
|
|
92
|
+
let temp_post = generateJson(post)
|
|
93
|
+
res.push(temp_post)
|
|
63
94
|
})
|
|
64
95
|
}
|
|
65
|
-
if (pages) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (page.path) {
|
|
73
|
-
temp_page.url = config.root + page.path
|
|
74
|
-
}
|
|
75
|
-
if (content != false && page._content) {
|
|
76
|
-
temp_page.content = page._content
|
|
77
|
-
}
|
|
78
|
-
if (page.tags && page.tags.length > 0) {
|
|
79
|
-
var tags = new Array()
|
|
80
|
-
var tag_index = 0
|
|
81
|
-
page.tags.each(function (tag) {
|
|
82
|
-
tags[tag_index] = tag.name
|
|
83
|
-
})
|
|
84
|
-
temp_page.tags = tags
|
|
85
|
-
}
|
|
86
|
-
if (page.categories && page.categories.length > 0) {
|
|
87
|
-
temp_page.categories = []
|
|
88
|
-
(page.categories.each || page.categories.forEach)(function (item) {
|
|
89
|
-
temp_page.categories.push(item)
|
|
90
|
-
})
|
|
91
|
-
}
|
|
92
|
-
res[index] = temp_page
|
|
93
|
-
index += 1
|
|
94
|
-
})
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
var json = JSON.stringify(res)
|
|
98
|
-
|
|
96
|
+
if (pages) {
|
|
97
|
+
pages.each(function(page) {
|
|
98
|
+
if (page.indexing == false) return
|
|
99
|
+
let temp_post = generateJson(page)
|
|
100
|
+
res.push(temp_post)
|
|
101
|
+
})
|
|
102
|
+
}
|
|
99
103
|
return {
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
path: cfg.path,
|
|
105
|
+
data: JSON.stringify(res)
|
|
102
106
|
}
|
|
103
107
|
})
|
|
@@ -24,20 +24,6 @@
|
|
|
24
24
|
/*exported searchFunc*/
|
|
25
25
|
var searchFunc = function(path, filter, searchId, contentId) {
|
|
26
26
|
|
|
27
|
-
function stripHtml(html) {
|
|
28
|
-
html = html.replace(/<style([\s\S]*?)<\/style>/gi, "");
|
|
29
|
-
html = html.replace(/<script([\s\S]*?)<\/script>/gi, "");
|
|
30
|
-
html = html.replace(/<figure([\s\S]*?)<\/figure>/gi, "");
|
|
31
|
-
html = html.replace(/<\/div>/ig, "\n");
|
|
32
|
-
html = html.replace(/<\/li>/ig, "\n");
|
|
33
|
-
html = html.replace(/<li>/ig, " * ");
|
|
34
|
-
html = html.replace(/<\/ul>/ig, "\n");
|
|
35
|
-
html = html.replace(/<\/p>/ig, "\n");
|
|
36
|
-
html = html.replace(/<br\s*[\/]?>/gi, "\n");
|
|
37
|
-
html = html.replace(/<[^>]+>/ig, "");
|
|
38
|
-
return html;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
27
|
function getAllCombinations(keywords) {
|
|
42
28
|
var i, j, result = [];
|
|
43
29
|
|
|
@@ -68,18 +54,17 @@ var searchFunc = function(path, filter, searchId, contentId) {
|
|
|
68
54
|
}
|
|
69
55
|
// perform local searching
|
|
70
56
|
datas.forEach(function(data) {
|
|
57
|
+
if (!data.title?.trim().length) { return }
|
|
58
|
+
if (!data.content?.trim().length) { return }
|
|
71
59
|
var matches = 0;
|
|
72
|
-
if (
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if (filter && !data.url.includes(filter)) {
|
|
60
|
+
if (filter && !data.path.includes(filter)) {
|
|
76
61
|
return;
|
|
77
62
|
}
|
|
78
|
-
var dataTitle = data.title.trim()
|
|
63
|
+
var dataTitle = data.title.trim();
|
|
79
64
|
var dataTitleLowerCase = dataTitle.toLowerCase();
|
|
80
|
-
var dataContent =
|
|
65
|
+
var dataContent = data.content;
|
|
81
66
|
var dataContentLowerCase = dataContent.toLowerCase();
|
|
82
|
-
var dataUrl = data.
|
|
67
|
+
var dataUrl = data.path;
|
|
83
68
|
var indexTitle = -1;
|
|
84
69
|
var indexContent = -1;
|
|
85
70
|
var firstOccur = -1;
|