fi3ework / hexo-theme-archer

🎯 A smart and modern theme for Hexo.
https://fi3ework.github.io/hexo-theme-archer
MIT License
1.49k stars 274 forks source link

还是上次那个分享的问题。 #315

Closed FlyyingPiggy2020 closed 2 years ago

FlyyingPiggy2020 commented 2 years ago

在把9月7号的文件,覆盖掉旧的文件之后。 我执行了hexo clean ,hexo g -d. 还是没有出现分享的二维码。

http://106.15.53.70/2021/09/06/433M%E9%81%A5%E6%8E%A7%E5%99%A8%E6%8E%A5%E6%94%B6/ 上面这个是出问题的连接。 下面这个是我的share.js的代码。

是不是还要配置什么东西,才会出现分享的二维码。 `/**

import qrcode from 'qrcode-generator'

function initQR(sURL) { const typeNumber = 0 const errorCorrectionLevel = 'L' const qr = qrcode(typeNumber, errorCorrectionLevel) qr.addData(sURL) qr.make() document.getElementsByClassName('share-qrcode')[0].innerHTML = qr.createImgTag() }

function generate(templateURL, param) { const shareURL = templateURL .replace(/<%-sURL%>/g, encodeURIComponent(param.sURL)) .replace(/<%-sTitle%>/g, param.sTitle) .replace(/<%-sDesc%>/g, param.sDesc) .replace(/<%-sAuthor%>/g, param.sAuthor) .replace(/<%-sImg%>/g, encodeURIComponent(param.sImg)) window.open(shareURL) }

function handleShareClick(type, param) { if (type === 'weibo') { generate( 'http://service.weibo.com/share/share.php?url=<%-sURL%>&title=<%-sTitle%>&pic=<%-sImg%>', param ) } else if (type === 'qzone') { generate( 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=<%-sURL%>&title=<%-sTitle%>&pics=<%-sImg%>&summary=<%-sDesc%>', param ) } else if (type === 'facebook') { generate('https://www.facebook.com/sharer/sharer.php?u=<%-sURL%>', param) } else if (type === 'twitter') { generate( 'https://twitter.com/intent/tweet?text=<%-sTitle%>&url=<%-sURL%>&via=<%-sAuthor%>', param ) } else if (type === 'qr') { // pre init qr } }

function init() { const sURL = window.location.href const sTitle = document.querySelector('title').innerHTML let sImg = document.querySelector('.article-entry img') && document.querySelector('.article-entry img').getAttribute('src') sImg = window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '') + sImg const sDesc = document.querySelector('.article-entry') && document.querySelector('.article-entry').innerText.substring(0, 30) + '...' const sAuthor = window.siteMeta.author const param = { sURL, sTitle, sImg, sDesc, sAuthor, }

const shareWrapper = document.querySelector('.share-list') if (!shareWrapper) { return } initQR(sURL) shareWrapper.addEventListener('click', function (e) { if (!e.target.getAttribute('data-type')) { return } handleShareClick(e.target.getAttribute('data-type'), param) }) }

init() `