diff --git a/_config.yml b/_config.yml index b899d72..36735de 100755 --- a/_config.yml +++ b/_config.yml @@ -9,31 +9,30 @@ stellar: ######## head tags ######## -head: - open_graph: true - twitter: false +open_graph: + enable: true + twitter_id: # for open_graph meta ######## Sidebar ######## sidebar: logo: - avatar: # default is config.avatar - title: # default is config.title - logo_action: - avatar: /about/ - title: / + avatar: + src: # default is config.avatar + href: # set your user center page like: '/about/' + title: # default is config.title, you can set html tag like: '' menu: - - class: post # post, wiki, about - name: btn.blog + post: + title: btn.blog url: / - - class: wiki - name: btn.wiki + wiki: + title: btn.wiki url: /wiki/ - - class: friends - name: 友链 + friends: + title: 友链 url: /friends/ - - class: about - name: 关于 + about: + title: 关于 url: /about/ # Sidebar widgets widgets: @@ -65,7 +64,7 @@ article: # npm i hexo-related-popular-posts related_posts: enable: false - title: 您可能感兴趣的文章 + title: meta.related_posts max_count: 5 placeholder_img: https://7.dusays.com/2021/02/20/76b86c0226ffd.svg # 分享文章 @@ -104,10 +103,8 @@ footer: url: https://music.163.com/#/user/home?id=63035382 - icon: '' url: /comments/ - license: 'CC BY SA 4.0' - source: - where: GitHub - url: https://github.com/xaoxuu/site-source + license: '[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)' + source: #'[GitHub](https://github.com/xaoxuu/hexo-theme-stellar)' ######## Tag Plugins ######## @@ -137,12 +134,12 @@ plugins: enable: true css: https://unpkg.com/swiper/swiper-bundle.min.css js: https://unpkg.com/swiper/swiper-bundle.min.js - + ## optional plugins ## # preload preload: - enable: #true - service: instant_page # instant_page, flying_pages + enable: true + service: flying_pages # instant_page, flying_pages instant_page: https://cdn.jsdelivr.net/gh/volantis-x/cdn-volantis@4.1.2/js/instant_page.js flying_pages: https://cdn.jsdelivr.net/gh/gijo-varghese/flying-pages@2.1.2/flying-pages.min.js diff --git a/languages/en.yml b/languages/en.yml index 74c7d20..3934dc6 100755 --- a/languages/en.yml +++ b/languages/en.yml @@ -9,7 +9,6 @@ btn: tag: Tag tags: Tags archives: Archives - learn_more: Learn more getting_started: Getting Started meta: @@ -19,19 +18,20 @@ meta: read_next: READ NEXT older: Older references: References + related_posts: Related Posts comment_title: Join the discussion back_to_top: Back to top more: 'More %s' footer: - license: 'Unless otherwise specified, this site adopts the CC BY SA 4.0 license agreement.' - info_not_open_source: 'This site was created by %s, using [Stellar](https://github.com/xaoxuu/hexo-theme-stellar) as the theme.' - info_open_source: 'This site was created by %s, using [Stellar](https://github.com/xaoxuu/hexo-theme-stellar) as the theme. You can find the source code of this site in [%s](%s).' + license: 'All articles in this blog are licensed under %s unless stating additionally.' + info_not_open_source: 'This site was deployed by %s using %s.' + info_open_source: 'This site was deployed by %s using %s. You can find the source code in %s.' page: error: what: Page Not Found - why: The address may be entered incorrectly or the address has been deleted + why: The address may be entered incorrectly or the address has been deleted. action: Back to Home categories: '%s Categories' tags: '%s Tags' diff --git a/languages/zh-CN.yml b/languages/zh-CN.yml index 90b06d3..1a5c950 100755 --- a/languages/zh-CN.yml +++ b/languages/zh-CN.yml @@ -9,7 +9,6 @@ btn: tag: 标签 tags: 标签 archives: 归档 - learn_more: 了解详情 getting_started: 开始使用 meta: @@ -19,12 +18,13 @@ meta: read_next: 接下来阅读 older: 更早一篇 references: 参考资料 + related_posts: 您可能感兴趣的文章 comment_title: 快来参与讨论吧 back_to_top: 回到顶部 more: '更多%s' footer: - license: '除非特别说明,本站采用 CC BY SA 4.0 许可协议。' + license: '本博客所有文章除特别声明外,均采用 %s 许可协议。转载请注明出处!' info_not_open_source: '本站由 %s 创建,使用 [Stellar](https://github.com/xaoxuu/hexo-theme-stellar) 作为主题。' info_open_source: '本站由 %s 创建,使用 [Stellar](https://github.com/xaoxuu/hexo-theme-stellar) 作为主题,您可以在 [%s](%s) 找到本站源码。' diff --git a/languages/zh-TW.yml b/languages/zh-TW.yml index b6a867f..bfef025 100755 --- a/languages/zh-TW.yml +++ b/languages/zh-TW.yml @@ -9,7 +9,6 @@ btn: tag: 標籤 tags: 標籤 archives: 歸檔 - learn_more: 了解詳情 getting_started: 開始使用 meta: @@ -19,12 +18,13 @@ meta: read_next: 接下來閱讀 older: 更早一篇 references: 參考資料 + related_posts: 您可能感興趣的文章 comment_title: 快來參與討論吧 back_to_top: 回到頂部 more: '更多%s' footer: - license: '除非特別說明,本站採用 CC BY SA 4.0 許可協議。' + license: '本網誌所有文章除特別聲明外,均採用 %s 許可協議。轉載請註明出處!' info_not_open_source: '本站由 %s 創建,使用 [Stellar](https://github.com/xaoxuu/hexo-theme-stellar) 作為主題。' info_open_source: '本站由 %s 創建,使用 [Stellar](https://github.com/xaoxuu/hexo-theme-stellar) 作為主題,您可以在 [%s](%s) 找到本站源碼。' diff --git a/layout/404.ejs b/layout/404.ejs index 5c3c0bd..5747e39 100755 --- a/layout/404.ejs +++ b/layout/404.ejs @@ -1,5 +1,5 @@ <% -page.class = '404'; +page.menu_id = '404'; page.layout = '404'; page.comment_title = ''; page.header = false; diff --git a/layout/_partial/footer.ejs b/layout/_partial/footer.ejs deleted file mode 100755 index 894dcda..0000000 --- a/layout/_partial/footer.ejs +++ /dev/null @@ -1,18 +0,0 @@ -<% -function layoutDiv() { - var wrapper = ''; - wrapper += '

