From 5bc949fc22de44174a28fb3b7fa84824981fbd06 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Fri, 19 Jan 2024 01:05:44 +0800 Subject: [PATCH] [opt] code optimization --- _config.yml | 7 +- layout/_partial/cover/index.ejs | 10 +-- layout/_partial/cover/post_cover.ejs | 2 +- layout/_partial/cover/wiki_cover.ejs | 4 +- layout/_partial/head.ejs | 10 +-- .../_partial/main/article/article_footer.ejs | 8 +-- layout/_partial/main/article/read_next.ejs | 6 +- .../_partial/main/article/related_posts.ejs | 2 +- layout/_partial/main/footer.ejs | 2 +- layout/_partial/main/navbar/breadcrumb.ejs | 2 +- layout/_partial/main/post_list/paginator.ejs | 2 +- layout/_partial/plugins/ai/tianli_gpt.ejs | 2 +- layout/_partial/plugins/comments/layout.ejs | 6 +- layout/_partial/sidebar/index.ejs | 37 +++++----- layout/_partial/sidebar/logo.ejs | 15 ++-- layout/_partial/sidebar/search.ejs | 2 +- layout/_partial/widgets/ghissues.ejs | 14 ++-- layout/_partial/widgets/ghrepo.ejs | 14 ++-- layout/_partial/widgets/ghuser.ejs | 2 +- layout/_partial/widgets/markdown.ejs | 2 +- layout/_partial/widgets/recent.ejs | 6 +- layout/_partial/widgets/related.ejs | 4 +- layout/_partial/widgets/tagcloud.ejs | 2 +- layout/_partial/widgets/timeline.ejs | 2 +- layout/_partial/widgets/toc.ejs | 40 +++++------ layout/archive.ejs | 2 +- layout/categories.ejs | 2 +- layout/index.ejs | 2 +- layout/index_topic.ejs | 2 +- layout/index_wiki.ejs | 4 +- layout/layout.ejs | 11 ++- layout/page.ejs | 70 +++++++++++++++---- layout/post.ejs | 33 --------- layout/tags.ejs | 2 +- layout/wiki.ejs | 32 --------- scripts/events/lib/config.js | 46 ++++++------ scripts/events/lib/doc_tree.js | 2 +- scripts/generators/wiki.js | 3 +- scripts/helpers/scrollreveal.js | 12 ++-- source/css/_layout/layout.styl | 1 - source/css/_layout/sidebar/sidebar.styl | 6 -- source/css/_plugins/scrollreveal.styl | 2 +- source/js/main.js | 7 +- 43 files changed, 203 insertions(+), 239 deletions(-) delete mode 100755 layout/post.ejs delete mode 100755 layout/wiki.ejs diff --git a/_config.yml b/_config.yml index dd9d3d6..248d882 100755 --- a/_config.yml +++ b/_config.yml @@ -11,6 +11,7 @@ stellar: preconnect: # - https://gcore.jsdelivr.net # - https://unpkg.com + # - https://cdn.bootcdn.net open_graph: enable: true @@ -369,9 +370,9 @@ plugins: # https://scrollrevealjs.org/api/reveal.html scrollreveal: enable: #true - js: https://gcore.jsdelivr.net/npm/scrollreveal@4.0.9/dist/scrollreveal.min.js - distance: 8px - duration: 500 # ms + js: https://cdn.bootcdn.net/ajax/libs/scrollReveal.js/4.0.9/scrollreveal.min.js + distance: 16px + duration: 800 # ms interval: 100 # ms scale: 1 # 0.1~1 diff --git a/layout/_partial/cover/index.ejs b/layout/_partial/cover/index.ejs index b63c82b..cfaf68d 100644 --- a/layout/_partial/cover/index.ejs +++ b/layout/_partial/cover/index.ejs @@ -1,12 +1,12 @@ <% function layoutCover() { - if (page.layout == 'wiki') { - return partial('wiki_cover'); + if (page.wiki) { + return partial('wiki_cover') } - if (page.layout == 'post') { - return partial('post_cover'); + if (page.layout === 'post') { + return partial('post_cover') } - return ''; + return '' } %> <%- layoutCover() %> diff --git a/layout/_partial/cover/post_cover.ejs b/layout/_partial/cover/post_cover.ejs index 4036643..d1ea71c 100644 --- a/layout/_partial/cover/post_cover.ejs +++ b/layout/_partial/cover/post_cover.ejs @@ -26,7 +26,7 @@ function div() { url = 'https://source.unsplash.com/random/2000x400'; } } - el += '
'; + el += '
'; el += '
'; if (theme.plugins.lazyload && theme.plugins.lazyload.enable) { el += '
'; diff --git a/layout/_partial/cover/wiki_cover.ejs b/layout/_partial/cover/wiki_cover.ejs index a3216cf..43a7b8c 100644 --- a/layout/_partial/cover/wiki_cover.ejs +++ b/layout/_partial/cover/wiki_cover.ejs @@ -1,7 +1,7 @@ <% function layoutWikiCover() { var el = ''; - let proj = theme.wiki.tree[page.wiki]; + const proj = theme.wiki.tree[page.wiki] if (proj == undefined) { return el; } @@ -18,7 +18,7 @@ function layoutWikiCover() { if (coverpage === true) { coverpage = ['cover', 'title', 'description']; } - el += '
'; + el += '
'; el += '
'; if (cover?.length > 0 && coverpage.includes('cover')) { diff --git a/layout/_partial/head.ejs b/layout/_partial/head.ejs index 7afbe1f..0e50571 100755 --- a/layout/_partial/head.ejs +++ b/layout/_partial/head.ejs @@ -1,8 +1,8 @@ <% function generate_title() { if (page.wiki) { - let proj = theme.wiki.tree[page.wiki]; - let wiki = (proj && proj.name) || page.wiki; + const proj = theme.wiki.tree[page.wiki] + const wiki = proj?.name || page.wiki if (page.title) { return wiki + __('symbol.colon') + page.title + ' - ' + config.title; } else { @@ -24,9 +24,9 @@ function generate_description() { return ''; } if (page.wiki) { - let proj = theme.wiki.tree[page.wiki]; - if (proj && proj.description) { - return ''; + const proj = theme.wiki.tree[page.wiki] + if (proj?.description) { + return '' } } if (page.description || page.excerpt || page.content) { diff --git a/layout/_partial/main/article/article_footer.ejs b/layout/_partial/main/article/article_footer.ejs index d22dc69..dc06e9b 100644 --- a/layout/_partial/main/article/article_footer.ejs +++ b/layout/_partial/main/article/article_footer.ejs @@ -14,7 +14,7 @@ function layoutDiv() { if (item.length === 0) { return el; } - el += '