swilgosz/hanamimastery

Add RSS Feed

Closed this issue · 3 comments

Overview

Implement automatic RSS feed generation.

Todo:

  • Feedly should load content
  • Ruby Land sources should not return error: http://rubyland.news/sources
  • Publication date should be recognized properly
  • The descriptions should be loaded properly.
  • The feed thumbnail (feedly) should be properly recognized.

Useful links:

Acceptance criteria:

We have 2 streams of content:

  1. Episodes - official episodes, with YT videos
  2. Stray - thoughts out of the main scope.

Write a RSS generator, that

  • Loops through all content
  • Merge two streams of content (articles and episodes)
  • Sorts by FILE CREATION DATE (or if not possible, by ID from meta data)
  • Generates RSS feed.
  • Saves file in the public/rss.xml

NICE to have

  • render the rss.xml file content under https://hanamimastery.com/rss (no extension) if possible

Dev notes

You're free to add any other fields, bulk of the stuff here is done in getRssData.

export async function getRssData() {
  const feed = new rss({
    title: "Hanami Mastery newest episodes!",
    description: "The best way to master Hanami ruby framework!",
    feed_url: "https://hanamimastery.com/rss.xml",
    site_url: "https://hanamimastery.com",
    image_url: "https://hanamimastery.com/logo-hm.jpeg",
    managingEditor: "Sebastian Wilgosz",
    webMaster: "Sebastian Wilgosz",
    copyright: "2021 Sebastian Wilgosz",
    language: "en",
    categories: ["Ruby", "Hanami", "Web development"],
    pubDate: new Date().toLocaleString(),
    ttl: "60",
  });

  const posts = await getAllFilesFrontMatter("stray");
  const episodes = await getAllFilesFrontMatter("episodes");
  const postsWithSlug = posts.map((item) => ({
    ...item,
    url: `https://hanamimastery.com/articles/${item.slug}`,
  }));
  const episodesWithSlug = episodes.map((item) => ({
    ...item,
    url: `https://hanamimastery.com/episodes/${item.slug}`,
  }));
  const items = postsWithSlug.concat(episodesWithSlug).sort((itemA, itemB) => {
    if (itemA.id > itemB.id) return -1;
    if (itemA.id < itemB.id) return 1;
    return 0;
  });
  items.map(({ author, tags, title, id, url }) => {
    feed.item({ author, title, categories: tags, guid: id, url });
  });
  return feed;
}

Regarding sorting via file creation date - it's always going to change. During deployment, will always be the same, since the repo is being built after having been downloaded onto Vercel's machines.

A good alternative - specify written_at or created_at in font matter and then sort by this. Let me know if you run into any issues, too - dealing with time and dates in js can be gruesome.

@adamszwaba here are some of the troubles I've noticed.

  1. http://rubyland.news/sources - This rss reader has problems parsing my feed.

image

  1. The content is not loaded (type HTML).
  2. Feedly does not show the content, when you click the single episode.
  3. Also, feedly shows ALL episodes, as published at the same time, currently 3h ago.

Screenshot_2021-07-05-22-09-34-86_1ab895e2a8c0baee42df612a40cf0390 (1)

What I've noticed, is that all my strings/text is wrapped within the ![CDATA] blocks, which are basically comments ref

Closing for now, I'll open different issue for the RSS tweaks.