Sort OPML feeds list + link to the HTML version by default
This commit is contained in:
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user