-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hexo/next): add hexo-next-waline plugin
- Loading branch information
Showing
6 changed files
with
131 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Waline | ||
# For more information: https://waline.js.org, https://github.com/lizheming/waline | ||
waline: | ||
enable: false | ||
serverURL: https://waline.vercel.app # Waline server address url | ||
placeholder: Just go go # Comment box placeholder | ||
avatar: mm # Gravatar style | ||
meta: [nick, mail, link] # Custom comment header | ||
pageSize: 10 # Pagination size | ||
lang: # Language, available values: en, zh-cn | ||
# Warning: Do not enable both `waline.visitor` and `leancloud_visitors`. | ||
visitor: false # Article reading statistic | ||
requiredFields: [] # Set required fields: [nick] | [nick, mail] |
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,80 @@ | ||
/* global hexo */ | ||
|
||
'use strict'; | ||
|
||
const Util = require('@next-theme/utils'); | ||
const utils = new Util(hexo, __dirname); | ||
|
||
function capitalize(input) { | ||
return input.toString().charAt(0).toUpperCase() + input.toString().substr(1); | ||
} | ||
|
||
function iconText(icon, key, defaultValue) { | ||
if (!defaultValue) { | ||
defaultValue = capitalize(key); | ||
} | ||
return ` | ||
<span class="post-meta-item-icon"> | ||
<i class="${icon}"></i> | ||
</span> | ||
{%- set post_meta_comment = __('post.comments.${key}') %} | ||
{%- if post_meta_comment == 'post.comments.${key}' %} | ||
{%- set post_meta_comment = '${defaultValue}' %} | ||
{%- endif %} | ||
<span class="post-meta-item-text">{{ post_meta_comment + __('symbol.colon') }}</span> | ||
`; | ||
} | ||
|
||
function warning(...args) { | ||
hexo.log.warn(`Since ${args[0]} is turned on, the ${args[1]} is disabled to avoid potential hazards.`); | ||
}; | ||
|
||
// Add comment | ||
hexo.extend.filter.register('theme_inject', injects => { | ||
|
||
const config = utils.defaultConfigFile('waline', 'default.yaml'); | ||
if (!config.enable || !config.serverURL) return; | ||
|
||
injects.comment.raw('waline', '<div class="comments" id="waline-comments"></div>', {}, { cache: true }); | ||
|
||
injects.bodyEnd.raw('waline', utils.getFileContent('waline.njk')); | ||
|
||
}); | ||
|
||
// Add post_meta | ||
hexo.extend.filter.register('theme_inject', injects => { | ||
|
||
const config = utils.defaultConfigFile('waline', 'default.yaml'); | ||
if (!config.enable || !config.serverURL) return; | ||
|
||
injects.postMeta.raw('waline', ` | ||
{% if post.comments and (is_post() or theme.waline.comment_count) %} | ||
<span class="post-meta-item"> | ||
${iconText('far fa-comment', 'waline')} | ||
<a title="waline" href="{{ url_for(post.path) }}#waline-comments" itemprop="discussionUrl"> | ||
<span class="post-comments-count waline-comment-count" id="{{ url_for(post.path) }}" data-xid="{{ url_for(post.path) }}" itemprop="commentCount"></span> | ||
</a> | ||
</span> | ||
{% endif %} | ||
`, {}, {}); | ||
|
||
if (config.visitor) { | ||
if (hexo.theme.config.leancloud_visitors && hexo.theme.config.leancloud_visitors.enable) { | ||
warning('waline.visitor', 'leancloud_visitors'); | ||
hexo.theme.config.leancloud_visitors.enable = false; | ||
return; | ||
} | ||
|
||
|
||
injects.postMeta.raw('waline', ` | ||
<span id="{{ url_for(post.path) }}" class="post-meta-item leancloud_visitors" data-flag-title="{{ post.title }}" title="{{ __('post.views') }}"> | ||
<span class="post-meta-item-icon"> | ||
<i class="far fa-eye"></i> | ||
</span> | ||
<span class="post-meta-item-text">{{ __('post.views') + __('symbol.colon') }}</span> | ||
<span class="leancloud-visitors-count"></span> | ||
</span> | ||
`, {}, {}); | ||
} | ||
|
||
}); |
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,21 @@ | ||
{ | ||
"name": "@waline/hexo-next", | ||
"version": "1.0.0", | ||
"description": "Waline comment system for NexT.", | ||
"main": "index.js", | ||
"repository": "lizheming/waline", | ||
"keywords": [ | ||
"Hexo", | ||
"NexT", | ||
"Waline" | ||
], | ||
"author": "lizheming <i@imnerd.org>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/lizheming/waline/issues" | ||
}, | ||
"homepage": "https://github.com/lizheming/waline/packages/#readme", | ||
"dependencies": { | ||
"@next-theme/utils": "^1.1.0" | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"extends": [ | ||
"config:base" | ||
] | ||
} |
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,10 @@ | ||
<script> | ||
NexT.utils.loadComments('#waline-comments', () => { | ||
NexT.utils.getScript('https://cdn.jsdelivr.net/npm/@waline/client/dist/Waline.min.js', () => { | ||
new Waline(Object.assign({{ config.waline | safedump }}, { | ||
el: '#waline-comments', | ||
path: {{ url_for(page.path) | replace(r/index\.html$/, '') | safedump }} | ||
})); | ||
}, window.Waline); | ||
}); | ||
</script> |