mirror of
https://github.com/seigler/awesome-dash-platform
synced 2025-07-27 06:36:08 +00:00
feat: clean up (a lot) (#247)
License: MIT Signed-off-by: Henrique Dias <hacdias@gmail.com>
This commit is contained in:
parent
6f15e77ed6
commit
a89015da98
12 changed files with 141 additions and 237 deletions
|
@ -1,23 +1,34 @@
|
|||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { join } = require('path')
|
||||
const yaml = require('node-yaml')
|
||||
const { sortAbc } = require('./utils')
|
||||
const dataDir = path.join(__dirname, '../data')
|
||||
const { sortAbc, sortInv, slugify } = require('./utils')
|
||||
|
||||
const dir = join(__dirname, '../data')
|
||||
const trimIfExists = (str) => str ? str.trim() : undefined
|
||||
|
||||
const files = fs.readdirSync(dataDir)
|
||||
.map(file => path.join(dataDir, file))
|
||||
module.exports = fs.readdirSync(dir)
|
||||
.map(file => join(dir, file))
|
||||
.map(file => yaml.readSync(file))
|
||||
.map(file => {
|
||||
file.content = file.content.map(({ title, description, ...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),
|
||||
...file
|
||||
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))
|
||||
|
||||
module.exports = files
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue