mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-09-16 12:39:05 +00:00
feat(definitions): helper script to create defs from data list
This commit is contained in:
36
_temp/create-empty-definitions.js
Normal file
36
_temp/create-empty-definitions.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import slugify from 'slugify'
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import { promisify } from 'util'
|
||||
|
||||
const writeFile = promisify(fs.writeFile)
|
||||
|
||||
import { words } from './undefined-words'
|
||||
const defintionPath = path.resolve(process.cwd(), '11ty/definitions/')
|
||||
|
||||
const template = `
|
||||
---
|
||||
title: {{title}}
|
||||
slug: {{slug}}
|
||||
defined: false
|
||||
---
|
||||
`
|
||||
|
||||
export function createDefinitions() {
|
||||
return words.forEach(async (word) => {
|
||||
const title = word
|
||||
const slug = slugify(word.toLowerCase().replace(/ \([a-z]+\)| ([a-z-]+) slur/i, ''))
|
||||
|
||||
const content = template.replace('{{title}}', title).replace('{{slug}}', slug).trim()
|
||||
|
||||
try {
|
||||
await writeFile(`${defintionPath}/${slug}.md`, content, 'utf8')
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user