selfdefined/_util/create-empty-definitions.js
Manny Becerra 56abe606a8
✏️ Updates "defintion" to "definition" in CONTRIBUTING docs and create-empty-definitions util (#285)
Co-authored-by: Manny Becerra <mannybecerra@users.noreply.github.com>
2020-08-29 14:14:44 -07:00

42 lines
850 B
JavaScript

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 definitionPath = 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(`${definitionPath}/${slug}.md`, content, 'utf8');
} catch (e) {
console.error(e);
process.exit(1);
}
return true;
});
}