awesome-ipfs/scripts/data.js
Henrique Dias a89015da98
feat: clean up (a lot) (#247)
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
2019-04-30 17:35:30 +01:00

35 lines
936 B
JavaScript

const fs = require('fs')
const { join } = require('path')
const yaml = require('node-yaml')
const { sortAbc, sortInv, slugify } = require('./utils')
const dir = join(__dirname, '../data')
const trimIfExists = (str) => str ? str.trim() : undefined
module.exports = fs.readdirSync(dir)
.map(file => join(dir, file))
.map(file => yaml.readSync(file))
.map(file => {
file.slug = slugify(file.title)
file.type = 'category'
file.content = file.content.map(({ title, description, ...meta }, i) => ({
...meta,
title: trimIfExists(title),
description: trimIfExists(description),
category: file.slug,
color: file.color,
index: i
}))
let sort = (a, b) => sortAbc(a.title, b.title)
if (file.slug === 'articles') {
sort = (a, b) => sortInv(a.date, b.date)
}
file.content = file.content.sort(sort)
return file
})
.sort((a, b) => sortAbc(a.title, b.title))