Skip to content

Commit 11ab545

Browse files
committed
fix: yml string to list
1 parent 302bf4e commit 11ab545

25 files changed

+54
-47
lines changed

layout/_partial/_cover/dock.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<div class='menu navigation'>
1515
<div class='list-h'>
1616
<% if (theme.cover.features) { %>
17-
<% (theme.cover.features || []).forEach(function(value){ %>
17+
<% getList(theme.cover.features).forEach(function(value){ %>
1818
<a href="<%= url_for(value.url) %>"
1919
<% if (value.rel) { %>
2020
rel="<%- value.rel %>"

layout/_partial/_cover/featured.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<div class='menu navigation'>
1515
<div class='list-h'>
1616
<% if (theme.cover.features) { %>
17-
<% (theme.cover.features || []).forEach(function(value){ %>
17+
<% getList(theme.cover.features).forEach(function(value){ %>
1818
<a href="<%= url_for(value.url) %>"
1919
<% if (value.rel) { %>
2020
rel="<%- value.rel %>"

layout/_partial/_cover/focus.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<div class='menu navigation'>
1515
<div class='list-h'>
1616
<% if (theme.cover.features) { %>
17-
<% (theme.cover.features || []).forEach(function(value){ %>
17+
<% getList(theme.cover.features).forEach(function(value){ %>
1818
<a href="<%= url_for(value.url) %>"
1919
<% if (value.rel) { %>
2020
rel="<%- value.rel %>"

layout/_partial/_cover/search.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<div class='menu navigation'>
2323
<div class='list-h'>
2424
<% if (theme.cover.features) { %>
25-
<% (theme.cover.features || []).forEach(function(value){ %>
25+
<% getList(theme.cover.features).forEach(function(value){ %>
2626
<a href="<%= url_for(value.url) %>"
2727
<% if (value.rel) { %>
2828
rel="<%- value.rel %>"

layout/_partial/article.ejs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</section>
3434
<section class='body'>
3535
<ul>
36-
<% (page.references||[]).forEach(function(row){ %>
36+
<% getList(page.references).forEach(function(row){ %>
3737
<li>
3838
<a href="<%- url_for(row.url) %>" rel="external nofollow noopener noreferrer" target="_blank">
3939
<%- row.title || url_for(row.url) %>
@@ -104,7 +104,7 @@
104104
<% } else { %>
105105
<div class='copyright'>
106106
<blockquote>
107-
<% (footer_widget.copyright.content||[]).forEach(function(row){ %>
107+
<% getList(footer_widget.copyright.content).forEach(function(row){ %>
108108
<% if (row == 'permalink') { %>
109109
<p><%- footer_widget.copyright.permalink %><a href="<%- decodeURI(page.permalink) %>"><%- decodeURI(page.permalink) %></a></p>
110110
<% } else { %>
@@ -119,7 +119,7 @@
119119
<% if (['post'].includes(page.layout) && footer_widget.donate && footer_widget.donate.enable == true) { %>
120120
<div class='donate'>
121121
<div class='imgs'>
122-
<% (footer_widget.donate.images||[]).forEach(function(url){ %>
122+
<% getList(footer_widget.donate.images).forEach(function(url){ %>
123123
<img src='<%- url_for(url) %>'>
124124
<% }) %>
125125
</div>

layout/_partial/footer.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<% if (item == 'social') { %>
2121
<br>
2222
<div class="social-wrapper" itemprop="about" itemscope itemtype="http://schema.org/Thing">
23-
<% (theme.site_footer.social||[]).forEach(function(value){ %>
23+
<% getList(theme.site_footer.social).forEach(function(value){ %>
2424
<% if (value.url && (value.icon || value.img || value.avatar)) { %>
2525
<a href="<%= url_for(value.url) %>"
2626
class="social <%- value.icon %> flat-btn"

layout/_partial/head.ejs

+6-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<!-- 渲染优化 -->
99
<%_ if (theme.dns_prefetch && theme.dns_prefetch.length){ _%>
1010
<meta http-equiv='x-dns-prefetch-control' content='on' />
11-
<%_ ([...theme.dns_prefetch]).forEach(function(item){ _%>
11+
<%_ getList(theme.dns_prefetch).forEach(function(item){ _%>
1212
<link rel='dns-prefetch' href='<%- item %>'>
1313
<link rel="preconnect" href="<%- item %>" crossorigin>
1414
<%_ }) _%>
@@ -26,7 +26,7 @@
2626
<meta content="telephone=no" name="format-detection">
2727
<!-- import head_begin begin -->
2828
<%_ if (config.import && config.import.head_begin){ _%>
29-
<%_ ([...config.import.head_begin]).forEach(function(item){ _%>
29+
<%_ getList(config.import.head_begin).forEach(function(item){ _%>
3030
<%- item %>
3131
<%_ }) _%>
3232
<%_ } _%>
@@ -41,13 +41,9 @@
4141
<%- generate_preload_fontfamily(theme) %>
4242
<!-- feed -->
4343
<%_ if (config.feed && config.feed.path){ _%>
44-
<%_ if (typeof(config.feed.path)=="string"){ _%>
45-
<%- feed_tag(config.feed.path, {title: config.title}) %>
46-
<%_ }else{ _%>
47-
<%_ ([...config.feed.path]).forEach(function(item){ _%>
48-
<%- feed_tag(item, {title: config.title}) %>
49-
<%_ }) _%>
50-
<%_ } _%>
44+
<%_ getList(config.feed.path).forEach(function(item){ _%>
45+
<%- feed_tag(item, {title: config.title}) %>
46+
<%_ }) _%>
5147
<%_ } _%>
5248
<!-- 页面元数据 -->
5349
<%- generate_title(config, theme, page) %>
@@ -72,7 +68,7 @@
7268
<%- partial('scripts/global') %>
7369
<!-- import head_end begin -->
7470
<%_ if (config.import && config.import.head_end){ _%>
75-
<%_ ([...config.import.head_end]).forEach(function(item){ _%>
71+
<%_ getList(config.import.head_end).forEach(function(item){ _%>
7672
<%- item %>
7773
<%_ }) _%>
7874
<%_ } _%>

layout/_partial/header.ejs

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@
7777
</a>
7878
<% if (value.rows) { %>
7979
<ul class="list-v">
80-
<% value.rows.forEach(function(value){ %>
80+
<% getList(value.rows).forEach(function(value){ %>
8181
<% menu(value, type) %>
8282
<%})%>
8383
</ul>
8484
<% } %>
8585
</li>
8686
<% } %>
8787
<% } %>
88-
<% menu_list.forEach(function(value){ %>
88+
<% getList(menu_list).forEach(function(value){ %>
8989
<% menu(value, 'pc') %>
9090
<% }) %>
9191
</ul>
@@ -106,7 +106,7 @@
106106
<li>
107107
<a class="s-menu fa-solid fa-bars fa-fw" target="_self" href="/" onclick="return false;" title="menu"></a>
108108
<ul class="menu-phone list-v navigation white-box">
109-
<% menu_list.forEach(function(value){ %>
109+
<% getList(menu_list).forEach(function(value){ %>
110110
<% menu(value, 'mobile') %>
111111
<% }) %>
112112
</ul>

layout/_partial/meta.ejs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ if (post.bottom_meta == false) {
3535
<%- post.title %>
3636
</h1>
3737
<div class='new-meta-box'>
38-
<% (topMetas).forEach(function(meta) { %>
38+
<% getList(topMetas).forEach(function(meta) { %>
3939
<% if (meta in theme.article.body.meta_library){ %>
4040
<%- partial('../_meta/' + meta, {post: post}) %>
4141
<% } %>
@@ -53,7 +53,7 @@ if (post.bottom_meta == false) {
5353
<% } else if (position == 'bottom') { %>
5454
<div class='article-meta' id="bottom">
5555
<div class='new-meta-box'>
56-
<% (bottomMetas).forEach(function(meta){ %>
56+
<% getList(bottomMetas).forEach(function(meta){ %>
5757
<% if (meta in theme.article.body.meta_library) { %>
5858
<%- partial('../_meta/' + meta, {post: post}) %>
5959
<% } %>

layout/_plugins/_page_plugins/index.ejs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%_
2-
(page.plugins||[]).forEach(function(item){
2+
getList(page.plugins).forEach(function(item){
33
try {
44
if (typeof item == "string") { _%>
55
<%- partial( item + "/index") %>
@@ -13,12 +13,12 @@
1313
没有找到页面插件:${item}
1414
请检查是否存在该插件,或者检查插件名称是否正确:${item}
1515
出问题的页面:${page.path}
16-
see: https://volantis.js.org/v5/page-settings/#页面插件-page-plugins
16+
see: https://volantis.js.org/v6/page-settings/#页面插件-page-plugins
1717
================================================================================
1818
There is no page plugin: ${item}
1919
Please check if the plugin exists, or check the plugin name is correct: ${item}
2020
The page that has problem: ${page.path}
21-
see: https://volantis.js.org/v5/page-settings/#页面插件-page-plugins
21+
see: https://volantis.js.org/v6/page-settings/#页面插件-page-plugins
2222
=================================================================================`);
2323
}
2424

layout/_plugins/highlight/prismjs/script.ejs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<% (theme.plugins.prismjs.js||[]).forEach(function(item) { %>
1+
<% getList(theme.plugins.prismjs.js).forEach(function(item) { %>
22
<%- js(item) %>
33
<% }) %>
4-
<% (theme.plugins.prismjs.css||[]).forEach(function(item) { %>
4+
<% getList(theme.plugins.prismjs.css).forEach(function(item) { %>
55
<%- css(item) %>
66
<% }) %>
77
<script>

layout/_plugins/share/layout.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="new-meta-item share -mob-share-list">
22
<div class="-mob-share-list share-body">
3-
<% (theme.article.body.meta_library.share||[]).forEach(function(item){ %>
3+
<% getList(theme.article.body.meta_library.share).forEach(function(item){ %>
44
<% if (item.id == 'qrcode'){ %>
55
<% var src = qrcode(url,{margin:1,size:8}); %>
66
<div class='hoverbox'>

layout/_widget/_pre.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%
22
var pf = [];
33
if (item.display) {
4-
item.display.forEach(function(p){
4+
getList(item.display).forEach(function(p){
55
pf.push(p);
66
});
77
} else {

layout/_widget/blogger.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<% } %>
2929
<% if (item.social && item.social.length > 0) { %>
3030
<div class="social-wrapper">
31-
<% (item.social||[]).forEach(function(value){ %>
31+
<% getList(item.social).forEach(function(value){ %>
3232
<% if (value.url && (value.icon || value.img || value.avatar)) { %>
3333
<a href="<%= url_for(value.url) %>"
3434
class="social <%- value.icon %> flat-btn"

layout/_widget/copyright.ejs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class='content'>
44
<% if (item.blockquote == true) { %>
55
<blockquote>
6-
<% (item.content||[]).forEach(function(row){ %>
6+
<% getList(item.content).forEach(function(row){ %>
77
<% if (row == 'permalink') { %>
88
<p><%- item.permalink %><a href=<%- page.permalink %>><%- page.permalink %></a></p>
99
<% } else { %>
@@ -12,7 +12,7 @@
1212
<% }) %>
1313
</blockquote>
1414
<% } else { %>
15-
<% (item.content||[]).forEach(function(row){ %>
15+
<% getList(item.content).forEach(function(row){ %>
1616
<% if (row == 'permalink') { %>
1717
<p><%- item.permalink %><a href=<%- page.permalink %>><%- page.permalink %></a></p>
1818
<% } else { %>

layout/_widget/grid.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<%- partial('header', {item: item}) %>
44
<div class='content'>
55
<div class="grid navigation<%- item.fixed ? ' fixed' : '' %>">
6-
<% (item.rows||[]).forEach(function(row){ %>
6+
<% getList(item.rows).forEach(function(row){ %>
77
<a class="flat-box" href="<%- url_for(row.url) %>"
88
<% if (row.rel) { %>
99
rel="<%- row.rel %>"

layout/_widget/list.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<%- partial('header', {item: item}) %>
44
<div class='content'>
55
<ul class="list entry navigation">
6-
<% (item.rows||[]).forEach(function(row){ %>
6+
<% getList(item.rows).forEach(function(row){ %>
77
<li><a class="flat-box" title="<%- url_for(row.url) %>" href="<%- url_for(row.url) %>"
88
<% if (row.rel) { %>
99
rel="<%- row.rel %>"

layout/_widget/load.ejs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%
22
let widget_library_temp = [];
33
%>
4-
<% (widgets||[]).forEach(function(widget){ %>
4+
<% getList(widgets).forEach(function(widget){ %>
55
<% if (theme.sidebar.widget_library && (widget in theme.sidebar.widget_library)){ %>
66
<% let w = theme.sidebar.widget_library[widget]; w.id = widget; %>
77
<% if(w.sticky) { %>
@@ -22,7 +22,7 @@
2222

2323
<%
2424
let widget_pjax_length = 0;
25-
page.sidebar.forEach(function(e){
25+
getList(page.sidebar).forEach(function(e){
2626
if (e&&theme.sidebar.widget_library&&theme.sidebar.widget_library[e]) {
2727
let widget_pjax_flag = theme.sidebar.widget_library[e].pjaxReload
2828
let widget_stickys = theme.sidebar.widget_library[e].sticky

layout/_widget/qrcode.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<section class="widget <%- item.class %> <%- page.widget_platform %> <%- page.widget_pjax %>">
33
<%- partial('header', {item: item}) %>
44
<div class='content article-entry'>
5-
<% (item.images||[]).forEach(function(url){ %>
5+
<% getList(item.images).forEach(function(url){ %>
66
<img src='<%- url_for(url) %>'
77
<% if (item.height) { %>
88
height='<%- item.height %>'

layout/_widget/references.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if (item.rows == undefined) {
44
var itms = new Array();
55
let id = item.id || 'references';
66
if (id in page) {
7-
(page[id]||[]).forEach(function(ref) {
7+
getList(page[id]).forEach(function(ref) {
88
if (ref.name || ref.url) {
99
item.rows.push(ref);
1010
}

layout/_widget/text.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<section class="widget <%- item.class %> <%- page.widget_platform %> <%- page.widget_pjax %>">
33
<%- partial('header', {item: item}) %>
44
<div class='content'>
5-
<% (item.content||[]).forEach(function(row){ %>
5+
<% getList(item.content).forEach(function(row){ %>
66
<%- markdown(row) %>
77
<% }) %>
88
</div>

layout/archive.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<% if (post.icon) { %>
2727
&nbsp;<i class="<%- post.icon %>" aria-hidden="true"></i>
2828
<% } %>
29-
<% (post.icons && post.icons||[]).forEach(function(icon){ %>
29+
<% getList(post.icons).forEach(function(icon){ %>
3030
&nbsp;<i class="<%- icon %>" aria-hidden="true"></i>
3131
<% }) %>
3232
</a>

layout/friends.ejs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<%- partial('_partial/meta',{post: page, position: 'top'}) %>
55
<%- page.excerpt %>
66
<% if (site.data.friends){ %>
7-
<% site.data.friends.forEach((group, i) => { %>
7+
<% getList(site.data.friends).forEach((group, i) => { %>
88
<div class='friends-group'>
99
<br>
1010
<h2 class='friend-header'>
@@ -15,7 +15,7 @@
1515
<%} %>
1616
<% if (theme.pages.friends.layout_scheme == 'traditional') { %>
1717
<div class='friend-content'>
18-
<% (group.items||[]).forEach(function(item){ %>
18+
<% getList(group.items).forEach(function(item){ %>
1919
<% if (item.url && item.title) { %>
2020
<a class='friend-card'
2121
target="_blank" rel="external noopener noreferrer" href="<%- url_for(item.url || '/') %>">
@@ -28,7 +28,7 @@
2828
<p class="friend-name"><%- item.title %></p>
2929
<% if (item.keywords) { %>
3030
<div class='friend-tags-wrapper'>
31-
<% (item.keywords||[]).forEach(function(keyword){ %>
31+
<% getList(item.keywords).forEach(function(keyword){ %>
3232
<p class="tags"><i class="fa-solid fa-hashtag fa-fw" aria-hidden="true"></i><%= keyword %></p>
3333
<% }) %>
3434
</div>
@@ -45,7 +45,7 @@
4545
</div>
4646
<% } else { %>
4747
<div class='simpleuser-group'>
48-
<% (group.items||[]).forEach(function(item){ %>
48+
<% getList(group.items).forEach(function(item){ %>
4949
<% if (item.url && item.title) { %>
5050
<a class="simpleuser" target="_blank" rel="external noopener noreferrer" href="<%- url_for(item.url || '/') %>">
5151
<img src="<%- item.avatar || (theme.plugins.lazyload && theme.plugins.lazyload.loadingImg) %>"/>

layout/layout.ejs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<body itemscope itemtype="http://schema.org/WebPage">
66
<!-- import body_begin begin-->
77
<%_ if (config.import && config.import.body_begin){ _%>
8-
<%_ ([...config.import.body_begin]).forEach(function(item){ _%>
8+
<%_ getList(config.import.body_begin).forEach(function(item){ _%>
99
<%- item %>
1010
<%_ }) _%>
1111
<%_ } _%>
@@ -33,7 +33,7 @@
3333
</div>
3434
<!-- import body_end begin-->
3535
<%_ if (config.import && config.import.body_end){ _%>
36-
<%_ ([...config.import.body_end]).forEach(function(item){ _%>
36+
<%_ getList(config.import.body_end).forEach(function(item){ _%>
3737
<%- item %>
3838
<%_ }) _%>
3939
<%_ } _%>

scripts/helpers/getList.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// yml string to list
2+
// yml 太烂了
3+
4+
hexo.extend.helper.register('getList', function (list) {
5+
if (!list) return []
6+
if (typeof list == "string") {
7+
return [list]
8+
} else {
9+
return [...list]
10+
}
11+
});

0 commit comments

Comments
 (0)