friend-json-generator.js
· 850 B · JavaScript
Ham
const blacklist = ["友站名称1", "友站名称2", "友站名称3"];
const path = "friend.json";
function genFriendJSON(locals) {
var friends = [];
var data = locals.data.link;
data.forEach((entry, index) => {
let lastIndex = 2;
if (index < lastIndex) {
const filteredLinkList = entry.link_list.filter(
(linkItem) => !blacklist.includes(linkItem.name)
);
friends = friends.concat(filteredLinkList);
}
});
const friendData = {
friends: friends.map((item) => {
return [item.name, item.link, item.avatar];
}),
};
console.log("friend.json 文件已生成。");
return [{
path: path,
data: JSON.stringify(friendData, null),
}, ];
}
hexo.extend.generator.register("friend_circle", genFriendJSON);
1 | const blacklist = ["友站名称1", "友站名称2", "友站名称3"]; |
2 | const path = "friend.json"; |
3 | |
4 | function genFriendJSON(locals) { |
5 | var friends = []; |
6 | var data = locals.data.link; |
7 | data.forEach((entry, index) => { |
8 | let lastIndex = 2; |
9 | if (index < lastIndex) { |
10 | const filteredLinkList = entry.link_list.filter( |
11 | (linkItem) => !blacklist.includes(linkItem.name) |
12 | ); |
13 | friends = friends.concat(filteredLinkList); |
14 | } |
15 | }); |
16 | const friendData = { |
17 | friends: friends.map((item) => { |
18 | return [item.name, item.link, item.avatar]; |
19 | }), |
20 | }; |
21 | console.log("friend.json 文件已生成。"); |
22 | return [{ |
23 | path: path, |
24 | data: JSON.stringify(friendData, null), |
25 | }, ]; |
26 | } |
27 | |
28 | hexo.extend.generator.register("friend_circle", genFriendJSON); |