'; - if (theme.footer.license) { - wrapper += markdown(__('footer.license', theme.footer.license)); - } - const author = '[' + config.author + '](' + config.url + config.root + ')'; - if (theme.footer.source && theme.footer.source.where && theme.footer.source.url) { - wrapper += markdown(__('footer.info_open_source', author, theme.footer.source.where, theme.footer.source.url)); - } else { - wrapper += markdown(__('footer.info_not_open_source', author)); - } - wrapper += '
'; - return wrapper; -} -%> -<%- layoutDiv() %> \ No newline at end of file diff --git a/layout/_partial/head.ejs b/layout/_partial/head.ejs index d97de3a..ada81c5 100755 --- a/layout/_partial/head.ejs +++ b/layout/_partial/head.ejs @@ -1,16 +1,4 @@ <% -function genrateRobots() { - var el = ''; - if (page.robots) { - el += ''; - } else if (is_home() == false) { - if (['post', 'wiki', 'index'].includes(page.layout) == false) { - el += ''; - } - } - return el; -} - function getTitle() { if (page.seo_title || page.title || page.wiki || page.layout) { return (page.seo_title || page.title || page.wiki || page.layout) + ' - ' + config.title; @@ -23,78 +11,25 @@ function getTitle() { } return ''; } -function getKeywords() { - if (page.keywords) { - return page.keywords; - } else if (page.tags && page.tags.length > 0) { - return page.tags.map(function(t){return t.name}).join(','); - } - return ''; +if (page.description == undefined) { + page.description = stellar_meta('description', page); } -function getDescription() { - if (page.description) { - return page.description; - } else { - if (['post', 'wiki'].includes(page.layout)) { - if (page.excerpt && page.excerpt.length > 0) { - return strip_html(page.excerpt); - } else if (page.content && page.content.length > 0) { - return truncate(strip_html(page.content), {length: 160}); - } - } +function og_args() { + var args = {}; + if (theme.open_graph.twitter_id) { + args.twitter_id = theme.open_graph.twitter_id; } - return ''; -} -function genrateKeywords() { - const keywords = getKeywords(); - if (keywords && keywords.length > 0) { - return ''; - } else { - return ''; + if (page.layout == 'post' && page.cover) { + args.twitter_card = 'summary_large_image'; } -} -function genrateDescription() { - const description = getDescription(); - if (description && description.length > 0) { - return ''; - } else { - return ''; - } -} -function genrateOpenGraph() { - if (theme.head.open_graph == false) { - return ''; - } - var el = ''; - el += ''; - el += ''; - el += ''; - el += ''; - el += ''; - el += ''; - if (page.layout == 'post' && page.cover && page.cover.length > 0) { - el += ''; - } - return el; -} -function genrateTwitter() { - if (theme.head.twitter == undefined || theme.head.twitter.length == 0 || theme.head.twitter == false) { - return ''; - } - var el = ''; - if (theme.head.twitter != 'true') { - el += ''; - } - if (page.layout == 'post' && page.cover && page.cover.length > 0) { - el += ''; - el += ''; - } - return el; + return args; } %> - + + <%- meta_generator() %> - <%- genrateRobots() %> + + @@ -107,11 +42,10 @@ function genrateTwitter() { <%- getTitle() %> - <%- genrateKeywords() %> - <%- genrateDescription() %> - <%- genrateOpenGraph() %> - <%- genrateTwitter() %> + <% if (theme.open_graph && theme.open_graph.enable) { %> + <%- open_graph(og_args()) %> + <% } %> <% if (config.feed && config.feed.path) { %> diff --git a/layout/_partial/main/article/related_posts.ejs b/layout/_partial/main/article/related_posts.ejs index 3b180e5..882e881 100644 --- a/layout/_partial/main/article/related_posts.ejs +++ b/layout/_partial/main/article/related_posts.ejs @@ -1,5 +1,6 @@ <% let post = page; %> +popular_posts_wrapper({ + title: __('meta.related_posts'), + json: popular_posts_json({ maxCount: 5 , ulClass: 'related-posts' , PPMixingRate: 0.2 , isImage: true , isExcerpt: true} , post ) +}) %> diff --git a/layout/_partial/main/footer.ejs b/layout/_partial/main/footer.ejs new file mode 100755 index 0000000..118b344 --- /dev/null +++ b/layout/_partial/main/footer.ejs @@ -0,0 +1,20 @@ +<% +const author = '[' + config.author + '](' + config.url + config.root + ')'; +const using = '[' + stellar_info('name') + '](' + stellar_info('tree') + ')'; +const source = theme.footer.source; +function layoutDiv() { + var wrapper = ''; + wrapper += '

