| 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); |
LiuShen / 友链friend.json生成新方式
Last active 3 months ago
通过HEXO内置Generator生成,更加快捷,不需要json包