diff options
author | Mark Otto <markdotto@gmail.com> | 2020-03-19 00:59:42 +0300 |
---|---|---|
committer | Mark Otto <otto@github.com> | 2020-05-20 19:38:50 +0300 |
commit | c4129f532a584f91949387688d2a72d690b675ad (patch) | |
tree | 8b507b0b59f547ec0829639a872b41c462a7b583 /build | |
parent | db2f004a8b9baebac0c0847fe49fb18c388cae63 (diff) |
Add script to create permalink pages
Diffstat (limited to 'build')
-rw-r--r-- | build/build-pages.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/build/build-pages.js b/build/build-pages.js new file mode 100644 index 000000000..7d55f5864 --- /dev/null +++ b/build/build-pages.js @@ -0,0 +1,51 @@ +#!/usr/bin/env node + +'use strict' + +const fs = require('fs') +const path = require('path') + +const iconsDir = path.join(__dirname, '../icons/') +const pagesDir = path.join(__dirname, '../docs/content/icons/') + +function capitalizeFirstLetter(string) { + return string.charAt(0).toUpperCase() + string.slice(1) +} + +(async ()=>{ + + try { + const files = await fs.promises.readdir(iconsDir) + + for(const file of files) { + + const iconBasename = path.basename(file, path.extname(file)) + const iconTitleCap = capitalizeFirstLetter(iconBasename) + const iconTitle = iconTitleCap.split("-").join(" ") + const pageName = path.join(pagesDir, iconBasename + '.md') + + let pageTemplate = `--- +title: ${iconTitle} +layout: icon +categories: +tags: +---\n` + + fs.access(pageName, fs.F_OK, (err) => { + if (err) { + fs.writeFile(pageName, pageTemplate, function (err) { + if (err) throw err + console.log(iconBasename + " successfully created") + }) + } else { + console.log(iconBasename + " Permalink already exists") + } + }) + + } + } + catch( e ) { + console.error("Error", e) + } + +})() |