From f3fc99ac033ca27a91cb2c0f1f3465436d3237ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Mon, 12 Sep 2022 16:43:24 +0800 Subject: [PATCH] :lipstick: Add 51la analytics widget plug-in in sidebar. --- assets/css/gemini/style.css | 176 ------------------------- assets/css/main.scss | 2 +- assets/js/utils.js | 36 +++-- data/resources.yaml | 1 + exampleSite/config.yaml | 47 +++++-- i18n/en.yaml | 5 + i18n/zh-cn.yaml | 5 + layouts/partials/sidebar.html | 4 +- layouts/partials/sidebar/overview.html | 2 +- layouts/partials/sidebar/siteinfo.html | 61 ++++++--- 10 files changed, 125 insertions(+), 214 deletions(-) delete mode 100644 assets/css/gemini/style.css diff --git a/assets/css/gemini/style.css b/assets/css/gemini/style.css deleted file mode 100644 index 8fd9dfe..0000000 --- a/assets/css/gemini/style.css +++ /dev/null @@ -1,176 +0,0 @@ -/** User-defined style. **/ -{{ $P := .Site.Params -}} - -{{- with $P.sidebar -}} -{{- $width := (int (math.Max .width 240)) -}} -{{- $offset := (int (math.Max .offset 12)) -}} -{{- $padding := (int (math.Max .padding 18)) -}} -{{- $positPad := (add $width $offset) }} -.main { -{{ if eq .position "right" }} - flex-direction: row-reverse; -{{- end }} -} -.header-inner { - width: {{ $width }}px; -} -.main-inner { - width: calc(100% - {{ $positPad }}px); -} -.sidebar { - width: {{ $width }}px; - visibility: inherit; -} -.sidebar-inner { - padding: {{ $padding }}px 10px; -} -.footer-inner { - padding-{{ .position }}: {{ $positPad }}px; -} -{{- end }} - -.site-author-image { -{{- if $P.avatar.rounded }} - border-radius:50%; -{{- end }} -{{- if $P.avatar.rotated }} - transition: transform 1s ease-out; -{{- end }} -} - -.site-author-image:hover { - transform: rotateZ(360deg); -} - -.site-state-item { - border-left: 1px solid #eee; -} -.site-state-item:first-child { - border-left: none; -} - -.rss-link { - border-top: 1px dotted #ccc; - border-bottom: 1px dotted #ccc; - text-align: center; - margin: 10px 0 0 0; -} - -.rss-link a { - display: block; - color: #fc6423; - border-bottom: none; -} - -.rss-link a:hover { - animation-name: wobble-vertical; - animation-duration: 2s; - animation-timing-function: ease-in-out; - animation-iteration-count: 1; -} - -.rss-link a:hover > i { - -webkit-transform: scaleY(-1); - transform: scaleY(-1); -} - -.links-of-social a { - font-size: 0.8125em; -} -.links-of-social .fa, -.links-of-social .fab, -.links-of-social .far, -.links-of-social .fas { - margin-right: 2px; -} -.links-of-social { - display: flex; - flex-wrap: wrap; - justify-content: center; -} -.links-of-social-item { - margin: 5px 0 0; -{{- if and $P.socialIcons.enable (not $P.socialIcons.iconsOnly) }} - width: 50%; -{{- end }} -} -.links-of-social-item a { - box-sizing: border-box; - display: inline-block; - max-width: 100%; - overflow: hidden; - padding: 0 5px; - text-overflow: ellipsis; - white-space: nowrap; -} -.links-of-social-item a { - border-bottom: 0; - border-radius: 4px; - display: block; -} -.links-of-social-item a:hover { - background: var(--body-bg-color); -} - -.cc-license { -{{ if eq $P.creativeCommons.size "big" }} - margin-top: 10px; -{{ else }} - margin-top: 5px; -{{- end }} -} - -.back-to-top { - bottom: 30px; -} - -.posts-expand .post-meta-container { - margin: 10px auto; -} - -.post-meta-item-icon { - margin: 0 0 0 -5px; -} - -:not(.post-meta-break) + .post-meta-item::before { - content: '|'; - margin: 0 0.3em; -} - -.post-meta-catg:not(:last-child)::after { - content: ';'; - margin: 0px; -} - -.posts-expand .post-header { - margin: 0; -} - -.posts-expand .post-body { - margin: 28px 0; -} - -.post-footer-btn { - text-align: center; -} - -.beian img { - display: inline-block; - margin: 0 3px; - vertical-align: middle; -} - -.with-love { -{{- with $P.footer.icon.color }} - color: {{ $P.footer.icon.color }}; -{{- end }} -{{- if $P.footer.icon.animated }} - animation: icon-animate 1.33s ease-in-out infinite; -{{- end }} -} - -/* Font Awesome */ -.fa-spin { - -webkit-animation: fa-spin .8s infinite linear; - animation: fa-spin .8s infinite linear; -} diff --git a/assets/css/main.scss b/assets/css/main.scss index 945bb35..0907ec5 100644 --- a/assets/css/main.scss +++ b/assets/css/main.scss @@ -65,7 +65,7 @@ $back2top_sidebar : {{ $P.backTop.sidebar }}; $avatar_rotated : {{ $P.avatar.rotated }}; $avatar_rounded : {{ $P.avatar.rounded }}; $avatar_rounded : {{ $P.avatar.rounded }}; -$site_state : {{ $P.siteState }}; +$site_state : {{ $P.siteState.basic }}; $social_icons_only : {{ $P.socialIcons.iconsOnly }}; $social_icons_transition : {{ $P.socialIcons.transition }}; $links_settings_layout : {{ $P.linksSets.layout }}; diff --git a/assets/js/utils.js b/assets/js/utils.js index 7fe5fd5..f9fca45 100644 --- a/assets/js/utils.js +++ b/assets/js/utils.js @@ -34,15 +34,7 @@ NexT.utils = { const wordsCount = document.getElementById('wordsCount'); if (wordsCount) { const words = wordsCount.getAttribute('data-count'); - let wordsLabel; - if (words > 10000) { - wordsLabel = (words / 10000.0).toFixed(2) + ' w'; - } else if (words > 1000) { - wordsLabel = (words / 1000.0).toFixed(2) + ' k'; - } else { - wordsLabel = words; - } - wordsCount.innerText = wordsLabel; + wordsCount.innerText = NexT.utils.numberFormat(words); } const readTimes = document.getElementById('readTimes'); @@ -72,6 +64,32 @@ NexT.utils = { const pushDateVal = NexT.utils.diffDate(lastPushDate.getAttribute('data-lastPushDate'), 1); lastPushDate.innerText = pushDateVal; } + + var statistic = document.querySelectorAll('#la-siteinfo-widget span'); + if (statistic) { + 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(statistic[valIds[i]].innerText); + document.getElementById(domIds[i]).innerText = pv; + } + } + }, + + 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) { + result = (number / 1000.0).toFixed(2) + ' k'; + } else { + result = number; + } + return result; }, diffDate: function(date, mode = 0) { diff --git a/data/resources.yaml b/data/resources.yaml index 5d57b65..5b60aa6 100644 --- a/data/resources.yaml +++ b/data/resources.yaml @@ -29,6 +29,7 @@ css: # Site analytics engine analytics: la: https://sdk.51.la/js-sdk-pro.min.js + laWidget: https://v6-widget.51.la/v6/JiZkaipzkPyiCL8x/quote.js?theme=0&col=true&f=12&display=0,0,0,1,0,1,1,1 baidu: https://hm.baidu.com/hm.js? google: https://www.googletagmanager.com/gtag/js?id= busuanzi: https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index 9a0bed7..058a0fb 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -39,15 +39,28 @@ 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 + # # More: https://xyproto.github.io/splash/docs/all.html + # style: "monokai" + anchorLineNos: true codeFences: true - lineNos: true - lineNumbersInTable: true + guessSyntax: true + hl_Lines: "" + hl_inline: false + lineAnchors: "" + lineNoStart: 1 + lineNos: false + lineNumbersInTable: false noClasses: true - # 高亮代码的样式名称,可选:monokai | emacs | api | dracula | friendly - # 更多的样式:https://xyproto.github.io/splash/docs/all.html - # Highlight style: monokai | emacs | api | dracula | friendly - # More: https://xyproto.github.io/splash/docs/all.html - style: "monokai" + noHl: false + style: monokai + tabWidth: 2 tableOfContents: # 开始/结束标题级别:1-6 # Heading title level of start or end: 1-6 @@ -91,6 +104,10 @@ outputs: # Enable robots with support crawler scan enableRobotsTXT: true +# 强制输出时压缩文件 +# Compress all files when output +minify: + #-------------------------------------- # 菜单配置说明 # identifier : 唯一标识不可重复 @@ -279,10 +296,18 @@ params: # 开启头像随鼠标转动动画 # If true, the avatar will be rotated with the cursor. rotated: true - - # 是否在侧边栏显示文章、分类、标签信息 - # Posts / Categories / Tags in sidebar. - siteState: true + siteState: + # 是否在侧边栏显示文章、分类、标签信息 + # Posts / Categories / Tags in sidebar. + basic: true + # 站点访问信息 + # Site information + statistic: + enable: true + # 组件类型,可选值为: 51la, busuanzi + # 使用51la时需要注册账号:https://invite.51.la/1NUfGTS1?target=V6 + # Plguin value is: 51la, busuzazi + plugin: 51la # 社交链接地址 # 用法: `Key: 名称 || 链接地址 || 图标` diff --git a/i18n/en.yaml b/i18n/en.yaml index d936713..6e4ee2b 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -135,11 +135,16 @@ PostCommentTitle: other: Comments SiteInfoItems: + title: "Web Status" runTimes: "Running:" words: "Words:" readTimes: "ReadTime:" visitors: "Visitors:" pageViews: "Views:" + todayViews: "Today Views:" + yesterdayViews: "Yesterday Views:" + monthViews: "Month Views:" + totalViews: "Total Views" lastUpdate: "Last Update:" FooterPowerby: diff --git a/i18n/zh-cn.yaml b/i18n/zh-cn.yaml index a53ff79..c30457e 100644 --- a/i18n/zh-cn.yaml +++ b/i18n/zh-cn.yaml @@ -136,11 +136,16 @@ PostCommentTitle: other: 评论交流 SiteInfoItems: + title: "网站资讯" runTimes: "已运行:" words: "总字数:" readTimes: "阅读约:" visitors: "总访客数:" pageViews: "页面浏览:" + todayViews: "今日访问:" + yesterdayViews: "昨日访问:" + monthViews: "本月访问:" + totalViews: "总访问量:" lastUpdate: "最后更新于:" FooterPowerby: diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index 2331580..176c26c 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -34,7 +34,9 @@ - {{ partial "sidebar/siteinfo.html" . }} + {{- if .Site.Params.siteState.statistic.enable }} + {{- partial "sidebar/siteinfo.html" . }} + {{- end }} {{- if and .Site.Params.backTop.enable .Site.Params.backTop.sidebar }} -{{- if .Site.Params.siteState }} +{{- if .Site.Params.siteState.basic }}