atom.ts 633 B

12345678910111213141516171819
  1. import { getProperty } from './feed';
  2. import { Feed } from './types';
  3. export function parseAtomFeed(txt: string): Feed {
  4. const domParser = new DOMParser();
  5. const doc = domParser.parseFromString(txt, 'text/xml');
  6. const feed: Feed = {
  7. items: Array.from(doc.querySelectorAll('entry')).map((node) => ({
  8. title: getProperty(node, 'title'),
  9. link: node.querySelector('link')?.getAttribute('href') ?? '',
  10. content: getProperty(node, 'content'),
  11. pubDate: getProperty(node, 'published'),
  12. ogImage: node.querySelector("meta[property='og:image']")?.getAttribute('content'),
  13. })),
  14. };
  15. return feed;
  16. }