-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
29 lines (24 loc) · 788 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"use strict";
const jsyml = require("js-yaml");
const fs = require("fs");
hexo.extend.helper.register("post_author", function (post_obj) {
const authorDir = hexo.source_dir + "_authors/";
const authorFiles = fs.readdirSync(authorDir);
const authorData = [];
for (const element of authorFiles) {
const authorFile = element;
const authorFileData = fs.readFileSync(authorDir + authorFile, "utf8");
const authorFileJson = jsyml.load(authorFileData);
authorData.push(authorFileJson);
}
const post = post_obj;
const post_authors = post.authors;
post.author = [];
for (const p_author of post_authors) {
const author = authorData.find((a) => a.username === p_author);
if (author) {
post.author.push(author);
}
}
return post.author
});