diff --git a/.gitignore b/.gitignore index 79be2e0..8c9526d 100644 --- a/.gitignore +++ b/.gitignore @@ -20,9 +20,11 @@ exampleSite/content/**/ # Exclude special files !exampleSite/config.yaml -!exampleSite/start.sh +!exampleSite/startup.sh data/* !data/config.yaml !data/resources.yaml +# vscode +.vscode/ diff --git a/README.md b/README.md index 6ffd465..edb6714 100644 --- a/README.md +++ b/README.md @@ -112,10 +112,12 @@ tags: #expand: true # It's means that will redirecting to external links #extlink: -# Switch to enabled or disabled comment plugins in this post +# Disabled comment plugins in this post #comment: # enable: false -# Enable table of content +# Disable table of content int this post +# Notice: By default will automatic build table of content +# with h2-h4 title in post and without other settings #toc: false # Absolute link for visit #url: "{{ lower .Name }}.html" diff --git a/README.zh.md b/README.zh.md index 5ee408e..32340ec 100644 --- a/README.zh.md +++ b/README.zh.md @@ -120,10 +120,11 @@ tags: #expand: true # 外部链接地址,访问时直接跳转 #extlink: -# 在当前页面开启或关闭评论功能 +# 在当前页面关闭评论功能 #comment: # enable: false -# 开启文章目录功能 +# 关闭当前页面目录功能 +# 注意:正常情况下文章中有H2-H4标题会自动生成目录,无需额外配置 #toc: false # 绝对访问路径 #url: "{{ lower .Name }}.html" diff --git a/VERSION b/VERSION index ecedc98..64b5ae3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.3.1 \ No newline at end of file +4.4.0 \ No newline at end of file diff --git a/archetypes/default.md b/archetypes/default.md index b317672..abed622 100644 --- a/archetypes/default.md +++ b/archetypes/default.md @@ -27,12 +27,12 @@ tags: # 外部链接地址,访问时直接跳转 # It's means that will redirecting to external links #extlink: -# 在当前页面开启或关闭评论功能 -# Switch to enabled or disabled comment plugins in this post +# 在当前页面关闭评论功能 +# Disabled comment plugins in this post #comment: # enable: false -# 开启文章目录功能 -# Enable table of content +# 关闭文章目录功能 +# Disable table of content #toc: false # 绝对访问路径 # Absolute link for visit diff --git a/assets/css/_common/components/post/index.scss b/assets/css/_common/components/post/index.scss index 179fc44..186c464 100644 --- a/assets/css/_common/components/post/index.scss +++ b/assets/css/_common/components/post/index.scss @@ -42,6 +42,7 @@ } } +@if $toc_number { .autonumber { h2 { counter-reset: h3; @@ -66,6 +67,7 @@ content: counter(h2) "." counter(h3) "." counter(h4) ". "; } } +} } @import 'post-collapse'; diff --git a/assets/css/_common/components/third-party/search.scss b/assets/css/_common/components/third-party/search.scss index d9a3e6a..db7369b 100644 --- a/assets/css/_common/components/third-party/search.scss +++ b/assets/css/_common/components/third-party/search.scss @@ -24,7 +24,7 @@ .search-popup { background: var(--card-bg-color); border-radius: 5px; - height: 80%; + height: 65%; margin: auto; transform: scale(0); transition: transform .4s; @@ -55,12 +55,7 @@ } .search-header { - background: $gainsboro; - @if $darkmode { - @media (prefers-color-scheme: dark) { - background: $grey-dim; - } - } + background: var(--content-bg-color); border-top-left-radius: 5px; border-top-right-radius: 5px; display: flex; @@ -72,6 +67,7 @@ border: 0; outline: 0; width: 100%; + color: var(--text-color); &::-webkit-search-cancel-button { display: none; @@ -81,15 +77,46 @@ .search-result-container { height: calc(100% - 55px); overflow: auto; - padding: 5px 25px; + padding: 0px 25px; + } - hr { - margin: 5px 0 10px; + .search-footer { + background: var(--content-bg-color); + border-bottom-left-radius: 5px; + border-bottom-right-radius: 5px; + padding: 0 5px; + color: var(--text-color); - &:first-child { - display: none; + .search-meta-info { + height: 26px; + display: flex; + padding: 5px 0; + + .search-hit-stats { + font-size: $font-size-smaller; + width: 65%; + padding: 2px 8px; + } + + .search-vendor { + width: 34%; + text-align: right; + font-size: $font-size-small; + font-weight: bold; + + img { + width: 68px; + margin: 5px; + vertical-align: middle; + display: inline; + } + + a { + border: none; + } } } + } .search-result-list { @@ -137,9 +164,16 @@ .algolia-pagination { // Override default style of ul - margin: 40px 0; + //margin: 40px 0; opacity: 1; padding: 0; + font-size: $font-size-smallest; + margin-bottom: -16px; + + .pagination { + visibility: visible; + margin: 0; + } .pagination-item { display: inline-block; @@ -176,4 +210,4 @@ margin: auto; } } -} +} \ No newline at end of file diff --git a/assets/css/_common/components/third-party/waline.scss b/assets/css/_common/components/third-party/waline.scss index dc2b87c..2e57eb4 100644 --- a/assets/css/_common/components/third-party/waline.scss +++ b/assets/css/_common/components/third-party/waline.scss @@ -2,4 +2,17 @@ .wl-actions>button:nth-child(3) { display: none } + + @include mobile() { + .wl-reaction-img { + width: 28px; + height: 28px; + } + .wl-reaction-votes { + padding: 0.85px; + font-weight: 500; + font-size: .65em; + line-height: .85; + } + } } \ No newline at end of file diff --git a/assets/css/_common/components/tool-buttons.scss b/assets/css/_common/components/tool-buttons.scss index ae29f0b..2f06f6d 100644 --- a/assets/css/_common/components/tool-buttons.scss +++ b/assets/css/_common/components/tool-buttons.scss @@ -2,9 +2,12 @@ @include sidebar-toggle(); background: none; - bottom: 55px; + bottom: 58px; filter: alpha(opacity=0); - font-size: 12px; + font-size: $font-size-smaller; + @include mobile() { + font-size: $font-size-smallest; + } .button { display: block; @@ -15,7 +18,6 @@ background-color: $tool-btn-bg; color: $tool-btn-color; text-align: center; - font-size: $font-size-larger; line-height: 35px; padding: 0; outline: 0; @@ -25,6 +27,13 @@ opacity: $tool-btn-opacity; touch-action: manipulation; + @include mobile() { + width: 24px; + height: 24px; + line-height: 24px; + border-radius: 3px; + } + &:hover { color: $tool-btn-hover-fore-color; opacity: $tool-btn-opacity-hover; @@ -32,7 +41,7 @@ } .goto-comments { - display: none; + display: none; } .goto-comments-on { @@ -42,7 +51,6 @@ @if $back2top_enable { .back-to-top { - font-size: $font-size-smaller; @if not $back2top_scrollpercent { span { @@ -51,7 +59,7 @@ } @if $back2top_sidebar { - margin: 20px - $sidebar-offset -10px -20px; + margin: 20px -$sidebar-offset -10px -20px; opacity: 0; transition: opacity $transition-ease; diff --git a/assets/css/_common/outline/footer/index.scss b/assets/css/_common/outline/footer/index.scss index 03cf5c6..be1ba96 100644 --- a/assets/css/_common/outline/footer/index.scss +++ b/assets/css/_common/outline/footer/index.scss @@ -32,10 +32,10 @@ .google-translate { display: flex; justify-content: center; - - i { + .fa { font-size: $font-size-larger; margin: auto 0; + line-height: normal; } } diff --git a/assets/css/_common/outline/sidebar/index.scss b/assets/css/_common/outline/sidebar/index.scss index da01454..dd214ac 100644 --- a/assets/css/_common/outline/sidebar/index.scss +++ b/assets/css/_common/outline/sidebar/index.scss @@ -27,6 +27,8 @@ img { display: inline-block; + max-width: 120px; + max-height: 42px; } } diff --git a/assets/css/_common/outline/sidebar/sidebar-author.scss b/assets/css/_common/outline/sidebar/sidebar-author.scss index b903716..f1f6e41 100644 --- a/assets/css/_common/outline/sidebar/sidebar-author.scss +++ b/assets/css/_common/outline/sidebar/sidebar-author.scss @@ -1,6 +1,7 @@ .site-author-image { border: $site-author-image-border-width solid $site-author-image-border-color; - max-width: $site-author-image-width; + width: $site-author-image-width; + height: $site-author-image-width; padding: 2px; @if $avatar_rounded { diff --git a/assets/css/_common/outline/sidebar/sidebar-toc.scss b/assets/css/_common/outline/sidebar/sidebar-toc.scss index 29eba64..085143d 100644 --- a/assets/css/_common/outline/sidebar/sidebar-toc.scss +++ b/assets/css/_common/outline/sidebar/sidebar-toc.scss @@ -2,6 +2,10 @@ font-size: $font-size-small; padding: 0 8px; + .active-current { + color: $orange; + } + ul { list-style: none; @@ -15,22 +19,22 @@ > ul { border-left: 1px solid; - margin-left: 6px; + margin-left: 4px; li { position: relative; padding-left: 0; - + &:before { position: absolute; content: ' '; top: 0.14em; left: -0.75em; - width: 0.68em; + width: 0.65em; height: 0.815em; border-style: none none dashed none; border-width: 0.05em; - } + } } } @@ -42,10 +46,11 @@ a { transition: all $transition-ease; border: none; - - &:before { - content: counters(item, ".") ". "; - counter-increment: item; + @if $toc_number { + &:before { + content: counters(item, ".") ". "; + counter-increment: item; + } } &:hover { diff --git a/assets/css/_mixins.scss b/assets/css/_mixins.scss index 10b2ebe..e0c65c5 100644 --- a/assets/css/_mixins.scss +++ b/assets/css/_mixins.scss @@ -1,6 +1,6 @@ @mixin mobile-smallest() { @media (max-width: 413px) { - @content;; + @content; } } diff --git a/assets/css/_variables/base.scss b/assets/css/_variables/base.scss index f6d9045..f41ea0a 100644 --- a/assets/css/_variables/base.scss +++ b/assets/css/_variables/base.scss @@ -296,7 +296,7 @@ $b2t-opacity-hover : 1; $b2t-position-bottom : -100px; $b2t-position-bottom-on : 19px; $b2t-position-right : 30px; -$b2t-position-right-mobile : 20px; +$b2t-position-right-mobile : 16px; $b2t-font-size : 12px; $b2t-color : white; $b2t-bg-color : $black-deep; diff --git a/assets/css/gt.scss b/assets/css/gt.scss deleted file mode 100644 index 65d3251..0000000 --- a/assets/css/gt.scss +++ /dev/null @@ -1,892 +0,0 @@ -:root { - --gt-blue: #2640b2; - --gt-border: #d1d5db; -} - -@keyframes "goog-te-spinner-rotator" { - 0% { - transform: rotate(0deg); - } - 100% { - transform: rotate(270deg); - } -} -@keyframes "goog-te-spinner-dash" { - 0% { - stroke-dashoffset: 187; - } - 50% { - stroke-dashoffset: 46.75; - transform: rotate(135deg); - } - 100% { - stroke-dashoffset: 187; - transform: rotate(450deg); - } -} -.goog-te-banner-frame { - left: 0px; - top: 0px; - height: 39px; - width: 100%; - z-index: 10000001; - position: fixed; - border: none; - border-bottom: 1px solid #6b90da; - margin: 0; - box-shadow: 0 0 8px 1px #999999; - _position: absolute; -} -.goog-te-menu-frame { - z-index: 10000002; - position: fixed; - box-shadow: 0.5rem 0.875rem 2.375rem rgba(39, 44, 49, 0.06), 0.0625rem 0.1875rem 0.5rem rgba(39, 44, 49, 0.03); - _position: absolute; -} -.goog-te-ftab-frame { - z-index: 10000000; - border: none; - margin: 0; -} -.goog-te-gadget { - font-family: arial; - font-size: 11px; - color: #666; - white-space: nowrap; - display: inline-flex; - img { - vertical-align: middle; - border: none; - display: inline-block; - } - .goog-te-combo { - margin: 4px 0; - } - - div:first-child { - margin: 0 10px; - } -} -.goog-te-gadget-simple { - background-color: #fff; - border-left: 1px solid #d5d5d5; - border-top: 1px solid #9b9b9b; - border-bottom: 1px solid #e8e8e8; - border-right: 1px solid #d5d5d5; - font-size: 10pt; - display: inline-block; - padding-top: 1px; - padding-bottom: 2px; - cursor: pointer; - zoom: 1; - *display: inline; - .goog-te-menu-value { - color: #000; - span { - text-decoration: none; - } - } -} -.goog-te-gadget-icon { - margin-left: 2px; - margin-right: 2px; - width: 19px; - height: 19px; - border: none; - vertical-align: middle; -} -.goog-te-combo { - margin-left: 4px; - margin-right: 4px; - vertical-align: baseline; - *vertical-align: middle; - font-family: arial; - font-size: 10pt; -} -.goog-logo-link { - font-size: 12px; - font-weight: bold; - color: #444; - text-decoration: none; - margin: 0 5px; - border-bottom: 0; - &:link { - font-size: 12px; - font-weight: bold; - color: #444; - text-decoration: none; - } - &:visited { - font-size: 12px; - font-weight: bold; - color: #444; - text-decoration: none; - } - &:hover { - font-size: 12px; - font-weight: bold; - color: #444; - text-decoration: none; - } - &:active { - font-size: 12px; - font-weight: bold; - color: #444; - text-decoration: none; - } -} -.goog-te-banner { - .goog-logo-link { - display: block; - margin: 0px 10px; - padding-top: 2px; - padding-left: 4px; - } - * { - font-family: arial; - font-size: 10pt; - } - margin: 0; - background-color: #fff; - overflow: hidden; - img { - border: none; - } - table { - tbody { - tr { - td { - &:nth-child(2) { - display: none; - } - } - } - } - } -} -.goog-close-link { - display: block; - margin: 0px 10px; -} -.goog-te-ftab { - * { - font-family: arial; - font-size: 10pt; - } - margin: 0px; - background-color: #fff; - white-space: nowrap; -} -.goog-te-menu { - * { - font-family: arial; - font-size: 10pt; - } - background-color: #ffffff; - text-decoration: none; - border: 2px solid #c3d9ff; - overflow-y: scroll; - overflow-x: hidden; - position: absolute; - left: 0; - top: 0; -} -.goog-te-menu2 { - * { - font-family: arial; - font-size: 10pt; - } - background-color: #ffffff; - text-decoration: none; - overflow: hidden; - padding: 4px; - border: 1px solid var(--gt-border); - border-radius: 4px; -} -.goog-te-balloon { - * { - font-family: arial; - font-size: 10pt; - } - background-color: #ffffff; - overflow: hidden; - padding: 8px; - border: none; - border-radius: 10px; - img { - border: none; - } -} -.goog-te-banner-content { - color: #000; - img { - vertical-align: middle; - } -} -.goog-te-banner-info { - color: #666; - vertical-align: top; - margin-top: 0px; - font-size: 7pt; -} -.goog-te-banner-margin { - width: 8px; -} -.goog-te-button { - div { - border: 1px solid var(--gt-border); - height: 20px; - } - button { - background: transparent; - border: none; - cursor: pointer; - height: 20px; - overflow: hidden; - margin: 0; - vertical-align: top; - white-space: nowrap; - &:active { - background: none repeat scroll 0 0 #cccccc; - } - } -} -.goog-te-ftab-link { - text-decoration: none; - font-weight: bold; - font-size: 10pt; - border: 1px outset #888; - padding: 6px 10px; - white-space: nowrap; - position: absolute; - left: 0px; - top: 0px; - img { - margin-left: 2px; - margin-right: 2px; - width: 19px; - height: 19px; - border: none; - vertical-align: middle; - } - span { - text-decoration: underline; - margin-left: 2px; - margin-right: 2px; - vertical-align: middle; - } -} -.goog-float-top { - .goog-te-ftab-link { - padding: 2px 2px; - border-top-width: 0px; - } -} -.goog-float-bottom { - .goog-te-ftab-link { - padding: 2px 2px; - border-bottom-width: 0px; - } -} -.goog-te-menu-value { - text-decoration: none; - color: var(--gt-blue); - white-space: nowrap; - margin-left: 4px; - margin-right: 4px; - span { - text-decoration: underline; - &::after { - content: "▼"; - } - } - img { - margin-left: 2px; - margin-right: 2px; - display: none; - } -} -.goog-te-menu-item { - padding: 3px; - text-decoration: none; - color: var(--gt-blue); - background: #ffffff; - &:link { - color: var(--gt-blue); - background: #ffffff; - } - &:visited { - color: #551a8b; - } - &:hover { - background: #c3d9ff; - } - &:active { - color: var(--gt-blue); - } -} -.goog-te-menu2-colpad { - width: 16px; -} -.goog-te-menu2-separator { - margin: 6px 0; - height: 1px; - background-color: var(--gt-border); - overflow: hidden; -} -.goog-te-menu2-item { - div { - padding: 4px; - color: var(--gt-blue); - background: #ffffff; - } - .indicator { - display: none; - } - text-decoration: none; - &:link { - div { - color: var(--gt-blue); - background: #ffffff; - } - } - &:visited { - div { - color: var(--gt-blue); - background: #ffffff; - } - } - &:active { - div { - color: var(--gt-blue); - background: #ffffff; - } - } - &:hover { - div { - color: #ffffff; - background: #3366cc; - border-radius: 2px; - } - } -} -.goog-te-menu2-item-selected { - div { - padding: 4px; - color: #000; - font-weight: bold; - } - .indicator { - display: auto; - } - .text { - padding-left: 4px; - padding-right: 4px; - } - text-decoration: none; - &:link { - div { - color: #000; - font-weight: bold; - } - } - &:visited { - div { - color: #000; - font-weight: bold; - } - } - &:hover { - div { - color: #000; - font-weight: bold; - } - } - &:active { - div { - color: #000; - font-weight: bold; - } - } -} -.goog-te-balloon-frame { - background-color: #ffffff; - border: 1px solid #6b90da; - box-shadow: 0.5rem 0.875rem 2.375rem rgba(39, 44, 49, 0.06), 0.0625rem 0.1875rem 0.5rem rgba(39, 44, 49, 0.03); - border-radius: 8px; -} -.goog-te-balloon-text { - margin-top: 6px; -} -.goog-te-balloon-zippy { - margin-top: 6px; - white-space: nowrap; - * { - vertical-align: middle; - } - .minus { - background-image: url(//www.google.com/images/zippy_minus_sm.gif); - } - .plus { - background-image: url(//www.google.com/images/zippy_plus_sm.gif); - } - span { - color: #00c; - text-decoration: underline; - cursor: pointer; - margin: 0 4px; - } -} -.goog-te-balloon-form { - margin: 6px 0 0 0; - form { - margin: 0; - textarea { - margin-bottom: 4px; - width: 100%; - } - } -} -.goog-te-balloon-footer { - margin: 6px 0 4px 0; -} -.goog-te-spinner-pos { - z-index: 1000; - position: fixed; - transition-delay: 0.6s; - left: -1000px; - top: -1000px; -} -.goog-te-spinner-animation { - background: #ccc; - display: flex; - align-items: center; - justify-content: center; - width: 104px; - height: 104px; - border-radius: 50px; - background: #fff url(//www.gstatic.com/images/branding/product/2x/translate_24dp.png) 50% 50% no-repeat; - transition: all 0.6s ease-in-out; - transform: scale(0.4); - opacity: 0; -} -.goog-te-spinner-animation-show { - transform: scale(0.5); - opacity: 1; -} -.goog-te-spinner { - margin: 2px 0 0 2px; - animation: goog-te-spinner-rotator 1.4s linear infinite; -} -.goog-te-spinner-path { - stroke-dasharray: 187; - stroke-dashoffset: 0; - stroke: #4285f4; - transform-origin: center; - animation: goog-te-spinner-dash 1.4s ease-in-out infinite; -} -#goog-gt-tt { - color: #222; - background-color: #ffffff; - border: 1px solid #eee; - box-shadow: 0 4px 16px rgba(0,0,0,.2); - display: none; - font-family: arial; - font-size: 10pt; - width: 420px; - padding: 12px; - position: absolute; - z-index: 10000; - .original-text { - clear: both; - font-size: 10pt; - position: relative; - text-align: justify; - width: 100%; - } - .title { - color: #999; - font-family: arial,sans-serif; - margin: 4px 0; - text-align: left; - } - .close-button { - display: none; - } - .logo { - float: left; - margin: 0px; - } - .activity-links { - display: inline-block; - } - .started-activity-container { - display: none; - width: 100%; - } - .activity-root { - margin-top: 20px; - } - .left { - float: left; - } - .right { - float: right; - } - .bottom { - min-height: 15px; - position: relative; - height: 1%; - } - .status-message { - background: linear-gradient(top,#29910d 0%,#20af0e 100%); - background: #29910d; - border-radius: 4px; - box-shadow: inset 0px 2px 2px #1e6609; - color: white; - font-size: 9pt; - font-weight: bolder; - margin-top: 12px; - padding: 6px; - text-shadow: 1px 1px 1px #1e6609; - } - .activity-link { - color: #1155cc; - cursor: pointer; - font-family: arial; - font-size: 11px; - margin-right: 15px; - text-decoration: none; - } - textarea { - font-family: arial; - resize: vertical; - width: 100%; - margin-bottom: 10px; - border-radius: 1px; - border: 1px solid #d9d9d9; - border-top: 1px solid silver; - font-size: 13px; - height: auto; - overflow-y: auto; - padding: 1px; - &:focus { - box-shadow: inset 0 1px 2px rgba(0,0,0,0.3); - border: 1px solid #4d90fe; - outline: none; - } - } - .activity-cancel { - margin-right: 10px; - } - .translate-form { - min-height: 25px; - vertical-align: middle; - padding-top: 8px; - .activity-form { - margin-bottom: 5px; - margin-bottom: 0px; - input { - display: inline-block; - min-width: 54px; - *min-width: 70px; - border: 1px solid #dcdcdc; - border: 1px solid rgba(0,0,0,0.1); - text-align: center; - color: #444; - font-size: 11px; - font-weight: bold; - height: 27px; - outline: 0; - padding: 0 8px; - vertical-align: middle; - line-height: 27px; - margin: 0 16px 0 0; - box-shadow: 0 1px 2px rgba(0,0,0,.1); - border-radius: 2px; - transition: all 0.218s; - background-color: #f5f5f5; - background-image: linear-gradient(top,#f5f5f5,#f1f1f1); - -webkit-user-select: none; - -moz-user-select: none; - cursor: default; - &:hover { - border: 1px solid #c6c6c6; - color: #222; - transition: all 0.0s; - background-color: #f8f8f8; - background-image: linear-gradient(top,#f8f8f8,#f1f1f1); - border-color: #3079ed; - } - &:active { - border: 1px solid #c6c6c6; - color: #333; - background-color: #f6f6f6; - background-image: linear-gradient(top,#f6f6f6,#f1f1f1); - border-color: #3079ed; - } - &:focus { - #goog-gt-tt { - .translate-form { - .activity-form { - input.focus { - #goog-gt-tt { - .translate-form { - .activity-form { - input { - &:active { - box-shadow: inset 0 0 0 1px rgba(255,255,255,0.5); - } - } - } - } - } - } - } - } - } - &:active { - box-shadow: inset 0 0 0 1px rgba(255,255,255,0.5); - } - outline: none; - border: 1px solid #4d90fe; - z-index: 4 !important; - border-color: #3079ed; - } - &.focus { - &:active { - box-shadow: inset 0 0 0 1px rgba(255,255,255,0.5); - } - } - } - input.focus { - outline: none; - border: 1px solid #4d90fe; - z-index: 4 !important; - border-color: #3079ed; - } - input.selected { - background-color: #eeeeee; - background-image: linear-gradient(top,#eeeeee,#e0e0e0); - box-shadow: inset 0px 1px 2px rgba(0,0,0,0.1); - border: 1px solid #ccc; - color: #333; - } - input.activity-submit { - color: white; - border-color: #3079ed; - background-color: #4d90fe; - background-image: linear-gradient(top,#4d90fe,#4787ed); - &:hover { - #goog-gt-tt { - .translate-form { - .activity-form { - input.activity-submit { - &:focus { - border-color: #3079ed; - background-color: #357ae8; - background-image: linear-gradient(top,#4d90fe,#357ae8); - } - } - } - } - } - box-shadow: inset 0 0 0 1px #fff,0px 1px 1px rgba(0,0,0,0.1); - border-color: #3079ed; - } - &:focus { - border-color: #3079ed; - } - &:active { - border-color: #3079ed; - } - } - input.activity-submit.focus { - #goog-gt-tt { - .translate-form { - .activity-form { - input.activity-submit { - &:active { - border-color: #3079ed; - background-color: #357ae8; - background-image: linear-gradient(top,#4d90fe,#357ae8); - } - } - } - } - } - border-color: #3079ed; - } - } - } - .gray { - color: #999; - font-family: arial,sans-serif; - } - .alt-helper-text { - color: #999; - font-size: 11px; - font-family: arial,sans-serif; - margin: 15px 0px 5px 0px; - } - .alt-error-text { - color: #800; - display: none; - font-size: 9pt; - } - .alt-menu.goog-menu { - background: #ffffff; - border: 1px solid #dddddd; - box-shadow: 0px 2px 4px #99a; - min-width: 0; - outline: none; - padding: 0; - position: absolute; - z-index: 2000; - } - .alt-menu { - .goog-menuitem { - cursor: pointer; - padding: 2px 5px 5px; - margin-right: 0px; - border-style: none; - h1 { - font-size: 100%; - font-weight: bold; - margin: 4px 0px; - } - strong { - color: #345aad; - } - } - div.goog-menuitem { - &:hover { - background: #ddd; - } - } - } - .goog-submenu-arrow { - text-align: right; - position: absolute; - right: 0; - left: auto; - } - .goog-menuitem-rtl { - .goog-submenu-arrow { - text-align: left; - position: absolute; - left: 0; - right: auto; - } - } - .gt-hl-text { - background-color: #f1ea00; - border-radius: 4px; - box-shadow: rgba(0,0,0,.5) 3px 3px 4px; - box-sizing: border-box; - color: #f1ea00; - cursor: pointer; - margin: -2px -2px -2px -3px; - padding: 2px 2px 2px 3px; - position: relative; - } - .trans-target-highlight { - background-color: #f1ea00; - border-radius: 4px; - box-shadow: rgba(0,0,0,.5) 3px 3px 4px; - box-sizing: border-box; - color: #f1ea00; - cursor: pointer; - margin: -2px -2px -2px -3px; - padding: 2px 2px 2px 3px; - position: relative; - color: #222; - } - .gt-hl-layer { - color: white; - position: absolute !important; - } - .trans-target { - background-color: #c9d7f1; - border-radius: 4px 4px 0px 0px; - box-shadow: rgba(0,0,0,.5) 3px 3px 4px; - box-sizing: border-box; - cursor: pointer; - margin: -2px -2px -2px -3px; - padding: 2px 2px 3px 3px; - position: relative; - .trans-target-highlight { - background-color: #c9d7f1; - border-radius: 4px 4px 0px 0px; - box-shadow: rgba(0,0,0,.5) 3px 3px 4px; - box-sizing: border-box; - cursor: pointer; - margin: -2px -2px -2px -3px; - padding: 2px 2px 3px 3px; - position: relative; - } - } - .trans-edit { - background-color: transparent; - border: 1px solid #4d90fe; - border-radius: 0em; - margin: -2px; - padding: 1px; - } - .gt-trans-highlight-l { - border-left: 2px solid red; - margin-left: -2px; - } - .gt-trans-highlight-r { - border-right: 2px solid red; - margin-right: -2px; - } - #alt-input { - padding: 2px; - } - #alt-input-text { - font-size: 11px; - padding: 2px 2px 3px; - margin: 0; - background-color: #fff; - color: #333; - border: 1px solid #d9d9d9; - border-top: 1px solid #c0c0c0; - display: inline-block; - vertical-align: top; - height: 21px; - box-sizing: border-box; - &:hover { - border: 1px solid #b9b9b9; - border-top: 1px solid #a0a0a0; - box-shadow: inset 0px 1px 2px rgba(0,0,0,0.1); - } - &:focus { - box-shadow: inset 0px 1px 2px rgba(0,0,0,0.3); - outline: none; - border: 1px solid #4d90fe; - } - } - #alt-input-submit { - font-size: 11px; - padding: 2px 6px 3px; - margin: 0 0 0 2px; - height: 21px; - } -} -div#goog-gt-tt { - padding: 10px 14px; -} -.gt-hl-layer { - clear: both; - font-size: 10pt; - position: relative; - text-align: justify; - width: 100%; -} -.goog-text-highlight { - background-color: #c9d7f1; - box-shadow: 2px 2px 4px #9999aa; - box-sizing: border-box; - position: relative; -} \ No newline at end of file diff --git a/assets/css/main.scss b/assets/css/main.scss index 0907ec5..7d0f14e 100644 --- a/assets/css/main.scss +++ b/assets/css/main.scss @@ -70,6 +70,7 @@ $social_icons_only : {{ $P.socialIcons.iconsOnly }}; $social_icons_transition : {{ $P.socialIcons.transition }}; $links_settings_layout : {{ $P.linksSets.layout }}; $toc_enable : {{ $P.toc.enable }}; +$toc_number : {{ $P.toc.number }}; $toc_expand_all : {{ $P.toc.expandAll }}; $toc_wrap : {{ $P.toc.wrap }}; diff --git a/assets/js/config.js b/assets/js/config.js index 1ca46e6..41169df 100644 --- a/assets/js/config.js +++ b/assets/js/config.js @@ -1,4 +1,52 @@ -if (!window.NexT) window.NexT = {}; +/* global NexT, boot, CONFIG */ +window.NexT = {}; +NexT.boot = {}; +NexT.plugins = {}; + +// Defined comment component & add register event +NexT.plugins.comments = {}; +NexT.plugins.comments.register = function() { + if (!NexT.CONFIG.page.comments) return; + for(var c in NexT.plugins.comments) { + if (c === 'register') continue; + eval('NexT.plugins.comments.'+c)(); + }; +} + +// Defined search engine & add register event +NexT.plugins.search = {} +NexT.plugins.search.register = function() { + for(var s in NexT.plugins.search) { + if (s === 'register') continue; + eval('NexT.plugins.search.'+s)(); + }; +} + +// Defined share plugin & add register event +NexT.plugins.share = {} +NexT.plugins.share.register = function() { + for(var s in NexT.plugins.share) { + if (s === 'register') continue; + eval('NexT.plugins.share.'+s)(); + }; +} + +// Defined other plugin & add register event +NexT.plugins.others = {} +NexT.plugins.others.register = function() { + for(var o in NexT.plugins.others) { + if (o === 'register') continue; + eval('NexT.plugins.others.'+o)(); + }; +} + +// Add event to register all third party plugins +NexT.plugins.register = function() { + for(var p in NexT.plugins) { + if (p === 'register') continue; + eval('NexT.plugins.'+p+'.register')(); + } +}; (function() { const className = 'next-config'; diff --git a/assets/js/next-boot.js b/assets/js/next-boot.js index 9c66eb1..8b55d29 100644 --- a/assets/js/next-boot.js +++ b/assets/js/next-boot.js @@ -1,15 +1,28 @@ -/* global NexT, CONFIG */ +/* boot starup */ -NexT.boot = {}; +(function () { + const onPageLoaded = () => document.dispatchEvent( + new Event('page:loaded', { + bubbles: true + }) + ); -NexT.boot.activeThemeMode = function(){ - NexT.utils.activeThemeMode(); -}; + if (document.readyState === 'loading') { + document.addEventListener('readystatechange', onPageLoaded, { once: true }); + } else { + onPageLoaded(); + } + document.addEventListener('pjax:success', onPageLoaded); +})(); NexT.boot.registerEvents = function() { + NexT.utils.registerImageLoadEvent(); NexT.utils.registerScrollPercent(); // NexT.utils.registerCanIUseTag(); + NexT.utils.registerToolButtons(); + // Register comment's components + NexT.plugins.register(); // Mobile top menu bar. document.querySelector('.site-nav-toggle .toggle').addEventListener('click', event => { @@ -37,14 +50,11 @@ NexT.boot.registerEvents = function() { NexT.boot.refresh = function() { - NexT.utils.calSiteInfo(); - NexT.utils.regSwitchThemeBtn(); + NexT.utils.fmtSiteInfo(); if (!NexT.CONFIG.page.isPage) return; NexT.utils.registerSidebarTOC(); - - NexT.utils.replacePostCRLink(); NexT.utils.registerCopyCode(); NexT.utils.registerPostReward(); if(NexT.CONFIG.page.comments) { @@ -54,6 +64,7 @@ NexT.boot.refresh = function() { } else { NexT.utils.hideCommontes(); } + NexT.utils.registerImageViewer(); //TODO /** @@ -88,7 +99,6 @@ NexT.boot.motion = function() { }; document.addEventListener('DOMContentLoaded', () => { - NexT.boot.activeThemeMode(); NexT.boot.registerEvents(); NexT.boot.motion(); NexT.boot.refresh(); diff --git a/assets/js/third-party/comments/artalk.js b/assets/js/third-party/comments/artalk.js index 8b5dcc2..827f2dd 100644 --- a/assets/js/third-party/comments/artalk.js +++ b/assets/js/third-party/comments/artalk.js @@ -1,13 +1,9 @@ -document.addEventListener('DOMContentLoaded', () => { - +/* Artalk comment plugin */ +NexT.plugins.comments.artalk = function() { const element = '.artalk-container'; - if (!NexT.CONFIG.page.comments - || !NexT.CONFIG.artalk + if (!NexT.CONFIG.artalk || !NexT.utils.checkDOMExist(element)) return; - const artalk_css = NexT.utils.getCDNResource(NexT.CONFIG.artalk.css); - NexT.utils.getStyle(artalk_css, null); - const artalk_js = NexT.utils.getCDNResource(NexT.CONFIG.artalk.js); const { site, @@ -15,10 +11,10 @@ document.addEventListener('DOMContentLoaded', () => { server, } = NexT.CONFIG.artalk.cfg; - NexT.utils.loadComments(element) - .then(() => NexT.utils.getScript(artalk_js, { - })) - .then(() => { + NexT.utils.lazyLoadComponent(element, function() { + NexT.utils.getScript(artalk_js, function(){ + const artalk_css = NexT.utils.getCDNResource(NexT.CONFIG.artalk.css); + NexT.utils.getStyle(artalk_css); new Artalk({ el : element, @@ -29,8 +25,9 @@ document.addEventListener('DOMContentLoaded', () => { locale : NexT.CONFIG.lang, placeholder : placeholder, darkMode : 'auto' - }); + }); + }); - NexT.utils.hiddeLodingCmp(element); + NexT.utils.hiddeLodingCmp(element); }); -}); \ No newline at end of file +} \ No newline at end of file diff --git a/assets/js/third-party/comments/giscus.js b/assets/js/third-party/comments/giscus.js index 62529a8..2147daa 100644 --- a/assets/js/third-party/comments/giscus.js +++ b/assets/js/third-party/comments/giscus.js @@ -1,5 +1,5 @@ -document.addEventListener('DOMContentLoaded', () => { - +/* Giscus comment plugin */ +NexT.plugins.comments.giscus = function() { const element = '.giscus-container'; if (!NexT.CONFIG.page.comments || !NexT.CONFIG.giscus @@ -17,8 +17,8 @@ document.addEventListener('DOMContentLoaded', () => { theme } = NexT.CONFIG.giscus.cfg; - NexT.utils.loadComments(element) - .then(() => NexT.utils.getScript(NexT.CONFIG.giscus.js, { + NexT.utils.lazyLoadComponent(element, function() { + NexT.utils.getScript(NexT.CONFIG.giscus.js, { attributes: { 'async' : true, 'crossorigin' : 'anonymous', @@ -35,7 +35,8 @@ document.addEventListener('DOMContentLoaded', () => { 'data-loading' : 'lazy' }, parentNode: document.querySelector(element) - })); - + }); + NexT.utils.hiddeLodingCmp(element); -}); \ No newline at end of file + }); +} \ No newline at end of file diff --git a/assets/js/third-party/comments/livere.js b/assets/js/third-party/comments/livere.js index 2051f05..2d1820c 100644 --- a/assets/js/third-party/comments/livere.js +++ b/assets/js/third-party/comments/livere.js @@ -1,11 +1,10 @@ -document.addEventListener('DOMContentLoaded', () => { - +/* LiveRe comment plugin */ +NexT.plugins.comments.livere = function() { const element = '#lv-container'; - if (!NexT.CONFIG.page.comments - || !NexT.CONFIG.livere + if (!NexT.CONFIG.livere || !NexT.utils.checkDOMExist(element)) return; - NexT.utils.loadComments(element).then(() => { + NexT.utils.lazyLoadComponent(element, function() { NexT.utils.getScript(NexT.CONFIG.livere.js, { attributes: { async: true @@ -15,4 +14,4 @@ document.addEventListener('DOMContentLoaded', () => { NexT.utils.hiddeLodingCmp(element); }); -}); +} diff --git a/assets/js/third-party/comments/utterances.js b/assets/js/third-party/comments/utterances.js index afb6751..0e32c64 100644 --- a/assets/js/third-party/comments/utterances.js +++ b/assets/js/third-party/comments/utterances.js @@ -1,8 +1,7 @@ -document.addEventListener('DOMContentLoaded', () => { - +/* Utterances comment plugin */ +NexT.plugins.comments.utterances = function() { const element = '.utterances-container'; - if (!NexT.CONFIG.page.comments - || !NexT.CONFIG.utterances + if (!NexT.CONFIG.utterances || !NexT.utils.checkDOMExist(element)) return; const { @@ -11,17 +10,19 @@ document.addEventListener('DOMContentLoaded', () => { label, theme } = NexT.CONFIG.utterances.cfg; - NexT.utils.loadComments(element) - .then(() => NexT.utils.getScript(NexT.CONFIG.utterances.js, { + NexT.utils.lazyLoadComponent(element, function() { + NexT.utils.getScript(NexT.CONFIG.utterances.js, { attributes: { 'async' : true, 'crossorigin' : 'anonymous', 'repo' : repo, 'issue-term' : issueterm, + 'label' : label, 'theme' : theme }, parentNode: document.querySelector(element) - })); + }); NexT.utils.hiddeLodingCmp(element); -}); + }); +} diff --git a/assets/js/third-party/comments/waline.js b/assets/js/third-party/comments/waline.js index 97ad00a..8c3b191 100644 --- a/assets/js/third-party/comments/waline.js +++ b/assets/js/third-party/comments/waline.js @@ -1,11 +1,11 @@ -document.addEventListener('DOMContentLoaded', () => { - +/* Waline comment plugin */ +NexT.plugins.comments.waline = function() { const element = '.waline-container'; - if (!NexT.CONFIG.page.comments - || !NexT.CONFIG.waline + if (!NexT.CONFIG.waline || !NexT.utils.checkDOMExist(element)) return; const { + comment, emoji, imguploader, pageview, @@ -19,10 +19,6 @@ document.addEventListener('DOMContentLoaded', () => { reactiontitle } = NexT.CONFIG.waline.cfg; - - const waline_css = NexT.utils.getCDNResource(NexT.CONFIG.waline.css); - NexT.utils.getStyle(waline_css, null); - const waline_js = NexT.utils.getCDNResource(NexT.CONFIG.waline.js); let locale = { @@ -35,15 +31,16 @@ document.addEventListener('DOMContentLoaded', () => { locale['reaction'+index] = value; }); - NexT.utils.loadComments(element) - .then(() => NexT.utils.getScript(waline_js, { - })) - .then(() => { + NexT.utils.lazyLoadComponent(element, function () { + NexT.utils.getScript(waline_js, function(){ + const waline_css = NexT.utils.getCDNResource(NexT.CONFIG.waline.css); + NexT.utils.getStyle(waline_css, 'before'); Waline.init({ locale, el : element, pageview : pageview, + comment : comment, emoji : emoji, imageUploader : imguploader, wordLimit : wordlimit, @@ -55,5 +52,6 @@ document.addEventListener('DOMContentLoaded', () => { }); NexT.utils.hiddeLodingCmp(element); + }) }); -}); \ No newline at end of file +} \ No newline at end of file diff --git a/assets/js/third-party/others/counter.js b/assets/js/third-party/others/counter.js new file mode 100644 index 0000000..6027bee --- /dev/null +++ b/assets/js/third-party/others/counter.js @@ -0,0 +1,35 @@ +/* Page's view & comment counter plugin */ +NexT.plugins.others.counter = function() { + let busz_postview = false; + let pageview_js = undefined; + let comment_js = undefined; + + const busz = NexT.CONFIG.busuanzi; + if (busz != undefined && busz.pageview) { + busz_postview = true; + } + + // Here can append others pageview & comment plugin + const waline = NexT.CONFIG.waline; + if (waline != undefined){ + if(!busz_postview && waline.cfg.pageview) { + pageview_js = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.js[0]); + NexT.utils.getScript(pageview_js, function(){ + Waline.pageviewCount({ + serverURL: waline.cfg.serverurl + }); + }); + } + + if (waline.cfg.comment) { + comment_js = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.js[1]); + NexT.utils.getScript(comment_js, function(){ + Waline.commentCount({ + serverURL: waline.cfg.serverurl + }); + }); + } + } + + +} \ No newline at end of file diff --git a/assets/js/third-party/others/google-translate.js b/assets/js/third-party/others/google-translate.js deleted file mode 100644 index 7dc5149..0000000 --- a/assets/js/third-party/others/google-translate.js +++ /dev/null @@ -1,173 +0,0 @@ -(function () { - var gtConstEvalStartTime = new Date(); - var h = this || self, - l = /^[\w+/_-]+[=]{0,2}$/, - m = null; - function n(a) { - return (a = a.querySelector && a.querySelector("script[nonce]")) && (a = a.nonce || a.getAttribute("nonce")) && - l.test(a) ? a : "" - } - function p(a, b) { - function c() {} - c.prototype = b.prototype; - a.i = b.prototype; - a.prototype = new c; - a.prototype.constructor = a; - a.h = function (g, f, k) { - for (var e = Array(arguments.length - 2), d = 2; d < arguments.length; d++) e[d - 2] = arguments[d]; - return b.prototype[f].apply(g, e) - } - } - function q(a) { - return a - }; - function r(a) { - if (Error.captureStackTrace) Error.captureStackTrace(this, r); - else { - var b = Error().stack; - b && (this.stack = b) - } - a && (this.message = String(a)) - } - p(r, Error); - r.prototype.name = "CustomError"; - function u(a, b) { - a = a.split("%s"); - for (var c = "", g = a.length - 1, f = 0; f < g; f++) c += a[f] + (f < b.length ? b[f] : "%s"); - r.call(this, c + a[g]) - } - p(u, r); - u.prototype.name = "AssertionError"; - function v(a, b) { - throw new u("Failure" + (a ? ": " + a : ""), Array.prototype.slice.call(arguments, 1)); - }; - var w; - function x(a, b) { - this.g = b === y ? a : "" - } - x.prototype.toString = function () { - return this.g + "" - }; - var y = {}; - function z(a) { - var b = document.getElementsByTagName("head")[0]; - b || (b = document.body.parentNode.appendChild(document.createElement("head"))); - b.appendChild(a) - } - function _loadJs(a) { - var b = document; - var c = "SCRIPT"; - "application/xhtml+xml" === b.contentType && (c = c.toLowerCase()); - c = b.createElement(c); - c.type = "text/javascript"; - c.charset = "UTF-8"; - if (void 0 === w) { - b = null; - var g = h.trustedTypes; - if (g && g.createPolicy) { - try { - b = g.createPolicy("goog#html", { - createHTML: q, - createScript: q, - createScriptURL: q - }) - } catch (t) { - h.console && h.console.error(t.message) - } - w = b - } else w = b - } - a = (b = w) ? b.createScriptURL(a) : a; - a = new x(a, y); - a: { - try { - var f = c && c.ownerDocument, - k = f && (f.defaultView || f.parentWindow); - k = k || h; - if (k.Element && k.Location) { - var e = k; - break a - } - } catch (t) {} - e = null - } - if (e && "undefined" != typeof e.HTMLScriptElement && (!c || !(c instanceof e.HTMLScriptElement) && (c instanceof e - .Location || c instanceof e.Element))) { - e = typeof c; - if ("object" == e && null != c || "function" == e) try { - var d = c.constructor.displayName || c.constructor.name || Object.prototype.toString.call(c) - } catch (t) { - d = "" - } else d = void 0 === c ? "undefined" : null === c ? "null" : typeof c; - v("Argument is not a %s (or a non-Element, non-Location mock); got: %s", - "HTMLScriptElement", d) - } - a instanceof x && a.constructor === x ? d = a.g : (d = typeof a, v( - "expected object of type TrustedResourceUrl, got '" + a + "' of type " + ("object" != d ? d : a ? - Array.isArray(a) ? "array" : d : "null")), d = "type_error:TrustedResourceUrl"); - c.src = d; - (d = c.ownerDocument && c.ownerDocument.defaultView) && d != h ? d = n(d.document) : (null === m && (m = n( - h.document)), d = m); - d && c.setAttribute("nonce", d); - z(c) - } - function _loadCss(a) { - var b = document.createElement("link"); - b.type = "text/css"; - b.rel = "stylesheet"; - b.charset = "UTF-8"; - b.href = a; - z(b) - } - function _isNS(a) { - a = a.split("."); - for (var b = window, c = 0; c < a.length; ++c) - if (!(b = b[a[c]])) return !1; - return !0 - } - function _setupNS(a) { - a = a.split("."); - for (var b = window, c = 0; c < a.length; ++c) b.hasOwnProperty ? b.hasOwnProperty(a[c]) ? b = b[a[c]] : b = - b[a[c]] = {} : b = b[a[c]] || (b[a[c]] = {}); - return b - } - window.addEventListener && "undefined" == typeof document.readyState && window.addEventListener( - "DOMContentLoaded", - function () { - document.readyState = "complete" - }, !1); - if (_isNS('google.translate.Element')) { - return - }(function () { - var c = _setupNS('google.translate._const'); - c._cest = gtConstEvalStartTime; - gtConstEvalStartTime = undefined; - c._cl = navigator.language || navigator.userLanguage; - c._cuc = 'googleTranslateElementInit'; - c._cac = ''; - c._cam = ''; - c._ctkk = '449649.3822363247'; - var h = 'translate.googleapis.com'; - var s = (true ? 'https' : window.location.protocol == 'https:' ? 'https' : 'http') + '://'; - var b = s + h; - c._pah = h; - c._pas = s; - // c._pbi = b + '/translate_static/img/te_bk.gif'; - c._pbi = ''; - c._pci = b + '/translate_static/img/te_ctrl3.gif'; - c._pli = b + '/translate_static/img/loading.gif'; - c._plla = h + '/translate_a/l'; - c._pmi = b + '/translate_static/img/mini_google.png'; - c._ps = window.translateelement_styles; - c._puh = 'translate.google.cn'; - _loadCss(c._ps); - _loadJs(b + `/translate_static/js/element/main_${navigator.language || navigator.userLanguage}.js`); - })(); -})(); - -function googleTranslateElementInit(){ - new google.translate.TranslateElement({ - includedLanguages: 'zh-CN,zh-TW,en,ru', - autoDisplay:false - },'google_translate_element'); -} \ No newline at end of file diff --git a/assets/js/third-party/others/lawidget.js b/assets/js/third-party/others/lawidget.js new file mode 100644 index 0000000..ff34674 --- /dev/null +++ b/assets/js/third-party/others/lawidget.js @@ -0,0 +1,17 @@ +/* 51La sidebar data widget */ +NexT.plugins.others.lawidget = function() { + const element = '#siteinfo-card-widget'; + const lawt_js = NexT.CONFIG.lawidget.js.replace('laId', NexT.CONFIG.lawidget.id); + + NexT.utils.lazyLoadComponent(element, function () { + NexT.utils.getScript(lawt_js,{ + attributes: { + id: 'LA-DATA-WIDGET', + crossorigin: 'anonymous', + charset: 'UTF-8', + defer: true + }, + parentNode: document.getElementById('la-siteinfo-widget') + }, NexT.utils.fmtLaWidget()); + }); +} \ No newline at end of file diff --git a/assets/js/third-party/others/math.js b/assets/js/third-party/others/math.js new file mode 100644 index 0000000..5ec5639 --- /dev/null +++ b/assets/js/third-party/others/math.js @@ -0,0 +1,38 @@ +/* Math render plugin */ +NexT.plugins.others.math = function() { + const render = NexT.CONFIG.page.math.render; + + if (render === 'mathjax') { + const render_js = NexT.utils.getCDNResource(NexT.CONFIG.page.math.js); + NexT.utils.getScript(render_js, function(){ + window.MathJax = { + tex: { + inlineMath: [["$", "$"]], + } + }; + }); + } + + if (render === 'katex') { + const render_css = NexT.utils.getCDNResource(NexT.CONFIG.page.math.css); + NexT.utils.getStyle(render_css); + const render_js_list = NexT.CONFIG.page.math.js; + render_js_list.forEach(js => { + const js_loader = NexT.utils.getScript(NexT.utils.getCDNResource(js)); + if(js.name === 'auto-render') { + js_loader.then(function(){ + renderMathInElement(document.body, { + delimiters: [ + {left: '$$', right: '$$', display: true}, + {left: '$', right: '$', display: false}, + {left: '\\(', right: '\\)', display: false}, + {left: '\\[', right: '\\]', display: true} + ], + + throwOnError : false + }) + }); + } + }); + } +} \ No newline at end of file diff --git a/assets/js/third-party/others/mermaid.js b/assets/js/third-party/others/mermaid.js new file mode 100644 index 0000000..69a4a93 --- /dev/null +++ b/assets/js/third-party/others/mermaid.js @@ -0,0 +1,15 @@ +/* Mermaid plugin */ +NexT.plugins.others.mermaid = function() { + const mermaid_js = NexT.utils.getCDNResource(NexT.CONFIG.page.mermaid.js); + + NexT.utils.getScript(mermaid_js, function(){ + mermaid.initialize({ + sequence: { + showSequenceNumbers: true, + actorMargin: 50, + diagramMarginX:10, + diagramMarginY:10 + } + }); + }); +} \ No newline at end of file diff --git a/assets/js/third-party/others/translate.js b/assets/js/third-party/others/translate.js new file mode 100644 index 0000000..6dee18e --- /dev/null +++ b/assets/js/third-party/others/translate.js @@ -0,0 +1,9 @@ +/* Google translate plugin */ +NexT.plugins.others.translate = function() { + const element = '#gtranslate'; + if (!NexT.utils.checkDOMExist(element)) return; + NexT.utils.lazyLoadComponent(element, function() { + window.translateelement_styles='/css/google-translate.min.css'; + NexT.utils.getScript('/js/third-party/google-translate.min.js'); + }); +} \ No newline at end of file diff --git a/assets/js/third-party/search/algolia.js b/assets/js/third-party/search/algolia.js index dcdb0e7..5af3492 100644 --- a/assets/js/third-party/search/algolia.js +++ b/assets/js/third-party/search/algolia.js @@ -1,12 +1,11 @@ -/* global instantsearch, algoliasearch, CONFIG, pjax */ +/* Algolia search engine */ +NexT.plugins.search.algolia = function() { -document.addEventListener('DOMContentLoaded', () => { - - const algoiajs = NexT.utils.getCDNResource(NexT.CONFIG.algolia.js); + const algoliajs = NexT.utils.getCDNResource(NexT.CONFIG.algolia.js); const instantschjs = NexT.utils.getCDNResource(NexT.CONFIG.algolia.instantjs); - NexT.utils.getScript(algoiajs, {}); - NexT.utils.getScript(instantschjs, {}).then(() => { + NexT.utils.getScript(algoliajs); + NexT.utils.getScript(instantschjs, function() { const { indexname, appid, apikey, hits } = NexT.CONFIG.algolia.cfg; const indexName = indexname; @@ -56,7 +55,7 @@ document.addEventListener('DOMContentLoaded', () => { const stats = NexT.CONFIG.i18n.hits_time .replace('${hits}', data.nbHits) .replace('${time}', data.processingTimeMS); - return `${stats}Algolia`; + return `${stats}`; } }, cssClasses: { @@ -138,7 +137,6 @@ document.addEventListener('DOMContentLoaded', () => { onPopupClose(); } }); - });; + }); - -}); \ No newline at end of file +} \ No newline at end of file diff --git a/assets/js/third-party/search/local.js b/assets/js/third-party/search/local.js index c2c238f..5c30d54 100644 --- a/assets/js/third-party/search/local.js +++ b/assets/js/third-party/search/local.js @@ -1,4 +1,4 @@ -/* global CONFIG, pjax, LocalSearch */ +/* LocalSearch engine */ class LocalSearch { constructor({ path = '', @@ -227,7 +227,7 @@ class LocalSearch { } } -document.addEventListener('DOMContentLoaded', () => { +NexT.plugins.search.localsearch = function() { if (! NexT.CONFIG.localSearch.path) { // Search DB path console.warn('`search indexes file` is not configurate!'); @@ -323,4 +323,4 @@ document.addEventListener('DOMContentLoaded', () => { onPopupClose(); } }); -}); +} diff --git a/assets/js/third-party/share/addthis.js b/assets/js/third-party/share/addthis.js index 17371a3..1bc88e3 100644 --- a/assets/js/third-party/share/addthis.js +++ b/assets/js/third-party/share/addthis.js @@ -1,16 +1,16 @@ -document.addEventListener('DOMContentLoaded', () => { - +/* AddThis share plugin */ +NexT.plugins.share.addthis = function() { const element = '.addthis_inline_share_toolbox'; if (!NexT.CONFIG.addthis || !NexT.utils.checkDOMExist(element)) return; const addthis_js = NexT.CONFIG.addthis.js + '?pubid=' + NexT.CONFIG.addthis.cfg.pubid; - NexT.utils.loadComments(element).then(() => { + NexT.utils.lazyLoadComponent(element, function() { NexT.utils.getScript(addthis_js, { attributes: { - async: true + async: false }, parentNode: document.querySelector(element) }); }); -}); \ No newline at end of file +} \ No newline at end of file diff --git a/assets/js/utils.js b/assets/js/utils.js index a8fe09a..2ef2605 100644 --- a/assets/js/utils.js +++ b/assets/js/utils.js @@ -1,103 +1,73 @@ -/* global NexT, CONFIG */ +/* util tools */ -HTMLElement.prototype.wrap = function(wrapper) { +HTMLElement.prototype.wrap = function (wrapper) { this.parentNode.insertBefore(wrapper, this); this.parentNode.removeChild(this); wrapper.appendChild(this); }; -(function() { - const onPageLoaded = () => document.dispatchEvent( - new Event('page:loaded', { - bubbles: true - }) - ); - - if (document.readyState === 'loading') { - document.addEventListener('readystatechange', onPageLoaded, { once: true }); - } else { - onPageLoaded(); - } - document.addEventListener('pjax:success', onPageLoaded); -})(); - NexT.utils = { - - regSwitchThemeBtn: function() { - const switchThemeBtn = document.getElementById('switch-theme'); - if (!switchThemeBtn) return; - switchThemeBtn.addEventListener('click', () => { - const colorTheme = document.documentElement.getAttribute('data-theme'); - NexT.utils.toggleDarkMode(!(colorTheme == 'dark')); - - }); - }, - - activeThemeMode: function() { - - const useDark = window.matchMedia("(prefers-color-scheme: dark)"); - let darkModeState = NexT.CONFIG.darkmode || useDark.matches; - const localState = NexT.utils.getLocalStorage('theme'); - if (localState == 'light' - || (localState == undefined && !NexT.CONFIG.darkmode)) { - darkModeState = false; - } - NexT.utils.toggleDarkMode(darkModeState); - - useDark.addListener(function(evt) { - toggleDarkMode(evt.matches); + registerImageLoadEvent: function() { + const images = document.querySelectorAll('.sidebar img, .post-block img, .vendors-list img'); + + const callback = (entries) => { + entries.forEach(item => { + if (item.intersectionRatio > 0) { + let ele = item.target; + let imgSrc = ele.getAttribute('data-src'); + if (imgSrc) { + let img = new Image(); + img.addEventListener('load', function() { + ele.src = imgSrc; + }, false); + ele.src = imgSrc; + // Prevent load image again + ele.removeAttribute('data-src'); + } + } + }) + }; + + const observer = new IntersectionObserver(callback); + images.forEach(img => { + observer.observe(img); }); }, - toggleDarkMode: function(state) { - if(state) { - document.documentElement.setAttribute('data-theme', 'dark'); - NexT.utils.setLocalStorage('theme', 'dark', 2); - } else { - document.documentElement.setAttribute('data-theme', 'light'); - NexT.utils.setLocalStorage('theme', 'light', 2); - } - - const theme = state ? 'dark' : 'light'; - NexT.utils.toggleGiscusDarkMode(theme); + registerImageViewer: function() { + new Viewer(document.querySelector('.post-body'),{ navbar:2, toolbar:2 }); }, - toggleGiscusDarkMode: function(theme) { - const iframe = document.querySelector('iframe.giscus-frame'); - if (iframe) { - const config = { setConfig: { theme: theme } }; - iframe.contentWindow.postMessage({ giscus: config }, 'https://giscus.app'); - } + registerToolButtons: function () { + const buttons = document.querySelector('.tool-buttons'); + + const scrollbar_buttons = buttons.querySelectorAll('div:not(#toggle-theme)'); + scrollbar_buttons.forEach(button => { + let targetId = button.id; + if (targetId != '') { + targetId = targetId.substring(5); + } + button.addEventListener('click', () => { + this.slidScrollBarAnime(targetId); + }); + }); + + buttons.querySelector('div#toggle-theme').addEventListener('click', () => { + const cur_theme = document.documentElement.getAttribute('data-theme'); + window.theme.toggle(cur_theme === 'dark' ? 'light' : 'dark'); + }); }, - setLocalStorage: function(key, value, ttl) { - if (ttl === 0) return; - const now = new Date(); - const expiryDay = ttl * 86400000; - const item = { - value: value, - expiry: now.getTime() + expiryDay - }; - localStorage.setItem(key, JSON.stringify(item)); + slidScrollBarAnime: function (targetId, easing = 'linear', duration = 500) { + window.anime({ + targets: document.scrollingElement, + duration: duration, + easing: easing, + scrollTop: targetId == '' ? 0 : document.getElementById(targetId).getBoundingClientRect().top + window.scrollY + }); }, - getLocalStorage: function(key) { - const itemStr = localStorage.getItem(key); - if (!itemStr) { - return undefined; - } - - const item = JSON.parse(itemStr); - const now = new Date(); - - if (now.getTime() > item.expiry) { - localStorage.removeItem(key); - return undefined; - } - return item.value; - }, - - domAddClass: function(selector, cls) { + domAddClass: function (selector, cls) { const doms = document.querySelectorAll(selector); if (doms) { doms.forEach(dom => { @@ -106,24 +76,24 @@ NexT.utils = { } }, - calSiteInfo: function() { + fmtSiteInfo: function () { const runtimeCount = document.getElementById('runTimes'); if (runtimeCount) { const publishDate = runtimeCount.getAttribute('data-publishDate'); - const runTimes = NexT.utils.diffDate(publishDate, 2); + const runTimes = this.diffDate(publishDate, 2); runtimeCount.innerText = runTimes; } const wordsCount = document.getElementById('wordsCount'); if (wordsCount) { const words = wordsCount.getAttribute('data-count'); - wordsCount.innerText = NexT.utils.numberFormat(words); + wordsCount.innerText = this.numberFormat(words); } const readTimes = document.getElementById('readTimes'); if (readTimes) { const times = readTimes.getAttribute('data-times'); - + const hour = 60; const day = hour * 24; @@ -132,7 +102,7 @@ NexT.utils = { let timesLabel; if (daysCount >= 1) { - timesLabel = daysCount + NexT.CONFIG.i18n.ds_days + parseInt((times - daysCount * day)/hour) + NexT.CONFIG.i18n.ds_hours; + timesLabel = daysCount + NexT.CONFIG.i18n.ds_days + parseInt((times - daysCount * day) / hour) + NexT.CONFIG.i18n.ds_hours; } else if (hoursCount >= 1) { timesLabel = hoursCount + NexT.CONFIG.i18n.ds_hours + (times - hoursCount * hour) + NexT.CONFIG.i18n.ds_mins; } else { @@ -144,40 +114,44 @@ NexT.utils = { const lastPushDate = document.getElementById('last-push-date'); if (lastPushDate) { - const pushDateVal = NexT.utils.diffDate(lastPushDate.getAttribute('data-lastPushDate'), 1); + const pushDateVal = this.diffDate(lastPushDate.getAttribute('data-lastPushDate'), 1); lastPushDate.innerText = pushDateVal; } + }, - const statisWidget = document.querySelectorAll('#la-siteinfo-widget span'); - if (statisWidget.length > 0) { - const valIds = [0,2,4,6]; - const domIds = ['today_site_pv', 'yesterday_site_pv', 'month_site_pv', 'total_site_pv'] - for (var i in valIds) { - let pv = NexT.utils.numberFormat(statisWidget[valIds[i]].innerText); - document.getElementById(domIds[i]).innerText = pv; + fmtLaWidget: function(){ + setTimeout(function(){ + const laWidget = document.querySelectorAll('#la-siteinfo-widget span'); + if (laWidget.length > 0) { + const valIds = [0, 2, 4, 6]; + const domIds = ['today_site_pv', 'yesterday_site_pv', 'month_site_pv', 'total_site_pv'] + for (let i in valIds) { + let pv = NexT.utils.numberFormat(laWidget[valIds[i]].innerText); + document.getElementById(domIds[i]).innerText = pv; + } } - } - - setTimeout(()=>{ NexT.utils.fmtBusuanzi(); }, 500); + }, 800); }, - fmtBusuanzi: function() { - const bszUV = document.getElementById('busuanzi_value_site_uv'); - if (bszUV) { - bszUV.innerText = NexT.utils.numberFormat(bszUV.innerText); - } - const bszPV = document.getElementById('busuanzi_value_site_pv'); - if (bszPV) { - bszPV.innerText = NexT.utils.numberFormat(bszPV.innerText); - } + fmtBusuanzi: function () { + setTimeout(function(){ + const bszUV = document.getElementById('busuanzi_value_site_uv'); + if (bszUV) { + bszUV.innerText = NexT.utils.numberFormat(bszUV.innerText); + } + const bszPV = document.getElementById('busuanzi_value_site_pv'); + if (bszPV) { + bszPV.innerText = NexT.utils.numberFormat(bszPV.innerText); + } + }, 800); }, - numberFormat: function(number) { + numberFormat: function (number) { let result; if (number.indexOf(',') > 0) { number = number.replaceAll(",", ""); } - + if (number > 10000) { result = (number / 10000.0).toFixed(2) + ' w'; } else if (number > 1000) { @@ -188,7 +162,7 @@ NexT.utils = { return result; }, - diffDate: function(date, mode = 0) { + diffDate: function (date, mode = 0) { const dateNow = new Date(); const datePost = new Date(date); const dateDiff = dateNow.getTime() - datePost.getTime(); @@ -218,15 +192,15 @@ NexT.utils = { } else { result = NexT.CONFIG.i18n.ds_just; } - } else if (mode == 2) { + } else if (mode == 2) { const yearCount = parseInt(dateDiff / year); if (yearCount >= 1) { - const dayCount = parseInt((dateDiff - (yearCount * year))/day); + const dayCount = parseInt((dateDiff - (yearCount * year)) / day); result = yearCount + NexT.CONFIG.i18n.ds_years + dayCount + NexT.CONFIG.i18n.ds_days; } else { - const dayCount = parseInt(dateDiff/day); + const dayCount = parseInt(dateDiff / day); result = dayCount + NexT.CONFIG.i18n.ds_days; - } + } } else { result = parseInt(dateDiff / day); } @@ -234,20 +208,26 @@ NexT.utils = { return result; }, - checkDOMExist: function(selector) { + checkDOMExist: function (selector) { return document.querySelector(selector) != null; }, - getCDNResource: function(res) { + getCDNResource: function (res) { let { plugins, router } = NexT.CONFIG.vendor; - let { name, version, file, alias } = res; + let { name, version, file, alias, alias_name } = res; let npm_name = name; + if (alias_name) npm_name = alias_name; let res_src = ''; - switch(plugins) { + switch (plugins) { case 'cdnjs': + case 'bootcdn': + case 'qiniu': let cdnjs_name = alias || name; - let cdnjs_file = file.replace(/\.js$/, '.min.js').replace(/^(dist|lib|source\/js|)\/(browser\/|)/, ''); + let cdnjs_file = file.replace(/^(dist|lib|source|\/js|)\/(browser\/|)/, ''); + if (cdnjs_file.indexOf('min') == -1) { + cdnjs_file = cdnjs_file.replace(/\.js$/, '.min.js'); + } res_src = `${router}/${cdnjs_name}/${version}/${cdnjs_file}` break; default: @@ -257,23 +237,10 @@ NexT.utils = { return res_src; }, - replacePostCRLink: function() { - if (NexT.CONFIG.hostname.startsWith('http')) return; - // Try to support mutli domain without base URL sets. - let href = window.location.href; - if (href.indexOf('#')>-1){ - href = href.split('#')[0]; - } - let postLink = document.getElementById('post-cr-link'); - if (!postLink) return; - postLink.text = href; - postLink.href = href; - }, - /** * One-click copy code support. */ - registerCopyCode: function() { + registerCopyCode: function () { if (!NexT.CONFIG.copybtn) return; let figure = document.querySelectorAll('.highlight pre'); @@ -320,7 +287,7 @@ NexT.utils = { }); }, - wrapTableWithBox: function() { + wrapTableWithBox: function () { document.querySelectorAll('table').forEach(element => { const box = document.createElement('div'); box.className = 'table-container'; @@ -328,7 +295,7 @@ NexT.utils = { }); }, - registerVideoIframe: function() { + registerVideoIframe: function () { document.querySelectorAll('iframe').forEach(element => { const supported = [ 'www.youtube.com', @@ -350,7 +317,7 @@ NexT.utils = { }); }, - registerScrollPercent: function() { + registerScrollPercent: function () { const backToTop = document.querySelector('.back-to-top'); const readingProgressBar = document.querySelector('.reading-progress-bar'); // For init back to top in sidebar if page was scrolled after page refresh. @@ -360,7 +327,7 @@ NexT.utils = { const scrollPercent = contentHeight > 0 ? Math.min(100 * window.scrollY / contentHeight, 100) : 0; if (backToTop) { const scrollPercentRound = Math.round(scrollPercent) - const isShow = scrollPercentRound >= 5; + const isShow = scrollPercentRound >= 5; backToTop.classList.toggle('back-to-top-on', isShow); backToTop.querySelector('span').innerText = scrollPercentRound + '%'; } @@ -379,21 +346,12 @@ NexT.utils = { } this.activateNavByIndex(index); }, { passive: true }); - - backToTop && backToTop.addEventListener('click', () => { - window.anime({ - targets : document.scrollingElement, - duration : 500, - easing : 'linear', - scrollTop: 0 - }); - }); }, /** * Tabs tag listener (without twitter bootstrap). */ - registerTabsTag: function() { + registerTabsTag: function () { // Binding `nav-tabs` & `tab-content` by real time permalink changing. document.querySelectorAll('.tabs ul.nav-tabs .tab').forEach(element => { element.addEventListener('click', event => { @@ -408,7 +366,7 @@ NexT.utils = { // https://stackoverflow.com/questions/20306204/using-queryselector-with-ids-that-are-numbers const tActive = document.getElementById(element.querySelector('a').getAttribute('href').replace('#', '')); [...tActive.parentNode.children].forEach(target => { - // Array.prototype.slice.call(tActive.parentNode.children).forEach(target => { + // Array.prototype.slice.call(tActive.parentNode.children).forEach(target => { target.classList.toggle('active', target === tActive); }); // Trigger event @@ -418,9 +376,9 @@ NexT.utils = { if (!NexT.CONFIG.stickytabs) return; const offset = nav.parentNode.getBoundingClientRect().top + window.scrollY + 10; window.anime({ - targets : document.scrollingElement, - duration : 500, - easing : 'linear', + targets: document.scrollingElement, + duration: 500, + easing: 'linear', scrollTop: offset }); }); @@ -429,7 +387,7 @@ NexT.utils = { window.dispatchEvent(new Event('tabs:register')); }, - registerCanIUseTag: function() { + registerCanIUseTag: function () { // Get responsive height passed from iframe. window.addEventListener('message', ({ data }) => { if (typeof data === 'string' && data.includes('ciu_embed')) { @@ -447,7 +405,7 @@ NexT.utils = { target.classList.toggle('menu-item-active', target.hostname === location.hostname && (isSamePath || isSubPath)); }); }, - + registerLangSelect: function() { const selects = document.querySelectorAll('.lang-select'); selects.forEach(sel => { @@ -463,19 +421,25 @@ NexT.utils = { }); },*/ - registerSidebarTOC: function() { - this.sections = [...document.querySelectorAll('.post-toc li a.nav-link')].map(element => { + registerSidebarTOC: function () { + const toc = document.getElementById('TableOfContents'); + if (!toc.hasChildNodes()) { + const tocActive = document.querySelector('.sidebar-inner'); + tocActive.classList.remove('sidebar-nav-active', 'sidebar-toc-active'); + tocActive.classList.add('sidebar-overview-active'); + } + this.sections = [...document.querySelectorAll('.post-toc li a')].map(element => { const target = document.getElementById(decodeURI(element.getAttribute('href')).replace('#', '')); // TOC item animation navigate. element.addEventListener('click', event => { event.preventDefault(); const offset = target.getBoundingClientRect().top + window.scrollY; window.anime({ - targets : document.scrollingElement, - duration : 500, - easing : 'linear', + targets: document.scrollingElement, + duration: 500, + easing: 'linear', scrollTop: offset, - complete : () => { + complete: () => { history.pushState(null, document.title, element.href); } }); @@ -484,7 +448,7 @@ NexT.utils = { }); }, - registerPostReward: function() { + registerPostReward: function () { const button = document.querySelector('.reward-container button'); if (!button) return; button.addEventListener('click', () => { @@ -492,22 +456,22 @@ NexT.utils = { }); }, - initCommontesDispaly: function(){ + initCommontesDispaly: function () { const comms = document.querySelectorAll('.comment-wrap > div'); - if (comms.length<=1) return; - comms.forEach(function(item){ - var dis = window.getComputedStyle(item, null).display; + if (comms.length <= 1) return; + comms.forEach(function (item) { + let dis = window.getComputedStyle(item, null).display; item.style.display = dis; }); }, - registerCommonSwitch: function() { + registerCommonSwitch: function () { const button = document.querySelector('.comment-switch .switch-btn'); if (!button) return; const comms = document.querySelectorAll('.comment-wrap > div'); button.addEventListener('click', () => { button.classList.toggle('move'); - comms.forEach(function(item){ + comms.forEach(function (item) { if (item.style.display === 'none') { item.style.cssText = "display: block; animation: tabshow .8s"; } else { @@ -517,17 +481,17 @@ NexT.utils = { }); }, - hideCommontes:function() { + hideCommontes: function () { document.querySelector('.post-comments').style.display = 'none'; }, - hiddeLodingCmp: function(selector) { + hiddeLodingCmp: function (selector) { const loadding = document.querySelector(selector).previousElementSibling; loadding.style.display = 'none'; }, - activateNavByIndex: function(index) { - const target = document.querySelectorAll('.post-toc li a.nav-link')[index]; + activateNavByIndex: function (index) { + const target = document.querySelectorAll('.post-toc li a')[index]; if (!target || target.classList.contains('active-current')) return; document.querySelectorAll('.post-toc .active').forEach(element => { @@ -543,14 +507,14 @@ NexT.utils = { const tocElement = document.querySelector('.sidebar-panel-container'); if (!tocElement.parentNode.classList.contains('sidebar-toc-active')) return; window.anime({ - targets : tocElement, - duration : 200, - easing : 'linear', + targets: tocElement, + duration: 200, + easing: 'linear', scrollTop: tocElement.scrollTop - (tocElement.offsetHeight / 2) + target.getBoundingClientRect().top - tocElement.getBoundingClientRect().top }); }, - updateSidebarPosition: function() { + updateSidebarPosition: function () { if (window.innerWidth < 992 || NexT.CONFIG.scheme === 'Pisces' || NexT.CONFIG.scheme === 'Gemini') return; // Expand sidebar on post detail page by default, when post has a toc. const hasTOC = document.querySelector('.post-toc'); @@ -564,7 +528,7 @@ NexT.utils = { } }, - activateSidebarPanel: function(index) { + activateSidebarPanel: function (index) { const duration = 200; const sidebar = document.querySelector('.sidebar-inner'); const panel = document.querySelector('.sidebar-panel-container'); @@ -574,34 +538,39 @@ NexT.utils = { window.anime({ duration, - targets : panel, - easing : 'linear', - opacity : 0, + targets: panel, + easing: 'linear', + opacity: 0, translateY: [0, -20], - complete : () => { + complete: () => { // Prevent adding TOC to Overview if Overview was selected when close & open sidebar. sidebar.classList.replace(activeClassName[1 - index], activeClassName[index]); window.anime({ duration, - targets : panel, - easing : 'linear', - opacity : [0, 1], + targets: panel, + easing: 'linear', + opacity: [0, 1], translateY: [-20, 0] }); } }); }, - getStyle: function(src, parent) { + getStyle: function (src, position='after', parent) { const link = document.createElement('link'); link.setAttribute('rel', 'stylesheet'); link.setAttribute('type', 'text/css'); link.setAttribute('href', src); - (parent || document.head).appendChild(link); + const head = (parent || document.head); + if (position === 'before') { + head.prepend(link); + } else { + head.append(link); + } }, - getScript: function(src, options = {}, legacyCondition) { + getScript: function (src, options = {}, legacyCondition) { if (typeof options === 'function') { return this.getScript(src, { condition: legacyCondition @@ -619,7 +588,7 @@ NexT.utils = { } = {}, parentNode = null } = options; - + return new Promise((resolve, reject) => { if (condition) { resolve(); @@ -653,9 +622,9 @@ NexT.utils = { }); }, - loadComments: function(selector, legacyCallback) { + lazyLoadComponent: function(selector, legacyCallback) { if (legacyCallback) { - return this.loadComments(selector).then(legacyCallback); + return this.lazyLoadComponent(selector).then(legacyCallback); } return new Promise(resolve => { const element = document.querySelector(selector); @@ -673,4 +642,4 @@ NexT.utils = { intersectionObserver.observe(element); }); } -}; +}; \ No newline at end of file diff --git a/data/config.yaml b/data/config.yaml index 89eec50..434707a 100644 --- a/data/config.yaml +++ b/data/config.yaml @@ -1,3 +1,5 @@ # Hugo NexT theme's custom config -version: 4.3.1 \ No newline at end of file +version: 4.4.0 + +domain: hugo-next.eu.org \ No newline at end of file diff --git a/data/resources.yaml b/data/resources.yaml index 9159733..67303ad 100644 --- a/data/resources.yaml +++ b/data/resources.yaml @@ -3,6 +3,8 @@ vendors: cdnjs: "https://cdnjs.cloudflare.com/ajax/libs" unpkg: "https://unpkg.com" + bootcdn: "https://cdn.bootcdn.net/ajax/libs" + qiniu: "https://cdn.staticfile.org" # JavaScript 资源 # JavaScript Resources @@ -10,6 +12,9 @@ js: - name: animejs version: 3.2.1 file: lib/anime.min.js + - name: viewerjs + version: 1.11.0 + file: dist/viewer.min.js # CSS 资源 # CSS Resources @@ -21,6 +26,9 @@ css: - name: animate.css version: 3.1.1 file: animate.min.css + - name: viewerjs + version: 1.11.0 + file: dist/viewer.min.css # 第三方服务组件资源 # 3rd servcies Resource @@ -44,12 +52,12 @@ addthis: waline: js: name: '@waline/client' - version: 2.11.3 + version: 2.13.0 file: dist/waline.js alias: waline css: name: '@waline/client' - version: 2.11.3 + version: 2.13.0 file: dist/waline.css alias: waline @@ -76,38 +84,51 @@ livere: # Full text search algolia: name: algoliasearch - version: 4.13.0 + version: 4.14.2 file: dist/algoliasearch-lite.umd.js instant: name: instantsearch.js - version: 4.40.5 + version: 4.49.0 file: dist/instantsearch.production.min.js plugins: # 数学公式渲染 mathjax: js: - - name: mathjax - version: 3.2.0 - file: es5/tex-mml-chtml.js + name: mathjax + version: 3.2.0 + file: es5/tex-mml-chtml.js katex: js: - name: katex version: 0.16.0 file: dist/katex.min.js - name: auto-render - alias2: katex + alias_name: katex version: 0.16.0 file: dist/contrib/auto-render.min.js css: - - name: katex - version: 0.16.0 - file: dist/katex.min.css + name: katex + version: 0.16.0 + file: dist/katex.min.css # 画图渲染 mermaid: js: - - name: mermaid - version: 9.1.7 - file: dist/mermaid.min.js + name: mermaid + version: 9.1.7 + file: dist/mermaid.min.js + # 文章访问/评论统计 + waline: + js: + - name: pageview + alias_name: '@waline/client' + version: 2.13.0 + file: dist/pageview.js + alias: waline + - name: comment + alias_name: '@waline/client' + version: 2.13.0 + file: dist/comment.js + alias: waline diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index c6b9d5b..d614c01 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -39,10 +39,6 @@ markup: renderer: unsafe: true highlight: - # codeFences: true - # lineNos: true - # lineNumbersInTable: true - # noClasses: true # # 高亮代码的样式名称,可选:monokai | emacs | api | dracula | friendly # # 更多的样式:https://xyproto.github.io/splash/docs/all.html # # Highlight style: monokai | emacs | api | dracula | friendly @@ -107,6 +103,7 @@ enableRobotsTXT: true # 强制输出时压缩文件 # Compress all files when output minify: + minifyOutput: true #-------------------------------------- # 菜单配置说明 @@ -306,7 +303,7 @@ params: enable: true # 组件类型,可选值为: 51la, busuanzi # 使用51la时需要注册账号:https://invite.51.la/1NUfGTS1?target=V6 - # Plguin value is: 51la, busuzazi + # Plguin value is: 51la, busuanzi plugin: busuanzi # 社交链接地址 @@ -813,7 +810,8 @@ params: # Waline comments system # More info seee: https://waline.js.org/ waline: - pageView: '#waline-pageview-count' + pageView: true + comment: true placeholder: "请文明发言哟 ヾ(≧▽≦*)o" sofa: "快来发表你的意见吧 (≧∀≦)ゞ" emoji: false @@ -1095,14 +1093,15 @@ params: # --------------------------------------------------------------- vendors: + vendors: # The CDN provider of NexT internal scripts. - # Available values: local | unpkg | cdnjs | custom + # Available values: local | unpkg | cdnjs | qiniu | bootcdn | custom # Warning: If you are using the latest master branch of NexT, please set `internal: local` internal: local # The default CDN provider of third-party plugins. - # Available values: local | unpkg | cdnjs | custom + # Available values: local | unpkg | cdnjs| qiniu | bootcdn | custom # Dependencies for `plugins: local`: https://github.com/next-theme/plugins - plugins: unpkg + plugins: qiniu # TODO # Custom CDN URL # For example: diff --git a/exampleSite/content/post/math-formula.md b/exampleSite/content/post/math-formula.md index ac0f252..3a3e965 100644 --- a/exampleSite/content/post/math-formula.md +++ b/exampleSite/content/post/math-formula.md @@ -34,22 +34,22 @@ math: mathjax **注意:** 使用[支持的TeX功能](https://docs.mathjax.org/en/latest/input/tex/index.html)的联机参考资料。 -### 例子 +## 例子 -## 重复的分数 +### 重复的分数 $$ \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} \equiv 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots} } } } $$ -## 总和记号 +### 总和记号 $$ \left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right) $$ -## 几何级数之和 +### 几何级数之和 我把接下来的两个例子分成了几行,这样它在手机上表现得更好。这就是为什么它们包含 `\displaystyle`。 $$ @@ -76,24 +76,24 @@ $$ \displaystyle= \frac{(k+1)((k+1)+1)}{2} $$ -## 乘记号 +### 乘记号 $$ \displaystyle 1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots = \displaystyle \prod_{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})}, \displaystyle\text{ for }\lvert q\rvert < 1. $$ -## 随文数式 +### 随文数式 这是一些线性数学: $$ k_{n+1} = n^2 + k_n^2 - k_{n-1} $$ , 然后是更多的文本。 -## 希腊字母 +### 希腊字母 $$ \Gamma\ \Delta\ \Theta\ \Lambda\ \Xi\ \Pi\ \Sigma\ \Upsilon\ \Phi\ \Psi\ \Omega \alpha\ \beta\ \gamma\ \delta\ \epsilon\ \zeta\ \eta\ \theta\ \iota\ \kappa\ \lambda\ \mu\ \nu\ \xi \ \omicron\ \pi\ \rho\ \sigma\ \tau\ \upsilon\ \phi\ \chi\ \psi\ \omega\ \varepsilon\ \vartheta\ \varpi\ \varrho\ \varsigma\ \varphi $$ -## 箭头 +### 箭头 $$ \gets\ \to\ \leftarrow\ \rightarrow\ \uparrow\ \Uparrow\ \downarrow\ \Downarrow\ \updownarrow\ \Updownarrow $$ @@ -122,7 +122,7 @@ $$ $$ -## 微积分学 +### 微积分学 $$ \int u \frac{dv}{dx}\,dx=uv-\int \frac{du}{dx}v\,dx $$ @@ -136,13 +136,13 @@ $$ $$ -## 洛伦茨方程 +### 洛伦茨方程 $$ \begin{aligned} \dot{x} & = \sigma(y-x) \\\\ \dot{y} & = \rho x - y - xz \\\\ \dot{z} & = -\beta z + xy \end{aligned} $$ -## 交叉乘积 +### 交叉乘积 这在KaTeX中是可行的,但在这种环境中馏分的分离不是很好。 $$ @@ -162,25 +162,25 @@ $$ $$ -## 有弹性的括号 +### 有弹性的括号 $$ \left(\frac{x^2}{y^3}\right) $$ -## 评估范围 +### 评估范围 $$ \left.\frac{x^3}{3}\right|_0^1 $$ -## 诊断标准 +### 诊断标准 $$ f(n) = \begin{cases} \frac{n}{2}, & \text{if } n\text{ is even} \\\\ 3n+1, & \text{if } n\text{ is odd} \end{cases} $$ -## 麦克斯韦方程组 +### 麦克斯韦方程组 $$ \begin{aligned} \nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\\\ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\\\ \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\\\ \nabla \cdot \vec{\mathbf{B}} & = 0 \end{aligned} $$ @@ -194,19 +194,19 @@ $$ {n \choose k} $$ -## 分数在分数 +### 分数在分数 $$ \frac{\frac{1}{x}+\frac{1}{y}}{y-z} $$ -## n次方根 +### n次方根 $$ \sqrt[n]{1+x+x^2+x^3+\ldots} $$ -## 矩阵 +### 矩阵 $$ \begin{pmatrix} a_{11} & a_{12} & a_{13}\\\\ a_{21} & a_{22} & a_{23}\\\\ a_{31} & a_{32} & a_{33} \end{pmatrix} \begin{bmatrix} 0 & \cdots & 0 \\\\ \vdots & \ddots & \vdots \\\\ 0 & \cdots & 0 \end{bmatrix} diff --git a/exampleSite/content/post/no-header-title.md b/exampleSite/content/post/no-header-title.md new file mode 100644 index 0000000..7a75e84 --- /dev/null +++ b/exampleSite/content/post/no-header-title.md @@ -0,0 +1,43 @@ +--- +title: "没有H1-6标题头和评论的文章" +description: "用于测试在没有H1-6标题头时,文章的目录导航是否会直接关闭,并关闭评论功能。" +keywords: "toc,header" + +date: 2022-10-06T09:02:26+08:00 +lastmod: 2022-10-30T21:03:16+08:00 + +categories: + - 示例 +tags: + - toc + - 标题 + +comment: + enable: false +url: "post/no-header-title.html" +--- + +刘慈欣2018克拉克奖获奖感言(部分内容节选)。 + +> 用于测试在没有H1-6标题头时,文章的目录导航是否会直接关闭,并关闭评论功能。 + + + +先生们、女士们,晚上好, + +很荣幸获得Clarke Award for Imagination in Service to Society Award。 + +这个奖项是对想象力的奖励,而想象力是人类所拥有的一种似乎只应属于神的能力,它存在的意义也远超出我们的想象。有历史学家说过,人类之所以能够超越地球上的其它物种建立文明,主要是因为他们能够在自己的大脑中创造出现实中不存在的东西。在未来,当人工智能拥有超过人类的智力时,想象力也许是我们对于它们所拥有的惟一优势。 + +科幻小说是基于想象力的文学,而最早给我留下深刻印象的是Arthur . Clarke的作品。除了Jules Verne和George Wells外,Clarke的作品是最早进入中国的西方现代科幻小说。在上世纪八十年代初,中国出版了他的《2001:A Space Odyssey》和《Rendezvous With Rama》。当时文革刚刚结束,旧的生活和信仰已经崩塌,新的还没有建立起来,我和其他年轻人一样,心中一片迷茫。这两本书第一次激活了我想象力,思想豁然开阔许多,有小溪流进大海的感觉。读完《2001:A Space Odyssey》的那天深夜,我走出家门仰望星空,那时的中国的天空还没有太多的污染,能够看到银河,在我的眼中,星空与过去完全不一样了,我第一次对宇宙的宏大与神秘产生了敬畏感,这是一种宗教般的感觉。而后来读到的《Rendezvous With Rama》,也让我惊叹如何可以用想象力构造一个栩栩如生的想象世界。正是Clarke带给我的这些感受,让我后来成为一名科幻作家。 + +现在,三十多年过去了,我渐渐发现,我们这一代在上世纪六十年代出生于中国的人,很可能是人类历史上最幸运的人,因为之前没有任何一代人,像我们这样目睹周围的世界发生了如此巨大的变化,我们现在生活的世界,与我们童年的世界已经完全是两个不同的世界,而这种变化还在加速发生着。中国是一个充满着未来感的国度,中国的未来可能充满着挑战和危机,但从来没有像现在这样具有吸引力,这就给科幻小说提供了肥沃的土壤,使其在中国受到了空前的关注,作为一个在六十年代出生在中国的科幻小说家,则是幸运中的幸运。 + +我期待有那么一天,像那些曾经描写过信息时代的科幻小说一样,描写太空航行的科幻小说也变的平淡无奇了,那时的火星和小行星带都是乏味的地方,有无数的人在那里谋生;木星和它众多的卫星已成为旅游胜地,阻止人们去那里的唯一障碍就是昂贵的价格。 + +但即使在这个时候,宇宙仍是一个大的无法想象的存在,距我们最近的恒星仍然遥不可及。浩瀚的星空永远能够承载我们无穷的想象力。 + +谢谢大家。 + + +> [点击阅读全文](https://weread.qq.com/web/reader/ce032b305a9bc1ce0b0dd2akecc32f3013eccbc87e4b62e) diff --git a/exampleSite/start.sh b/exampleSite/startup.sh similarity index 100% rename from exampleSite/start.sh rename to exampleSite/startup.sh diff --git a/i18n/en.yaml b/i18n/en.yaml index fc9971c..d114344 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -93,6 +93,8 @@ PostReadTime: other: "{{- .ReadingTime -}}min" PostViews: other: "Views" +PostComments: + other: "Comments" PostTag: other: "Tags" PostReadMore: diff --git a/i18n/zh-cn.yaml b/i18n/zh-cn.yaml index 8a77470..139470d 100644 --- a/i18n/zh-cn.yaml +++ b/i18n/zh-cn.yaml @@ -94,6 +94,8 @@ PostReadTime: other: "{{- .ReadingTime -}}分钟" PostViews: other: 浏览 +PostComments: + other: 评论 PostTags: other: 标签 PostReadMore: diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html new file mode 100644 index 0000000..d187cc9 --- /dev/null +++ b/layouts/_default/_markup/render-image.html @@ -0,0 +1 @@ +{{ .Text }} \ No newline at end of file diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 7606f8a..8db7191 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,8 +1,10 @@ {{- range $k, $v := (partialCached "init.html" .) -}} - {{- $.Scratch.Set $k $v -}} +{{- $.Scratch.Set $k $v -}} {{- end -}} +{{ $commentEnable := .Params.comment.enable | default .Site.Params.comments.enable }} +{{ .Scratch.Set "isComment" $commentEnable }} - + {{- partial "head.html" . }} @@ -29,7 +31,7 @@
{{- block "main" . }}{{- end }} - {{- if .IsPage }} + {{- if and .IsPage $commentEnable }} {{- partialCached "comments.html" . }} {{- end }}
diff --git a/layouts/_default/list.algoliaindexes.json b/layouts/_default/list.algoliaindexes.json index 91124c1..28a550b 100644 --- a/layouts/_default/list.algoliaindexes.json +++ b/layouts/_default/list.algoliaindexes.json @@ -2,9 +2,10 @@ {{- range $index, $entry := where .Site.RegularPages "Kind" "page" }} {{- if $index }}, {{ end }} { + "objectID": "{{ .Date.Unix }}", "permalink": "{{ .Permalink | relURL }}", "title": {{ .Title | jsonify }}, - "content": {{ .Plain | jsonify }}, + "content": {{ .Plain | jsonify | safeJS }}, "date": {{ .Date.Format $.Site.Params.timeFormat | jsonify }}, "updated": {{ .Lastmod.Format $.Site.Params.timeFormat | jsonify }} } diff --git a/layouts/partials/_funs/get_plugin.html b/layouts/partials/_funs/get_plugin.html new file mode 100644 index 0000000..e25a3ef --- /dev/null +++ b/layouts/partials/_funs/get_plugin.html @@ -0,0 +1,11 @@ +{{/* Get third party js plugins resource */}} + +{{ $pluginPath := printf "%s/%s/%s" "js/third-party" .class .plugin }} +{{ $targetPath := printf "js/%s" .plugin }} +{{ $plugin := resources.Get $pluginPath | resources.ExecuteAsTemplate $targetPath .ctx }} + +{{ if hugo.IsProduction }} +{{ $plugin = $plugin | minify | fingerprint }} +{{ end }} + + \ No newline at end of file diff --git a/layouts/partials/_funs/get_res.html b/layouts/partials/_funs/get_res.html index c49a386..21749d1 100644 --- a/layouts/partials/_funs/get_res.html +++ b/layouts/partials/_funs/get_res.html @@ -8,7 +8,7 @@ {{ end }} {{- $file := .res.file }} -{{- if eq .vendor "cdnjs" }} +{{- if ne .vendor "unpkg" }} {{- with .res.alias }} {{- $npm = . }} {{- end }} diff --git a/layouts/partials/_thirdparty/analytics/51la.html b/layouts/partials/_thirdparty/analytics/51la.html index 63d0886..8946f02 100644 --- a/layouts/partials/_thirdparty/analytics/51la.html +++ b/layouts/partials/_thirdparty/analytics/51la.html @@ -1,17 +1,17 @@ diff --git a/layouts/partials/_thirdparty/analytics/baidu.html b/layouts/partials/_thirdparty/analytics/baidu.html index 7795e0c..c68fc11 100644 --- a/layouts/partials/_thirdparty/analytics/baidu.html +++ b/layouts/partials/_thirdparty/analytics/baidu.html @@ -1,11 +1,11 @@ \ No newline at end of file diff --git a/layouts/partials/_thirdparty/analytics/busuanzi.html b/layouts/partials/_thirdparty/analytics/busuanzi.html index 2bdda46..0545dca 100644 --- a/layouts/partials/_thirdparty/analytics/busuanzi.html +++ b/layouts/partials/_thirdparty/analytics/busuanzi.html @@ -1,11 +1,15 @@ diff --git a/layouts/partials/_thirdparty/analytics/google.html b/layouts/partials/_thirdparty/analytics/google.html index 103dd4c..2bbc612 100644 --- a/layouts/partials/_thirdparty/analytics/google.html +++ b/layouts/partials/_thirdparty/analytics/google.html @@ -1,18 +1,18 @@ \ No newline at end of file diff --git a/layouts/partials/_thirdparty/others/math.html b/layouts/partials/_thirdparty/others/math.html deleted file mode 100644 index e1eb956..0000000 --- a/layouts/partials/_thirdparty/others/math.html +++ /dev/null @@ -1,28 +0,0 @@ - -{{ $math := .Params.math | default .Site.Params.math }} -{{- partial "scripts/plugins.html" (dict "vendor" (.Scratch.Get "vendor") "router" (.Scratch.Get "router") "res" .Site.Data.resources.plugins "index" $math) }} -{{ if eq $math "katex" }} - -{{ end }} -{{ if eq $math "mathjax" }} - -{{ end }} \ No newline at end of file diff --git a/layouts/partials/_thirdparty/others/mermaid.html b/layouts/partials/_thirdparty/others/mermaid.html deleted file mode 100644 index bd61ca9..0000000 --- a/layouts/partials/_thirdparty/others/mermaid.html +++ /dev/null @@ -1,15 +0,0 @@ -{{- partial "scripts/plugins.html" (dict "vendor" (.Scratch.Get "vendor") "router" (.Scratch.Get "router") "res" .Site.Data.resources.plugins "index" "mermaid") }} - - - diff --git a/layouts/partials/_thirdparty/search/algolia.html b/layouts/partials/_thirdparty/search/algolia.html index 81e67c0..c527759 100644 --- a/layouts/partials/_thirdparty/search/algolia.html +++ b/layouts/partials/_thirdparty/search/algolia.html @@ -8,7 +8,21 @@
-

