I like the idea of micro.blog, and I’ve lazily cross-posted my blog to the site via RSS for a while, but the feed always ended up in the format of [post title] - [link to post], which doesn’t capture the spirt of microblogging.
I reworked the RSS feed in general when updating this site to next.js, but I thought I'd take a stab at getting micro.blog crossposting working too.
Since I couldn’t find much in their documentation on what parameters were used to construct the micro.blog feed from an RSS feed, I found users who were cross posting, looked at their feeds, and then tested out a couple posts to see how they showed up on the timeline.
Notes:
I ended up taking the same loop my index page uses (gets every single markdown post, but then returns the latest ten) and running it through this function:
1import siteConfig from "../data/config.json"; 2var md = require("markdown-it")(); 3 4const makeJsonFeed = (posts) => { 5 const feed = { 6 feed_url: siteConfig.jsonURL, 7 title: siteConfig.description, 8 home_page_url: siteConfig.siteUrl, 9 author: { 10 url: siteConfig.siteUrl, 11 name: siteConfig.author, 12 }, 13 }; 14 const items = posts.map((post) => { 15 return { 16 author: { 17 url: siteConfig.siteUrl, 18 name: siteConfig.author, 19 }, 20 id: `${siteConfig.siteURL}${post.slug}`, 21 url: `${siteConfig.siteURL}${post.slug}`, 22 date_published: post.frontmatter.date, 23 content_html: md.render(post.markdownBody), 24 }; 25 }); 26 feed.items = items; 27 28 return JSON.stringify(feed); 29}; 30 31export default makeJsonFeed;
And on the index route, I use it like this:
1const jsonFeedObj = makeJsonFeed(postsToUse); 2fs.writeFileSync("./public/rss/feed.json", jsonFeedObj);
While I do have titles on most of my posts, they are optional, and I chose to leave them off the JSON feed. If they are added, micro.blog goes back to the [post title] - [link to post] I was trying to get away from!
You can see the result at my micro.blog timeline or in the JSON feed.