/* eslint-disable camelcase */ /** * Butterfly * Related Posts * According the tag */ 'use strict' const { postDesc } = require('../common/postDesc') hexo.extend.helper.register('related_posts', function (currentPost, allPosts) { let relatedPosts = [] const tagsData = currentPost.tags tagsData.length && tagsData.forEach(function (tag) { allPosts.forEach(function (post) { if (currentPost.path !== post.path && isTagRelated(tag.name, post.tags)) { const getPostDesc = post.postDesc || postDesc(post, hexo) const relatedPost = { title: post.title, path: post.path, cover: post.cover, cover_type: post.cover_type, weight: 1, updated: post.updated, created: post.date, postDesc: getPostDesc } const index = findItem(relatedPosts, 'path', post.path) if (index !== -1) { relatedPosts[index].weight += 1 } else { relatedPosts.push(relatedPost) } } }) }) if (relatedPosts.length === 0) { return '' } let result = '' const hexoConfig = hexo.config const config = hexo.theme.config const limitNum = config.related_post.limit || 6 const dateType = config.related_post.date_type || 'created' const headlineLang = this._p('post.recommend') relatedPosts = relatedPosts.sort(compare('weight')) if (relatedPosts.length > 0) { result += '