From e6ee562996d04f93df922c2e8ae19088ca457597 Mon Sep 17 00:00:00 2001 From: elkan1788 Date: Mon, 5 Aug 2024 20:38:20 +0800 Subject: [PATCH] :sparkles::fire::lipstick: Remove sharethis & add others. --- .../_common/components/post/post-footer.scss | 18 ++++++++++++ assets/css/main.scss | 2 ++ assets/js/third-party/share/addthis.js | 16 ---------- assets/js/third-party/share/addtoany.js | 24 +++++++++++++++ assets/js/third-party/share/sharethis.js | 21 ++++++++++++++ data/resources.yaml | 8 +++-- exampleSite/config.yaml | 18 ++++++++---- .../partials/_thirdparty/share/addthis.html | 3 -- .../partials/_thirdparty/share/addtoany.html | 11 +++++++ .../partials/_thirdparty/share/sharethis.html | 1 + layouts/partials/init.html | 29 +++++++++++++++---- layouts/partials/post/footer.html | 17 +++++++++-- layouts/partials/scripts/global.html | 19 ++++++++++-- 13 files changed, 150 insertions(+), 37 deletions(-) delete mode 100644 assets/js/third-party/share/addthis.js create mode 100644 assets/js/third-party/share/addtoany.js create mode 100644 assets/js/third-party/share/sharethis.js delete mode 100644 layouts/partials/_thirdparty/share/addthis.html create mode 100644 layouts/partials/_thirdparty/share/addtoany.html create mode 100644 layouts/partials/_thirdparty/share/sharethis.html diff --git a/assets/css/_common/components/post/post-footer.scss b/assets/css/_common/components/post/post-footer.scss index a7aa412..5cb7f52 100644 --- a/assets/css/_common/components/post/post-footer.scss +++ b/assets/css/_common/components/post/post-footer.scss @@ -91,3 +91,21 @@ } } } + +@if $post_share_enable { + .post-share-tools { + display: flex; + justify-content: center; + + a { + border: 0px; + } + } + + @if $post_sharethis_set { + .st-cmp-settings { + display: none; + } + } +} + diff --git a/assets/css/main.scss b/assets/css/main.scss index 1865bbd..11fba61 100644 --- a/assets/css/main.scss +++ b/assets/css/main.scss @@ -85,6 +85,8 @@ $post_edit_enable : {{ $P.postEdit.enable }}; $post_meta_item_text : {{ $P.postMeta.itemText }}; $reward_settings_animation : {{ $P.rewardSets.animation }}; $post_end_tag_icon : {{ $P.postFooter.tagIcon }}; +$post_share_enable : {{ $P.share.enable }}; +$post_sharethis_set : {{ isset $P.share "sharethis" }}; // TODO find the paramters $text_align_desktop : {{ $P.textAlign.desktop }}; diff --git a/assets/js/third-party/share/addthis.js b/assets/js/third-party/share/addthis.js deleted file mode 100644 index 1bc88e3..0000000 --- a/assets/js/third-party/share/addthis.js +++ /dev/null @@ -1,16 +0,0 @@ -/* 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.lazyLoadComponent(element, function() { - NexT.utils.getScript(addthis_js, { - attributes: { - async: false - }, - parentNode: document.querySelector(element) - }); - }); -} \ No newline at end of file diff --git a/assets/js/third-party/share/addtoany.js b/assets/js/third-party/share/addtoany.js new file mode 100644 index 0000000..950b0b1 --- /dev/null +++ b/assets/js/third-party/share/addtoany.js @@ -0,0 +1,24 @@ +/* Addtoany share plugin */ +NexT.plugins.share.addtoany = function() { + const element = '.a2a_kit'; + if (!NexT.CONFIG.share.enable || !NexT.utils.checkDOMExist(element)) return; + + const addtoany = NexT.CONFIG.share.addtoany; + + if (!addtoany) return; + + NexT.utils.lazyLoadComponent(element, function() { + let addtoany_cfg = ` + var a2a_config = a2a_config || {}; + a2a_config.onclick = 1; + a2a_config.locale = "${addtoany.locale}"; + a2a_config.num_services = ${addtoany.num}; + `; + + NexT.utils.getScript(null, { + textContent: addtoany_cfg + }); + + NexT.utils.getScript(addtoany.js, () => { NexT.utils.hiddeLodingCmp(element); }); + }); +} \ No newline at end of file diff --git a/assets/js/third-party/share/sharethis.js b/assets/js/third-party/share/sharethis.js new file mode 100644 index 0000000..8a78257 --- /dev/null +++ b/assets/js/third-party/share/sharethis.js @@ -0,0 +1,21 @@ +/* Sharethis share plugin */ +NexT.plugins.share.sharethis = function() { + const element = '.sharethis-inline-share-buttons'; + if (!NexT.CONFIG.share.enable || !NexT.utils.checkDOMExist(element)) return; + + const sharethis = NexT.CONFIG.share.sharethis; + + if (!sharethis) return; + + const sharethis_js = sharethis.js.replace(/id/, sharethis.id); + + NexT.utils.lazyLoadComponent(element, function() { + NexT.utils.getScript(sharethis_js, { + attributes: { + async: 'async' + } + }); + + NexT.utils.hiddeLodingCmp(element); + }); +} \ No newline at end of file diff --git a/data/resources.yaml b/data/resources.yaml index 2da1d7e..41c1148 100644 --- a/data/resources.yaml +++ b/data/resources.yaml @@ -90,8 +90,12 @@ analytics: # 文章分享 # Share -addthis: - js: https://s7.addthis.com/js/300/addthis_widget.js +share: + sharethis: + js: https://platform-api.sharethis.com/js/sharethis.js#property=id&product=inline-share-buttons&source=platform + + addtoany: + js: https://static.addtoany.com/menu/page.js # 评论组件 # Comment component diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index 5c703b4..87ba743 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -935,11 +935,19 @@ params: id: # color: "#fc6423" - # AddThis文章分享功能(服务商已下线,不推荐使用) - # 更多信息及配置请参考:https://www.addthis.com - # AddThis Share (The service provider has been offline, not recommended for use) - # See: https://www.addthis.com - # addThisId: # + # 文章分享功能 + share: + enable: true + # 更多信息与配置,请参考:https://sharethis.com + # For more information and configuration, please refer to:https://sharethis.com + # sharethis: + # id: # + # 简单的在线分享,没有统计数据功能,更多信息可参考:https://www.addtoany.com/ + # Simple online sharing without statistical data function. + # For more information, please refer to: https://www.addtoany.com/ + addtoany: + locale: zh-CN + num_services: 8 # --------------------------------------------------------------- diff --git a/layouts/partials/_thirdparty/share/addthis.html b/layouts/partials/_thirdparty/share/addthis.html deleted file mode 100644 index 520e2e1..0000000 --- a/layouts/partials/_thirdparty/share/addthis.html +++ /dev/null @@ -1,3 +0,0 @@ -{{ if isset .Site.Params "addthisid" }} -
-{{ end }} \ No newline at end of file diff --git a/layouts/partials/_thirdparty/share/addtoany.html b/layouts/partials/_thirdparty/share/addtoany.html new file mode 100644 index 0000000..f2a2718 --- /dev/null +++ b/layouts/partials/_thirdparty/share/addtoany.html @@ -0,0 +1,11 @@ +
+ + + + + + + + + +
\ No newline at end of file diff --git a/layouts/partials/_thirdparty/share/sharethis.html b/layouts/partials/_thirdparty/share/sharethis.html new file mode 100644 index 0000000..74b3f22 --- /dev/null +++ b/layouts/partials/_thirdparty/share/sharethis.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/layouts/partials/init.html b/layouts/partials/init.html index 5b16e82..1fe126d 100644 --- a/layouts/partials/init.html +++ b/layouts/partials/init.html @@ -139,12 +139,29 @@ {{ $config = merge $config (dict "utterances" $utterances) }} {{ end }} -{{ with .Site.Params.addThisId }} -{{ $addthis := dict - "js" $.Site.Data.resources.addthis.js - "cfg" (dict "pubid" .) -}} -{{ $config = merge $config (dict "addthis" $addthis) }} +{{ with .Site.Params.share }} + +{{ $share := dict "enable" .enable }} + +{{ if isset . "sharethis" }} + {{ $sharethis := dict + "js" $.Site.Data.resources.share.sharethis.js + "id" .sharethis.id + }} + {{ $share = merge $share (dict "sharethis" $sharethis) }} +{{ end }} + +{{ if isset . "addtoany" }} + {{ $addtoany := dict + "js" $.Site.Data.resources.share.addtoany.js + "locale" .addtoany.locale + "num" .addtoany.num_services + }} + + {{ $share = merge $share (dict "addtoany" $addtoany) }} +{{ end }} + +{{ $config = merge $config (dict "share" $share) }} {{ end }} {{ with .Site.Params.siteState.statistic }} diff --git a/layouts/partials/post/footer.html b/layouts/partials/post/footer.html index 5995722..1cda9eb 100644 --- a/layouts/partials/post/footer.html +++ b/layouts/partials/post/footer.html @@ -10,8 +10,21 @@
{{ else }} {{ partial "post/footer_meta/tags.html" . }} -{{ if and (not (isset .Params "share")) (not .Params.share) }} -{{ partial "_thirdparty/share/addthis.html" . }} +{{ $enable := .Params.share | default .Site.Params.share.enable }} +{{ with .Site.Params.share }} + {{ if $enable }} +
+
+ +
+ {{ if isset . "sharethis" }} + {{ partial "_thirdparty/share/sharethis.html" }} + {{ end }} + {{ if isset . "addtoany" }} + {{ partial "_thirdparty/share/addtoany.html" }} + {{ end }} +
+ {{ end }} {{ end }}
{{ partial "post/footer_meta/reward.html" . }} diff --git a/layouts/partials/scripts/global.html b/layouts/partials/scripts/global.html index d017f2b..956dd88 100644 --- a/layouts/partials/scripts/global.html +++ b/layouts/partials/scripts/global.html @@ -40,9 +40,22 @@ {{ end }} {{/* Share scripts */}} -{{ if isset .Site.Params "addthisid" }} -{{ $addthisjs := resources.Get "js/third-party/share/addthis.js" }} -{{ $nextjs = $nextjs | append $addthisjs }} +{{/** if and .Site.Params.share.enable (isset .Site.Params "sharethisid") }} +{{ $sharethisjs := resources.Get "js/third-party/share/sharethis.js" }} +{{ $nextjs = $nextjs | append $sharethisjs }} +{{ end **/}} + +{{ with .Site.Params.share }} +{{ if or .enable .Params.share }} + {{ if isset . "sharethis" }} + {{ $sharethisjs := resources.Get "js/third-party/share/sharethis.js" }} + {{ $nextjs = $nextjs | append $sharethisjs }} + {{ end }} + {{ if isset . "addtoany" }} + {{ $addtoanyjs := resources.Get "js/third-party/share/addtoany.js" }} + {{ $nextjs = $nextjs | append $addtoanyjs }} + {{ end }} +{{ end }} {{ end }} {{/* Comments scripts */}}