# Related Articles related_post: enable:true limit:6# Number of posts displayed date_type:created# or created or updated 文章日期顯示創建日或者更新日
1 2 3 4 5 6 7 8
# Display the article introduction on homepage # 1: description # 2: both (if the description exists, it will show description, or show the auto_excerpt) # 3: auto_excerpt (default) # false: do not show the article introduction index_post_content: method:2 length:500# if you set method to 2 or 3, the length need to config
if (relatedPosts.length > 0) { result += '<div class="relatedPosts">' result += `<div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>${headlineLang}</span></div>` result += '<div class="relatedPosts-list">' for (let i = 0; i < Math.min(relatedPosts.length, limitNum); i++) { const cover = relatedPosts[i].cover === false ? relatedPosts[i].randomcover : relatedPosts[i].cover const title = this.escape_html(relatedPosts[i].title) + const description = this.strip_html(relatedPosts[i].description) + const content = this.strip_html(relatedPosts[i].content) result += `<div><a href="${this.url_for(relatedPosts[i].path)}" title="${title}">` result += `<img class="cover" src="${this.url_for(cover)}" alt="cover">` if (dateType === 'created') { result += `<div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> ${this.date(relatedPosts[i].created, hexoConfig.date_format)}</div>` } else { result += `<div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> ${this.date(relatedPosts[i].updated, hexoConfig.date_format)}</div>` } result += `<div class="title">${title}</div>` + switch (config.index_post_content.method) { + case false: + break + case 1: + result += `<div class="info">${description}</div>` + break + case 2: + if (description) { + result += `<div class="info">${description}</div>` + } + else { + let expert = content.substring(0, config.index_post_content.length) + content.length > config.index_post_content.length ? expert += ' ...' : '' + result += `<div class="info">${expert}</div>` + } + break + default: + let expert = content.substring(0, config.index_post_content.length) + content.length > config.index_post_content.length ? expert += ' ...' : '' + result += `<div class="info">${expert}</div>` + break + } result += '</div></a></div>' }
result += '</div></div>' return result } }) function isTagRelated (tagName, TBDtags) { let result = false TBDtags.forEach(function (tag) { if (tagName === tag.name) { result = true } }) return result }
function findItem (arrayToSearch, attr, val) { for (let i = 0; i < arrayToSearch.length; i++) { if (arrayToSearch[i][attr] === val) { return i } } return -1 }
function compare (attr) { return function (a, b) { const val1 = a[attr] const val2 = b[attr] return val2 - val1 } }
.relatedPosts>.relatedPosts-list.content.date { font-size: 1rem; -webkit-transition: all .6s ease-in-out; -moz-transition: all .6s ease-in-out; -o-transition: all .6s ease-in-out; -ms-transition: all .6s ease-in-out; transition: all .6s ease-in-out; }
.relatedPosts>.relatedPosts-list.content.title { font-size: 1.1rem; -webkit-transition: all .6s ease-in-out; -moz-transition: all .6s ease-in-out; -o-transition: all .6s ease-in-out; -ms-transition: all .6s ease-in-out; transition: all .6s ease-in-out; }