-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: gitalk cannot login; feat: manifest
- Loading branch information
Showing
17 changed files
with
237 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,24 @@ | ||
/* | ||
* @Author: Rainy | ||
* @Date: 2019-12-01 14:25:59 | ||
* @LastEditors: Rainy | ||
* @LastEditTime: 2019-12-05 20:38:59 | ||
* @LastEditors : Rainy | ||
* @LastEditTime : 2020-02-07 12:53:01 | ||
*/ | ||
|
||
function tryRun (fn, times = 3) { | ||
let execCount = 1; | ||
fn(next); | ||
function next(delay) { | ||
if (execCount >= times) { | ||
return; | ||
} | ||
setTimeout(() => { | ||
execCount += 1 | ||
fn(next) | ||
}, delay); | ||
} | ||
} | ||
|
||
function integrateGitalk(router) { | ||
const linkGitalk = document.createElement('link'); | ||
linkGitalk.href = 'https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css'; | ||
linkGitalk.rel = 'stylesheet'; | ||
document.body.appendChild(linkGitalk); | ||
const scriptGitalk = document.createElement('script'); | ||
scriptGitalk.src = 'https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js'; | ||
document.body.appendChild(scriptGitalk); | ||
// import copy from './utils/copy'; | ||
import getGitalk from './utils/getGitalk'; | ||
|
||
router.afterEach((to, from) => { | ||
|
||
if (scriptGitalk.onload) { | ||
loadGitalk(to); | ||
} else { | ||
scriptGitalk.onload = () => { | ||
loadGitalk(to); | ||
}; | ||
export default ({ Vue, options, router, siteData }) => { | ||
setTimeout(() => { | ||
try { | ||
//对document的判断是防止编译的时候报错 | ||
document && | ||
(() => { | ||
getGitalk({ router }); | ||
// copy(); | ||
})(); | ||
} catch (e) { | ||
console.error(e.message); | ||
} | ||
}); | ||
|
||
function loadGitalk(to) { | ||
let commentsContainer = document.getElementById('gitalk-container'); | ||
if (!commentsContainer) { | ||
commentsContainer = document.createElement('div'); | ||
commentsContainer.id = 'gitalk-container'; | ||
commentsContainer.classList.add('content'); | ||
} | ||
const $page = document.querySelector('.page'); | ||
if ($page) { | ||
$page.appendChild(commentsContainer); | ||
if (typeof Gitalk !== 'undefined' && Gitalk instanceof Function) { | ||
renderGitalk(to.fullPath); | ||
} | ||
} | ||
} | ||
function renderGitalk(fullPath) { | ||
const gitalk = new Gitalk({ | ||
clientID: '58efa883d352424befd3', | ||
clientSecret: 'faf0e2d7ff9355b3692d605d698f7abcbbd43388', | ||
repo: 'https://github.com/Rain120/awesome-javascript-code-implementation', | ||
owner: 'rain120', | ||
admin: ['rain120'], | ||
id: window.location.pathname || fullPath || 'comment', | ||
distractionFreeMode: false, | ||
language: 'zh-CN' | ||
}); | ||
gitalk.render('gitalk-container'); | ||
} | ||
} | ||
|
||
export default ({ Vue, options, router }) => { | ||
try { | ||
document && integrateGitalk(router); | ||
} catch (e) { | ||
console.error(e.message); | ||
} | ||
}, 500); | ||
}; |
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "非常棒的JavaScript源码实现", | ||
"short_name": "JavaScript源码实现", | ||
"theme_color": "#3EAF7C", | ||
"background_color": "#3EAF7C", | ||
"display": "standalone", | ||
"Scope": "/", | ||
"start_url": "/", | ||
"icons": [ | ||
{ | ||
"src": "images/icons/icon-72x72.png", | ||
"sizes": "72x72", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "images/icons/icon-96x96.png", | ||
"sizes": "96x96", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "images/icons/icon-128x128.png", | ||
"sizes": "128x128", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "images/icons/icon-144x144.png", | ||
"sizes": "144x144", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "images/icons/icon-152x152.png", | ||
"sizes": "152x152", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "images/icons/icon-192x192.png", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "images/icons/icon-384x384.png", | ||
"sizes": "384x384", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "images/icons/icon-512x512.png", | ||
"sizes": "512x512", | ||
"type": "image/png" | ||
} | ||
], | ||
"splash_pages": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* @Author: Rainy | ||
* @Date: 2020-02-07 11:10:37 | ||
* @LastEditors : Rainy | ||
* @LastEditTime : 2020-02-07 11:11:27 | ||
*/ | ||
|
||
export default () => { | ||
function addCopy(e) { | ||
let copyTxt = ''; | ||
e.preventDefault(); // 取消默认的复制事件 | ||
copyTxt = window.getSelection(0).toString(); | ||
copyTxt = `${copyTxt}\n作者:Rain120\n原文:${window.location.href}\n著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。`; | ||
const clipboardData = e.clipboardData || window.clipboardData; | ||
clipboardData.setData('text', copyTxt); | ||
} | ||
document.addEventListener('cut', e => { | ||
addCopy(e); | ||
}); | ||
document.addEventListener('copy', e => { | ||
addCopy(e); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* @Author: Rainy | ||
* @Date: 2020-02-07 11:06:08 | ||
* @LastEditors : Rainy | ||
* @LastEditTime : 2020-02-07 12:49:22 | ||
*/ | ||
|
||
// export default ({ pages }) => { | ||
// const path = window.location.pathname || 'comment'; | ||
// // 获取当前页面信息 | ||
// const dist = pages.filter(item => { | ||
// return item.path === path; | ||
// })[0]; | ||
|
||
// //只有在isNoPage是false的时候才会显示评论 | ||
// if (!dist.frontmatter || !dist.frontmatter.isNoPage) { | ||
// const page = document.querySelector('.page'); | ||
|
||
// const linkGitalk = document.createElement('link'); | ||
// linkGitalk.href = 'https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css'; | ||
// linkGitalk.rel = 'stylesheet'; | ||
// document.body.appendChild(linkGitalk); | ||
|
||
// const scriptGitalk = document.createElement('script'); | ||
// scriptGitalk.src = 'https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js'; | ||
// document.body.appendChild(scriptGitalk); | ||
|
||
// scriptGitalk.onload = () => { | ||
// let gitalk = document.createElement('div'); | ||
// gitalk.id = 'gitalk-container'; | ||
// page.appendChild(gitalk); | ||
// var _gitalk = new Gitalk({ | ||
// clientID: '58efa883d352424befd3', | ||
// clientSecret: 'faf0e2d7ff9355b3692d605d698f7abcbbd43388', | ||
// repo: 'https://github.com/Rain120/awesome-javascript-code-implementation', | ||
// owner: 'rain120', | ||
// admin: ['rain120'], | ||
// // id: window.location.pathname || fullPath || 'comment', | ||
// distractionFreeMode: false, | ||
// language: 'zh-CN', | ||
// id: decodeURI(path) // 每个页面根据url生成对应的issue,保证页面之间的评论都是独立的 | ||
// }); | ||
// _gitalk.render('gitalk-container'); | ||
// }; | ||
// } | ||
// }; | ||
|
||
|
||
function tryRun (fn, times = 3) { | ||
let execCount = 1; | ||
fn(next); | ||
function next(delay) { | ||
if (execCount >= times) { | ||
return; | ||
} | ||
setTimeout(() => { | ||
execCount += 1 | ||
fn(next) | ||
}, delay); | ||
} | ||
} | ||
|
||
export default ({ router }) => { | ||
const linkGitalk = document.createElement('link'); | ||
linkGitalk.href = 'https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css'; | ||
linkGitalk.rel = 'stylesheet'; | ||
document.body.appendChild(linkGitalk); | ||
|
||
const scriptGitalk = document.createElement('script'); | ||
scriptGitalk.src = 'https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js'; | ||
document.body.appendChild(scriptGitalk); | ||
|
||
router.afterEach((to, from) => { | ||
if (scriptGitalk.onload) { | ||
loadGitalk(to); | ||
} else { | ||
scriptGitalk.onload = () => { | ||
loadGitalk(to); | ||
}; | ||
} | ||
}); | ||
|
||
function loadGitalk(to) { | ||
let commentsContainer = document.getElementById('gitalk-container'); | ||
if (!commentsContainer) { | ||
commentsContainer = document.createElement('div'); | ||
commentsContainer.id = 'gitalk-container'; | ||
commentsContainer.classList.add('content'); | ||
} | ||
const $page = document.querySelector('.page'); | ||
if ($page) { | ||
$page.appendChild(commentsContainer); | ||
if (typeof Gitalk !== 'undefined' && Gitalk instanceof Function) { | ||
renderGitalk(to.fullPath); | ||
} | ||
} | ||
} | ||
|
||
function renderGitalk(fullPath) { | ||
const path = window.location.pathname || fullPath || 'comment'; | ||
|
||
const gitalk = new Gitalk({ | ||
clientID: '58efa883d352424befd3', | ||
clientSecret: 'faf0e2d7ff9355b3692d605d698f7abcbbd43388', | ||
repo: 'https://github.com/Rain120/awesome-javascript-code-implementation', | ||
owner: 'rain120', | ||
admin: ['rain120'], | ||
distractionFreeMode: false, | ||
language: 'zh-CN', | ||
id: decodeURI(path), // 每个页面根据url生成对应的issue,保证页面之间的评论都是独立的 | ||
}); | ||
gitalk.render('gitalk-container'); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.