+
+ \ No newline at end of file diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 5f989c2..dd4ec0c 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1,6 +1,6 @@ {{- $ft := .Site.Params.footer }} {{ if $ft.translate }} -
+
@@ -24,32 +24,6 @@ {{ $ft.copyright | default .Site.Params.author }}
-{{- with .Site.Params.busuanzi }} -{{- if .enable }} -
- {{- if .visitors }} - - {{- end }} - {{- if .views }} - - {{- end }} -
-{{- end }} -{{- end }} {{- if $ft.powered }}
{{ $pb := printf "Hugo & Hugo NexT.%s" hugo.Version .Site.Data.config.version .Site.Params.scheme }} @@ -71,7 +45,7 @@ {{- range .list }} {{- if .image }} - {{ .name }} + {{ .name }} {{- else }} {{ .name }} {{- end }} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index f9f3662..2d3a8ed 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -5,6 +5,61 @@ {{- partial "head/facebook.html" . }} {{- partialCached "head/verify.html" . }} {{- partialCached "head/style.html" . }} + {{- partial "head/config.html" . }} {{- partialCached "head/analytics.html" . }} diff --git a/layouts/partials/head/config.html b/layouts/partials/head/config.html index be3caaf..c4b9b5b 100644 --- a/layouts/partials/head/config.html +++ b/layouts/partials/head/config.html @@ -1,10 +1,40 @@ - \ No newline at end of file + +{{/* Append waline pageview & comment plugin */}} +{{ if and .Site.Params.waline ( or .Site.Params.waline.pageView .Site.Params.waline.comment) }} +{{ $counter := dict + "js" .Site.Data.resources.plugins.waline.js +}} +{{ $pageCfg = merge $pageCfg (dict "waline" $counter) }} +{{ end }} + +{{/* Append mermaid plugin */}} +{{ if .Params.mermaid }} +{{ $mermaid := dict + "js" .Site.Data.resources.plugins.mermaid.js +}} +{{ $pageCfg = merge $pageCfg (dict "mermaid" $mermaid) }} +{{ end }} + +{{/* Append math render plugin */}} +{{ with or .Params.math .Site.Params.math }} +{{ $math := dict + "render" . + "js" (index $.Site.Data.resources.plugins .).js +}} + +{{ if eq . "katex" }} + {{ $math = merge $math ( dict "css" $.Site.Data.resources.plugins.katex.css ) }} +{{ end }} + +{{ $pageCfg = merge $pageCfg (dict "math" $math) }} +{{ end }} + + \ No newline at end of file diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 956a531..ec1a2f3 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -1,3 +1,3 @@ -{{ partial "header/brand.html" . }} +{{ partialCached "header/brand.html" . }} {{ partial "header/menus.html" . }} -{{ partial "header/search.html" . }} \ No newline at end of file +{{ partialCached "header/search.html" . }} \ No newline at end of file diff --git a/layouts/partials/init.html b/layouts/partials/init.html index 30c88bf..68e54e6 100644 --- a/layouts/partials/init.html +++ b/layouts/partials/init.html @@ -114,6 +114,24 @@ {{ $config = merge $config (dict "addthis" $addthis) }} {{ end }} +{{ with .Site.Params.siteState.statistic }} +{{ $statis := dict "statis" . }} +{{ $config = merge $config $statis }} +{{ end }} + +{{ with .Site.Params.analytics.laId }} +{{ $lawidget := dict + "js" $.Site.Data.resources.analytics.laWidget + "id" . +}} +{{ $config = merge $config (dict "lawidget" $lawidget) }} +{{ end }} + +{{ with .Site.Params.analytics.busuanzi }} +{{ $busz := dict "pageview" .postViews }} +{{ $config = merge $config (dict "busuanzi" $busz) }} +{{ end }} + {{ $globalVars.Set "config" $config }} {{ with .Site.Params.customFilePath }} @@ -122,4 +140,10 @@ {{ end }} {{ end }} +{{ $theme := "light" }} +{{ if .Site.Params.darkmode }} + {{ $theme = "dark" }} +{{ end }} +{{ $globalVars.Set "theme" $theme }} + {{ return $globalVars.Values }} diff --git a/layouts/partials/post/footer_meta/reward.html b/layouts/partials/post/footer_meta/reward.html index 0b34727..f9eba82 100644 --- a/layouts/partials/post/footer_meta/reward.html +++ b/layouts/partials/post/footer_meta/reward.html @@ -11,7 +11,7 @@ {{- $pay := replace $name $fw ($fw | upper) 1 }} {{- $payName := T (printf "Reward%s" $pay) }}
- {{ $.Site.Params.author }} - {{ $payName }} + {{ $.Site.Params.author }} - {{ $payName }} {{ $payName }}
{{- end }} diff --git a/layouts/partials/post/header.html b/layouts/partials/post/header.html index f78979d..b482c8e 100644 --- a/layouts/partials/post/header.html +++ b/layouts/partials/post/header.html @@ -27,12 +27,25 @@ {{ partial "post/header_meta/created_date.html" . }} {{ partial "post/header_meta/update_date.html" . }} {{ partial "post/header_meta/categories.html" . }} + {{ if and $.IsHome (not (isset .Params "extlink")) }} + + {{ end }}
{{- if not $.IsHome }} {{ end }} diff --git a/layouts/partials/post/header_meta/comments.html b/layouts/partials/post/header_meta/comments.html new file mode 100644 index 0000000..2e54dd0 --- /dev/null +++ b/layouts/partials/post/header_meta/comments.html @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/layouts/partials/post/header_meta/views.html b/layouts/partials/post/header_meta/views.html index 303d74c..7a15037 100644 --- a/layouts/partials/post/header_meta/views.html +++ b/layouts/partials/post/header_meta/views.html @@ -2,9 +2,6 @@ {{- if .Site.Params.leancloudVisitors.enable }} {{- $pageViewId = "leancloud-visitors-count" }} {{- end }} -{{- if .Site.Params.waline.pageView }} -{{- $pageViewId = "waline-pageview-count" }} -{{- end }} {{- if .Site.Params.analytics.busuanzi.postViews }} {{- $pageViewId = "busuanzi_value_page_pv" }} {{- end }} @@ -15,5 +12,7 @@ - + + + diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index e75e74a..9f052a3 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -1,15 +1,2 @@ -{{ partialCached "scripts/global.html" . }} - -{{ if or .Params.math .Site.Params.math }} - {{ partialCached "_thirdparty/others/math.html" . }} -{{ end }} - -{{ if .Params.mermaid }} - {{ partialCached "_thirdparty/others/mermaid.html" . }} -{{ end }} - - - - - - +{{- partialCached "scripts/global.html" . -}} +{{- partial "scripts/plugins.html" . -}} \ No newline at end of file diff --git a/layouts/partials/scripts/global.html b/layouts/partials/scripts/global.html index b1f70b5..69e14d3 100644 --- a/layouts/partials/scripts/global.html +++ b/layouts/partials/scripts/global.html @@ -1,79 +1,101 @@ -{{- $jsRes := .Site.Data.resources.js }} -{{- $vendor := .Site.Params.vendors.plugins }} -{{- $router := .Scratch.Get "router" }} -{{- range $jsRes }} +{{/* Loading all page need scripts */}} +{{ $jsRes := .Site.Data.resources.js }} +{{ $vendor := .Site.Params.vendors.plugins }} +{{ $router := .Scratch.Get "router" }} +{{ range $jsRes }} {{ $pluginJS := partial "_funs/get_res.html" (dict "res" . "vendor" $vendor "router" $router) }} -{{- end }} +{{ end }} - + -{{- $config := resources.Get "js/config.js" }} -{{- $motion := resources.Get "js/motion.js" }} -{{- $boot := resources.Get "js/next-boot.js" }} -{{- $utils := resources.Get "js/utils.js" }} -{{- $nextjs := (slice $config $utils $boot ) }} -{{- if .Site.Params.motion.enable }} +{{/* Core scripts */}} +{{ $config := resources.Get "js/config.js" }} +{{ $utils := resources.Get "js/utils.js" }} +{{ $boot := resources.Get "js/next-boot.js" }} +{{ $nextjs := slice $config $utils $boot }} + +{{/* Animation scripts */}} +{{ if .Site.Params.motion.enable }} {{ $motionjs := resources.Get "js/motion.js" }} {{ $nextjs = $nextjs | append $motionjs }} -{{- end }} -{{- if or (eq .Site.Params.shceme "Muse") (eq .Site.Params.shceme "Mist") }} +{{ end }} + +{{/* Special scheme scripts */}} +{{ if or (eq .Site.Params.shceme "Muse") (eq .Site.Params.shceme "Mist") }} {{ $musejs := resources.Get "js/schemes/muse.js" }} {{ $nextjs = $nextjs | append $musejs }} -{{- end }} -{{- if .Site.Params.bookmark.enable }} -{{- $bookmarkjs := resources.Get "js/bookmark.js" }} -{{- $nextjs = $nextjs | append $bookmarkjs }} -{{- end }} -{{- if .Site.Params.pjax }} -{{- $pjaxjs := resources.Get "js/pjax.js" }} -{{- $nextjs = $nextjs | append $pjaxjs }} -{{- end }} -{{- if isset .Site.Params "addthisid" }} -{{- $addthisjs := resources.Get "js/third-party/share/addthis.js" }} -{{- $nextjs = $nextjs | append $addthisjs }} -{{- end }} -{{- if isset .Site.Params "waline" }} -{{- $walinejs := resources.Get "js/third-party/comments/waline.js" }} -{{- $nextjs = $nextjs | append $walinejs }} -{{- end }} -{{- if isset .Site.Params "giscus" }} -{{- $giscusjs := resources.Get "js/third-party/comments/giscus.js" }} -{{- $nextjs = $nextjs | append $giscusjs }} -{{- end }} -{{- if isset .Site.Params "livere" }} -{{- $liverejs := resources.Get "js/third-party/comments/livere.js" }} -{{- $nextjs = $nextjs | append $liverejs }} -{{- end }} -{{- if isset .Site.Params "artalk" }} -{{- $artalkjs := resources.Get "js/third-party/comments/artalk.js" }} -{{- $nextjs = $nextjs | append $artalkjs }} -{{- end }} -{{- if isset .Site.Params "utterances" }} -{{- $utterancesjs := resources.Get "js/third-party/comments/utterances.js" }} -{{- $nextjs = $nextjs | append $utterancesjs }} -{{- end }} -{{- if .Site.Params.localSearch.enable }} -{{- $search := resources.Get "js/third-party/search/local.js" }} -{{- $nextjs = $nextjs | append $search }} {{ end }} -{{- if .Site.Params.algoliaSearch.enable }} -{{- $search := resources.Get "js/third-party/search/algolia.js" }} -{{- $nextjs = $nextjs | append $search }} + +{{/* Bookmark scripts */}} +{{ if .Site.Params.bookmark.enable }} +{{ $bookmarkjs := resources.Get "js/bookmark.js" }} +{{ $nextjs = $nextjs | append $bookmarkjs }} +{{ end }} + +{{/* Pjax scripts */}} +{{ if .Site.Params.pjax }} +{{ $pjaxjs := resources.Get "js/pjax.js" }} +{{ $nextjs = $nextjs | append $pjaxjs }} +{{ end }} + +{{/* Share scripts */}} +{{ if isset .Site.Params "addthisid" }} +{{ $addthisjs := resources.Get "js/third-party/share/addthis.js" }} +{{ $nextjs = $nextjs | append $addthisjs }} +{{ end }} + +{{/* Comments scripts */}} +{{ if isset .Site.Params "waline" }} +{{ $walinejs := resources.Get "js/third-party/comments/waline.js" }} +{{ $nextjs = $nextjs | append $walinejs }} +{{ if or .Site.Params.waline.pageView .Site.Params.waline.comment }} + {{ $counterjs := resources.Get "js/third-party/others/counter.js" }} + {{ $nextjs = $nextjs | append $counterjs }} + {{ end }} +{{ end }} +{{ if isset .Site.Params "giscus" }} +{{ $giscusjs := resources.Get "js/third-party/comments/giscus.js" }} +{{ $nextjs = $nextjs | append $giscusjs }} +{{ end}} +{{ if isset .Site.Params "livere" }} +{{ $liverejs := resources.Get "js/third-party/comments/livere.js" }} +{{ $nextjs = $nextjs | append $liverejs }} +{{ end }} +{{ if isset .Site.Params "artalk" }} +{{ $artalkjs := resources.Get "js/third-party/comments/artalk.js" }} +{{ $nextjs = $nextjs | append $artalkjs }} +{{ end }} +{{ if isset .Site.Params "utterances" }} +{{ $utterancesjs := resources.Get "js/third-party/comments/utterances.js" }} +{{ $nextjs = $nextjs | append $utterancesjs }} +{{ end }} + +{{/* Search engin scripts */}} +{{ if .Site.Params.localSearch.enable }} +{{ $search := resources.Get "js/third-party/search/local.js" }} +{{ $nextjs = $nextjs | append $search }} +{{ end }} +{{ if .Site.Params.algoliaSearch.enable }} +{{ $search := resources.Get "js/third-party/search/algolia.js" }} +{{ $nextjs = $nextjs | append $search }} +{{ end }} + +{{/* Other not useful scripts, eg: 51la widget, translate */}} +{{ with .Site.Params.siteState.statistic }} + {{ if and .enable (eq .plugin "51la") }} + {{ $lawt := resources.Get "js/third-party/others/lawidget.js" }} + {{ $nextjs = $nextjs | append $lawt }} + {{ end }} {{ end }} {{ if .Site.Params.footer.translate }} -{{- $gt := resources.Get "js/third-party/others/google-translate.js" }} -{{- $nextjs = $nextjs | append $gt }} - -{{ $gtCss := resources.Get "css/gt.scss" }} -{{ $style := $gtCss | resources.ToCSS | minify }} - +{{ $translate := resources.Get "js/third-party/others/translate.js" }} +{{ $nextjs = $nextjs | append $translate }} {{ end }} -{{- $nextjs = $nextjs | resources.Concat "js/main.js"}} + + +{{ $nextjs = $nextjs | resources.Concat "js/main.js"}} {{ if hugo.IsProduction }} -{{- $nextjs = $nextjs | minify | fingerprint }} +{{ $nextjs = $nextjs | minify | fingerprint }} {{ end }} - \ No newline at end of file diff --git a/layouts/partials/scripts/plugins.html b/layouts/partials/scripts/plugins.html index ddb791a..4587138 100644 --- a/layouts/partials/scripts/plugins.html +++ b/layouts/partials/scripts/plugins.html @@ -1,17 +1,9 @@ +{{/* Defind loading plugin scripts which only need in pages */}} -{{- $vendor := .vendor }} -{{- $router := .router }} -{{- $res := (index .res .index) }} -{{- $cssRes := $res.css }} -{{ if $cssRes }} - {{ range $cssRes }} - {{ $css := partial "_funs/get_res.html" (dict "res" . "vendor" $vendor "router" $router) }} - - {{ end }} -{{ end }} -{{- $jsRes := $res.js }} -{{ range $jsRes }} - {{ $js := partial "_funs/get_res.html" (dict "res" . "vendor" $vendor "router" $router) }} - +{{ if or .Params.math .Site.Params.math }} + {{ partial "_funs/get_plugin.html" (dict "ctx" . "class" "others" "plugin" "math.js") }} {{ end }} +{{ if .Params.mermaid }} + {{ partial "_funs/get_plugin.html" (dict "ctx" . "class" "others" "plugin" "mermaid.js") }} +{{ end }} \ No newline at end of file diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index 83c493c..c4c5b0e 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -4,7 +4,8 @@