GoogleChrome / webdev-infra

Apache License 2.0
37 stars 28 forks source link

fix: add utility to fetch XML feeds #78

Closed mamieorine closed 1 year ago

mamieorine commented 1 year ago

fixes #71

The utility for fetching RSS feeds which can be used in external data jobs ideally exports a single method that reads the authorsData.json file on both web.dev and d.c.c, loops over all authors and looks for a to-be-introduced external key, which contains the configurable list of arbitrary sources.

Next is fetching the feeds from the sources in the external key, normalising them and writing a JSON file containing all data needed for the updated author page layout. The written JSON file named external-posts.json will be located at src/site/_data/ directory.


How to test this job with web.dev.

  1. Updates an authorsData.json file in webdev project, just for testing purposes:
{
  "danristic": {
    "homepage": "http://www.danristic.com/",
    "twitter": "dristic101",
    "image": "image/T4FyVKpzu4WKF1kBNvXepbi08t52/b6v4qq26t6NWHAIm0SbV.png",
    "external": [
      {
        "url": "https://www.bram.us/feed/"
      },
      {
        "url": "https://www.tunetheweb.com/rss.xml"
      },
      {
        "url": "https://una.im/rss.xml"
      },
      {
        "url": "https://nerdy.dev/rss.xml"
      }
    ]
  },
  "paulkinlan": {
    "homepage": "https://paul.kinlan.me/",
    "twitter": "paul_kinlan",
    "image": "image/T4FyVKpzu4WKF1kBNvXepbi08t52/0O1ZGr2P0l9oTKabyUK5.jpeg",
    "external": [
      {
        "label": "blog",
        "url": "https://paul.kinlan.me/index.xml"
      },
      {
        "label": "dcc",
        "url": "https://developer.chrome.com/authors/paulkinlan/feed.xml"
      },
      {
        "label": "webdev",
        "url": "https://web.dev/authors/paulkinlan/feed.xml"
      }
    ]
  }
}
  1. Run npm install on webdev-infra project. Then wrap up a new webdev-infra module and replace the current module with a new one at the node_modules directory in web.dev. project.

  2. Adds this code below in the eleventy.js in web.dev. project.

const authorsData = fs.readFileSync('src/site/_data/authorsData.json', 'utf8');
const {externalPosts} = require('webdev-infra/utils/rss-feeds')
externalPosts(authorsData);
  1. Run npm run build, a new JSON file named external-posts.json will be generated to src/site/_data/ path.