hexo-next-mastodon-comments-core 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3
+
4
+ name: Node.js Package
5
+
6
+ on:
7
+ release:
8
+ types: [created]
9
+
10
+ jobs:
11
+ publish-npm:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: actions/setup-node@v2
16
+ with:
17
+ node-version: 14
18
+ registry-url: https://registry.npmjs.org/
19
+ - run: npm publish
20
+ env:
21
+ NODE_AUTH_TOKEN: ${{secrets.npm_token}}
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Hexo NexT Mastodon Comments
2
+
3
+ ![Theme Version](https://img.shields.io/badge/NexT-v8.4.0+-blue?style=flat-square)
4
+ ![Package Version](https://img.shields.io/github/package-json/v/feiju12138/hexo-next-mastodon-comments?style=flat-square)
5
+
6
+ Mastodon Comments system for NexT.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install hexo-next-mastodon-comments-core
12
+ ```
13
+
14
+ ## Configure
15
+
16
+ Set the value `enable` to `true`, add the Mastodon instance domain (`MASTODON_DOMAIN`), and add the Mastodon instance username (`MASTODON_USER`). You can config those in both **hexo** or **theme** `_config.yml`:
17
+
18
+ ```yml next/_config.yml
19
+ # Mastodon Comments
20
+ # For more information: https://github.com/feiju12138/mastodon-comments https://github.com/feiju12138/hexo-next-mastodon-comments
21
+ mastodon-comments:
22
+ enable: false
23
+ MASTODON_DOMAIN: mastodon.social # Mastodon 实例域名
24
+ MASTODON_USER: feiju # Mastodon 实例中根评论发布的用户名
25
+ # JS: https://cdn.jsdelivr.net/gh/feiju12138/mastodon-comments@latest/dist/mastodon-comments.min.js # 自定义 JS 文件地址
26
+ ```
27
+
28
+ ## Add `toot-id` in post header
29
+
30
+ ⚠️ Use quotes for toot-id to avoid JS precision loss.
31
+
32
+ ```md source/_posts/Test.md
33
+ ---
34
+ toot-id: "116164221651686918"
35
+ ---
36
+ ```
37
+
38
+ You can also use [feiju12138/hexo-next-mastodon-comments-helper](https://github.com/feiju12138/hexo-next-mastodon-comments-helper) to auto add `toot-id` in post header.
package/default.yaml ADDED
@@ -0,0 +1,7 @@
1
+ # Mastodon Comments
2
+ # For more information: https://github.com/feiju12138/mastodon-comments https://github.com/feiju12138/hexo-next-mastodon-comments
3
+ mastodon-comments:
4
+ enable: false
5
+ MASTODON_DOMAIN: mastodon.social # Mastodon 实例域名
6
+ MASTODON_USER: feiju # Mastodon 实例中根评论发布的用户名
7
+ # JS: https://cdn.jsdelivr.net/gh/feiju12138/mastodon-comments@latest/dist/mastodon-comments.min.js # 自定义 JS 文件地址
@@ -0,0 +1,22 @@
1
+ {{ next_data("mastodon-comments", config["mastodon-comments"]) }}
2
+
3
+ <script>
4
+ document.addEventListener("page:loaded", () => {
5
+ if (!CONFIG.page.comments) return;
6
+
7
+ NexT.utils.loadComments("#mastodon-comments")
8
+ .then(() => NexT.utils.getScript(CONFIG["mastodon-comments"].JS || "https://cdn.jsdelivr.net/gh/feiju12138/mastodon-comments@latest/dist/mastodon-comments.min.js"))
9
+ .then(() => {
10
+ const tootIdEl = document.getElementById("toot-id");
11
+ if (tootIdEl && tootIdEl.textContent !== "undefined") {
12
+ initMastodonComments({
13
+ MASTODON_DOMAIN: CONFIG["mastodon-comments"].MASTODON_DOMAIN,
14
+ MASTODON_USER: CONFIG["mastodon-comments"].MASTODON_USER,
15
+ TOOT_ID: tootIdEl.textContent
16
+ });
17
+ } else {
18
+ document.getElementById("mastodon-comments").textContent = "当前文章未配置嘟文ID"
19
+ }
20
+ });
21
+ });
22
+ </script>
package/index.js ADDED
@@ -0,0 +1,46 @@
1
+ /* global hexo */
2
+
3
+ "use strict";
4
+
5
+ // 注入嘟文编号
6
+ hexo.extend.filter.register("after_post_render", function (data) {
7
+
8
+ // 跳过所有非文章的页面
9
+ if (data.layout !== "post") {
10
+ return data;
11
+ }
12
+
13
+ // 在头部注入嘟文编号
14
+ data.content = [
15
+ `<div id="toot-id" style="display: none">${data["toot-id"]}</div>`,
16
+ data.content
17
+ ].join("");
18
+
19
+ return data;
20
+ });
21
+
22
+ // 注入外部依赖
23
+ const css = hexo.extend.helper.get("css").bind(hexo);
24
+ hexo.extend.injector.register(
25
+ "head_end",
26
+ () => css("https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css"),
27
+ "post",
28
+ );
29
+
30
+ // 添加评论
31
+ const Util = require("@next-theme/utils");
32
+ hexo.extend.filter.register("theme_inject", injects => {
33
+ // 获取配置
34
+ const utils = new Util(hexo, __dirname);
35
+ const config = utils.defaultConfigFile("mastodon-comments", "default.yaml");
36
+
37
+ // 判断是否未启用或缺少关键配置
38
+ if (!config.enable || !config.MASTODON_DOMAIN || !config.MASTODON_USER) return;
39
+
40
+ // 定义挂载点
41
+ injects.comment.raw("Mastodon Comments", `<div class="comments"><div id="mastodon-comments"></div></div>`, {}, { cache: true });
42
+
43
+ // 加载渲染脚本
44
+ injects.bodyEnd.raw("Mastodon Comments", utils.getFileContent("hexo-next-mastodon-comments.njk"));
45
+
46
+ });
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "hexo-next-mastodon-comments-core",
3
+ "version": "1.0.5",
4
+ "description": "Mastodon Comments system for NexT.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": "https://github.com/feiju12138/hexo-next-mastodon-comments",
10
+ "keywords": [
11
+ "Hexo",
12
+ "NexT",
13
+ "mastodon-comments"
14
+ ],
15
+ "author": "feiju12138",
16
+ "license": "LGPL-3.0",
17
+ "bugs": {
18
+ "url": "https://github.com/feiju12138/hexo-next-mastodon-comments/issues"
19
+ },
20
+ "homepage": "https://github.com/feiju12138/hexo-next-mastodon-comments#readme",
21
+ "dependencies": {
22
+ "@next-theme/utils": "^1.1.0"
23
+ }
24
+ }
package/renovate.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": [
3
+ "config:base"
4
+ ]
5
+ }