Skip to content

Commit

Permalink
OPML file (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwojcik authored Aug 17, 2024
1 parent c031430 commit b3b1df5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
6 changes: 3 additions & 3 deletions _11ty/api/allFeeds.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const fetchJsonFeeds = require("./jsonFeeds");
const fetchXmlFeeds = require("./xmlFeeds");
const fetchRssFeeds = require("./rssFeeds");

module.exports = async () => {
const xmlFeeds = await fetchXmlFeeds();
const rssFeeds = await fetchRssFeeds();
const jsonFeeds = await fetchJsonFeeds();

const allFeeds = [...xmlFeeds, ...jsonFeeds]
const allFeeds = [...rssFeeds, ...jsonFeeds]
.sort((a, b) => a.name.localeCompare(b.name))
.filter((item) => item);

Expand Down
2 changes: 0 additions & 2 deletions _11ty/api/jsonFeeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ module.exports = async () => {
.sort((a, b) => new Date(b.published) - new Date(a.published))
.slice(0, siteConfig.maxItemsPerFeed);

// TODO: Validate article items

return {
...site,
articles,
Expand Down
6 changes: 2 additions & 4 deletions _11ty/api/xmlFeeds.js → _11ty/api/rssFeeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const siteConfig = require("../../content/_data/siteConfig");
const stripAndTruncateHTML = require("../helpers/stripAndTruncateHTML");

module.exports = async () => {
const xmlFeedSites = siteMetadata().filter((site) => site.feedType === "xml");
const rssFeedSites = siteMetadata().filter((site) => site.feedType === "rss");
const { extractFromXml } = await feedExtractor;

const feedContents = await xmlFeedSites.map(async (site) => {
const feedContents = await rssFeedSites.map(async (site) => {
try {
const feedData = await EleventyFetch(site.feed, {
...ELEVENTY_FETCH_OPTIONS,
Expand All @@ -20,8 +20,6 @@ module.exports = async () => {

const { entries } = extractFromXml(feedData);

// TODO: Validate article items

const articles = entries
.map((item) => ({
title: item.title || siteConfig.defaultArticleTitle,
Expand Down
4 changes: 2 additions & 2 deletions _11ty/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const path = require("path");
const siteConfig = require("../content/_data/siteConfig");

module.exports = {
DEFAULT_FEED_TYPE: "xml",
ALLOWED_FEED_TYPES: ["xml", "json"],
DEFAULT_FEED_TYPE: "rss",
ALLOWED_FEED_TYPES: ["rss", "json"],
SITES_DIRECTORY: path.join("content", "sites"),
ALLOWED_SITE_PROPERTIES: [
"file",
Expand Down
1 change: 1 addition & 0 deletions content/_data/phrases.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
sAvatar: "'s avatar",
newerArticles: "Newer",
olderArticles: "Older",
opmlFileTitle: "All feeds",
menu: {
sites: "Sites",
about: "About",
Expand Down
2 changes: 2 additions & 0 deletions content/pages/sites.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ canonical: /sites/

This is a list of sites aggregated on this Multiplicity instance. Modify it by adding / editing Markdown files in `content/sites` directory.

[Download OPML file](/feeds.opml)

{% include "partials/sitelist.njk" %}
15 changes: 15 additions & 0 deletions content/utils/opml.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
permalink: /feeds.opml
eleventyExcludeFromCollections: true
---
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>{{ phrases.opmlFileTitle }}</title>
</head>
<body>
{%- for site in sites %}
<outline text="{{ site.name }}" title="{{ site.name }}" type="{{ site.feedType }}" xmlUrl="{{ site.feed }}"/>
{%- endfor %}
</body>
</opml>

0 comments on commit b3b1df5

Please sign in to comment.