/** * Butterfly * Related Posts * According the tag */ 'use strict' hexo.extend.helper.register('related_posts', function (currentPost, allPosts) { let relatedPosts = [] currentPost.tags.forEach(function (tag) { allPosts.forEach(function (post) { if (isTagRelated(tag.name, post.tags)) { const relatedPost = { title: post.title, path: post.path, cover: post.cover, cover_type: post.cover_type, weight: 1, updated: post.updated, created: post.date } const index = findItem(relatedPosts, 'path', post.path) if (index !== -1) { relatedPosts[index].weight += 1 } else { if (currentPost.path !== post.path) { 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 += '