summaryrefslogtreecommitdiffstats
path: root/build/build-pages.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-07-22 19:27:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-07-23 08:52:25 +0000
commit78edec0e2d8a3e1216d99234554276cb05505ac4 (patch)
tree6f1a3cfda8731ef3a19f5ae57c928054a0c5624f /build/build-pages.js
parentInitial commit. (diff)
downloadbootstrap-icons-78edec0e2d8a3e1216d99234554276cb05505ac4.tar.xz
bootstrap-icons-78edec0e2d8a3e1216d99234554276cb05505ac4.zip
Adding upstream version 1.9.1+dfsg.upstream/1.9.1+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'build/build-pages.js')
-rw-r--r--build/build-pages.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/build/build-pages.js b/build/build-pages.js
new file mode 100644
index 0000000..911524d
--- /dev/null
+++ b/build/build-pages.js
@@ -0,0 +1,62 @@
+#!/usr/bin/env node
+
+'use strict'
+
+const fs = require('fs').promises
+const path = require('path')
+const picocolors = require('picocolors')
+
+const iconsDir = path.join(__dirname, '../icons/')
+const pagesDir = path.join(__dirname, '../docs/content/icons/')
+
+const VERBOSE = process.argv.includes('--verbose')
+
+function capitalizeFirstLetter(string) {
+ return (string.charAt(0).toUpperCase() + string.slice(1)).split('-').join(' ')
+}
+
+async function main(file) {
+ const iconBasename = path.basename(file, path.extname(file))
+ const iconTitle = capitalizeFirstLetter(iconBasename)
+ const pageName = path.join(pagesDir, `${iconBasename}.md`)
+
+ const pageTemplate = `---
+title: ${iconTitle}
+categories:
+tags:
+---
+`
+
+ try {
+ await fs.access(pageName, fs.F_OK)
+
+ if (VERBOSE) {
+ console.log(`${picocolors.cyan(iconBasename)}: Page already exists; skipping`)
+ }
+ } catch {
+ await fs.writeFile(pageName, pageTemplate)
+ console.log(picocolors.green(`${iconBasename}: Page created`))
+ }
+}
+
+(async () => {
+ try {
+ const basename = path.basename(__filename)
+ const timeLabel = picocolors.cyan(`[${basename}] finished`)
+
+ console.log(picocolors.cyan(`[${basename}] started`))
+ console.time(timeLabel)
+
+ const files = await fs.readdir(iconsDir)
+
+ await Promise.all(files.map(file => main(file)))
+
+ const filesLength = files.length
+
+ console.log(picocolors.green('\nSuccess, %s page%s prepared!'), filesLength, filesLength !== 1 ? 's' : '')
+ console.timeEnd(timeLabel)
+ } catch (error) {
+ console.error(error)
+ process.exit(1)
+ }
+})()