'; + if (theme.footer.license) { + wrapper += markdown(__('footer.license', theme.footer.license)); + } + if (source) { + wrapper += markdown(__('footer.info_open_source', author, using, source)); + } else { + wrapper += markdown(__('footer.info_not_open_source', author, using)); + } + wrapper += '
'; + return wrapper; +} +%> +<%- layoutDiv() %> diff --git a/layout/_partial/main/navbar/breadcrumb.ejs b/layout/_partial/main/navbar/breadcrumb.ejs index 6987283..7e9be7a 100644 --- a/layout/_partial/main/navbar/breadcrumb.ejs +++ b/layout/_partial/main/navbar/breadcrumb.ejs @@ -30,7 +30,7 @@ <%- p.title %> <% }); %> <% site.pages.filter(function (p) { %> - <% return p.layout == 'wiki' && p.wiki == page.wiki && !p.order %> + <% return p.layout == 'wiki' && p.wiki == page.wiki && p.description %> <% }).limit(1).each(function(p) { %> <%- page.wiki %> diff --git a/layout/_partial/main/post_list/wiki_card.ejs b/layout/_partial/main/post_list/wiki_card.ejs index d3c72ad..d95be53 100644 --- a/layout/_partial/main/post_list/wiki_card.ejs +++ b/layout/_partial/main/post_list/wiki_card.ejs @@ -35,7 +35,4 @@ <% } else if (post.excerpt) { %> <%- strip_html(post.excerpt) %> <% } %> -
- 了解详情 -
diff --git a/layout/_partial/sidebar/header.ejs b/layout/_partial/sidebar/header.ejs index 8b4353f..042d864 100644 --- a/layout/_partial/sidebar/header.ejs +++ b/layout/_partial/sidebar/header.ejs @@ -1,16 +1,22 @@ +<% +function layoutMainMenu() { + var el = ''; + el += ''; + return el; +} +%>
<%- partial('logo') %> - -
\ No newline at end of file + <%- layoutMainMenu() %> + diff --git a/layout/_partial/sidebar/logo.ejs b/layout/_partial/sidebar/logo.ejs index c92fe62..ba8c1d7 100644 --- a/layout/_partial/sidebar/logo.ejs +++ b/layout/_partial/sidebar/logo.ejs @@ -1,8 +1,6 @@
- - <% if (theme.sidebar.logo.avatar != false) { %> -
- <% } %> - <%- theme.sidebar.logo.title || config.title %> -
+ <% if (theme.sidebar.logo.avatar.src || config.avatar) { %> + + <% } %> + <%- theme.sidebar.logo.title || config.title %>
diff --git a/layout/_partial/sidebar/widgets/recent.ejs b/layout/_partial/sidebar/widgets/recent.ejs index efe0f16..d9134f1 100644 --- a/layout/_partial/sidebar/widgets/recent.ejs +++ b/layout/_partial/sidebar/widgets/recent.ejs @@ -9,7 +9,7 @@
<% - var arr = page.class == 'wiki' ? site.pages.filter(function(p){ + var arr = page.menu_id == 'wiki' ? site.pages.filter(function(p){ return p.layout == 'wiki' && p.title && p.title.length > 0; }) : site.posts.filter(function(p){ return p.title && p.title.length > 0; diff --git a/layout/archive.ejs b/layout/archive.ejs index 104f8c7..d310daf 100755 --- a/layout/archive.ejs +++ b/layout/archive.ejs @@ -1,6 +1,6 @@ <% -if (page.class == undefined) { - page.class = 'post'; +if (page.menu_id == undefined) { + page.menu_id = 'post'; } %> <% if (page.posts && (is_category() || is_tag())) { %> diff --git a/layout/categories.ejs b/layout/categories.ejs index faba0a6..0374e60 100755 --- a/layout/categories.ejs +++ b/layout/categories.ejs @@ -1,6 +1,6 @@ <% -if (page.class == undefined) { - page.class = 'post'; +if (page.menu_id == undefined) { + page.menu_id = 'post'; } %> <% if (site.categories.length) { %> diff --git a/layout/index.ejs b/layout/index.ejs index 8b78d54..12933ec 100755 --- a/layout/index.ejs +++ b/layout/index.ejs @@ -1,13 +1,13 @@ <% -if (page.class == undefined) { +if (page.menu_id == undefined) { if (page.layout == 'index' && page.title && page.wiki) { - page.class = 'wiki'; + page.menu_id = 'wiki'; } else { - page.class = 'post'; + page.menu_id = 'post'; } } %> -<% if (page.class == 'post') { %> +<% if (page.menu_id == 'post') { %> <%- partial('_partial/main/navbar/list_post') %> <% if (page.posts) { %>
@@ -21,7 +21,7 @@ if (page.class == undefined) { <%- partial('_partial/main/post_list/paginator') %>
<% } %> -<% } else if (page.class == 'wiki') { %> +<% } else if (page.menu_id == 'wiki') { %> <% function outputExcerpt(post) { %>
diff --git a/layout/layout.ejs b/layout/layout.ejs index 0070586..add5732 100755 --- a/layout/layout.ejs +++ b/layout/layout.ejs @@ -11,11 +11,13 @@ <%- partial('_partial/main/header/index') %> <%- body %> <%- partial('_partial/menubtn') %>
- <%- partial('_partial/scripts/index') %> +
+ <%- partial('_partial/scripts/index') %> +
diff --git a/layout/post.ejs b/layout/post.ejs index 847681a..424d3ef 100755 --- a/layout/post.ejs +++ b/layout/post.ejs @@ -1,6 +1,6 @@ <% -if (page.class == undefined) { - page.class = 'post'; +if (page.menu_id == undefined) { + page.menu_id = 'post'; } if (page.header == undefined) { page.header = false; diff --git a/layout/tags.ejs b/layout/tags.ejs index 32cd26b..5c471ed 100755 --- a/layout/tags.ejs +++ b/layout/tags.ejs @@ -1,6 +1,6 @@ <% -if (page.class == undefined) { - page.class = 'post'; +if (page.menu_id == undefined) { + page.menu_id = 'post'; } %> <% if (site.tags.length) { %> diff --git a/layout/wiki.ejs b/layout/wiki.ejs index 609b04b..cad147c 100755 --- a/layout/wiki.ejs +++ b/layout/wiki.ejs @@ -1,6 +1,6 @@ <% -if (page.class == undefined) { - page.class = 'wiki'; +if (page.menu_id == undefined) { + page.menu_id = 'wiki'; } if (page.layout == undefined) { page.layout = 'index'; diff --git a/scripts/events/index.js b/scripts/events/index.js index 7daf1b6..9ca8fb6 100644 --- a/scripts/events/index.js +++ b/scripts/events/index.js @@ -10,9 +10,9 @@ hexo.on('generateBefore', () => { hexo.on('ready', () => { const { version } = require('../../package.json'); hexo.log.info(` -=================================================== -Stellar ${version} -Docs: https://xaoxuu.com/wiki/stellar/ -Repo: https://github.com/xaoxuu/hexo-theme-stellar/ -===================================================`); -}); \ No newline at end of file +======================================================= + Stellar ${version} + Docs: https://xaoxuu.com/wiki/stellar/ + Repo: https://github.com/xaoxuu/hexo-theme-stellar/ +=======================================================`); +}); diff --git a/scripts/helpers/related_posts.js b/scripts/helpers/related_posts.js index ea6cfe8..96fd5f5 100644 --- a/scripts/helpers/related_posts.js +++ b/scripts/helpers/related_posts.js @@ -3,18 +3,23 @@ */ 'use strict'; + var util = require('hexo-util'); -// Examples of helper hexo.extend.helper.register('popular_posts_wrapper', function(args){ - if (!args || !args.json || args.json.length == 0) return ""; + const title = args.title; + const json = args.json.json; + const cls = args.json.class; + if (json == undefined || json.length == 0) { + return ''; + } const cfg = hexo.theme.config.article.related_posts; if (cfg.enable != true) return; var returnHTML = ""; var div = `
'; return div; diff --git a/scripts/helpers/stellar_info.js b/scripts/helpers/stellar_info.js new file mode 100644 index 0000000..5a4725a --- /dev/null +++ b/scripts/helpers/stellar_info.js @@ -0,0 +1,21 @@ +'use strict'; + +hexo.extend.helper.register('stellar_info', function(args){ + const repo = 'https://github.com/xaoxuu/hexo-theme-stellar'; + const wiki = 'https://xaoxuu.com/wiki/stellar/'; + const issues = repo + '/issues/'; + const { version } = require('../../package.json'); + const cfg = hexo.theme.config.stellar; + if (!args) { + return repo; + } else if (args == 'name') { + return 'Stellar'; + } else if (args == 'version') { + return version; + } else if (args == 'issues') { + return repo + '/issues/' + } else if (args == 'tree') { + return repo + '/tree/' + version; + } + return ''; +}); diff --git a/scripts/helpers/stellar_meta.js b/scripts/helpers/stellar_meta.js new file mode 100644 index 0000000..5a76a70 --- /dev/null +++ b/scripts/helpers/stellar_meta.js @@ -0,0 +1,44 @@ +'use strict'; + +var util = require('hexo-util'); + +hexo.extend.helper.register('stellar_meta', function(args, page){ + if (['robots', 'description'].includes(args) == false) { + return ''; + } + function meta(str) { + if (str && str.length > 0) { + return str; + } else { + return ''; + } + } + if (args == 'robots') { + if (page.__index == true) { + return ''; + } + if (page.robots) { + meta(page.robots); + } else { + // default rule + if (['post', 'wiki', 'index'].includes(page.layout) == false) { + meta('noindex,nofollow'); + } + } + } else if (args == 'description') { + if (page.__index == true) { + meta(hexo.config.description); + } else if (page.description) { + meta(util.stripHTML(page.description)); + } else if (['post', 'wiki'].includes(page.layout)) { + var description = ''; + if (page.excerpt && page.excerpt.length > 0) { + description = util.stripHTML(page.excerpt); + } else if (page.content && page.content.length > 0) { + description = util.truncate(util.stripHTML(page.content), {length: 160}); + } + meta(description); + } + } + return ''; +}); diff --git a/source/css/_layout/partial/paginator.styl b/source/css/_layout/partial/paginator.styl index 8bcbffd..826821b 100644 --- a/source/css/_layout/partial/paginator.styl +++ b/source/css/_layout/partial/paginator.styl @@ -1,4 +1,4 @@ -.posts .paginator-wrap +.post-list .paginator-wrap display: flex justify-content: space-between align-items: center