Sort OPML feeds list + link to the HTML version by default

This commit is contained in:
2026-03-08 11:17:16 -05:00
parent 16d8bdb47d
commit c448283d70
3 changed files with 16 additions and 3 deletions

View File

@@ -1,6 +1,15 @@
import fs from "fs";
import * as opml from "opml";
const sortArrayOfObjectsByProperty = (arr, prop, desc=false) => {
const direction = desc ? -1 : 1
return arr.sort((a, b) => {
if ( a[prop] < b[prop] ) return -1 * direction
if ( a[prop] > b[prop] ) return 1 * direction
return 0
})
}
export const setupBlogCollections = eleventyConfig => {
eleventyConfig.addCollection("blogByYear", api => {
const postsByYear = {}
@@ -45,6 +54,9 @@ export const setupBlogCollections = eleventyConfig => {
opml.parse(xml, (err, doc) => err ? rej(err) : res(doc))
})
return parsed.opml.body.subs
let subs = parsed.opml.body.subs
subs = sortArrayOfObjectsByProperty(subs, 'title')
subs.forEach(cat => cat.subs = sortArrayOfObjectsByProperty(cat.subs, 'title'))
return subs
})
}