Include external blog post in the list of posts? #5666
Unanswered
gaborcsardi
asked this question in
Question / Answer
Replies: 1 comment
-
|
@gaborcsardi // index.js
const Hexo = require("hexo");
const hexo = new Hexo(process.cwd(), { silent: false });
// In this example, the information about articles posted on other sites is hardcoded, but it's also possible to fetch it via an API.
const otherSiteContents = [{
title: 'other site A content1',
updated: new Date(),
permalink: 'https://site.a.example.com/content1'
},
{
title: 'other site A content2',
updated: new Date(),
permalink: 'https://site.a.example.com/content2'
},
{
title: 'other site B content1',
updated: new Date(),
permalink: 'https://site.b.example.com/content1'
}
]
hexo.init().then(() => {
hexo.load().then(() => {
const posts = hexo.locals.get("posts");
const merged = [...posts.toArray(), ...otherSiteContents].sort((a, b) => {
// Of course, you can also sort by date to get the publication date, or by title to sort by title.
return new Date(a.updated) - new Date(b.updated);
});
for (let post of merged) {
console.log(`${post.updated} - ${post.title} ${post.permalink}`)
}
});
});If you save the above code as |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I sometimes write blog posts other blogs, and would like to include links to these in the list of posts on my personal site. Is there a way to do this in hexo?
Beta Was this translation helpful? Give feedback.
All reactions