-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add disqus plugin, closed #123
- Loading branch information
1 parent
025bc5c
commit fd7d4e0
Showing
3 changed files
with
63 additions
and
1 deletion.
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
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,47 @@ | ||
location.href = location.href.replace('/-/', '/#/') | ||
|
||
function install (hook, vm) { | ||
const dom = Docsify.dom | ||
const disqus = vm.config.disqus | ||
if (!disqus) { | ||
throw Error('$docsify.disqus is required') | ||
} | ||
|
||
hook.init(_ => { | ||
const script = dom.create('script') | ||
|
||
script.async = true | ||
script.src = `https://${disqus}.disqus.com/embed.js` | ||
script.setAttribute('data-timestamp', +new Date()) | ||
dom.appendTo(dom.body, script) | ||
}) | ||
|
||
hook.mounted(_ => { | ||
const div = dom.create('div') | ||
div.id = 'disqus_thread' | ||
const main = dom.getNode('#main') | ||
div.style = `width: ${main.clientWidth}px; margin: 0 auto 20px;` | ||
dom.appendTo(dom.find('.content'), div) | ||
|
||
window.disqus_config = function () { | ||
this.page.url = location.origin + '/-' + vm.route.path | ||
this.page.identifier = vm.route.path | ||
this.page.title = document.title | ||
} | ||
}) | ||
|
||
hook.doneEach(_ => { | ||
if (typeof window.DISQUS !== 'undefined') { | ||
DISQUS.reset({ | ||
reload: true, | ||
config: function () { | ||
this.page.url = location.origin + '/-' + vm.route.path | ||
this.page.identifier = vm.route.path | ||
this.page.title = document.title | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
$docsify.plugins = [].concat(install, $docsify.plugins) |