From 337bddfe1d11fb7ffab0a5581c25cdf193cb1961 Mon Sep 17 00:00:00 2001 From: Alex Zappa Date: Sun, 14 Apr 2024 00:10:26 +0200 Subject: [PATCH] Update scripts to consistent indentation The main changes in these scripts are indentation adjustments, from tab-based to space-based, to maintain code consistency. The inclusion of commas at the end of certain script parts, in the new-post.mjs and generate-og-images.mjs files, makes the code follow modern JavaScript standards more closely. --- scripts/edit-post.mjs | 158 ++++++++++++++++----------------- scripts/generate-og-images.mjs | 4 +- scripts/new-post.mjs | 2 +- 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/scripts/edit-post.mjs b/scripts/edit-post.mjs index 7bd8127..27e817f 100644 --- a/scripts/edit-post.mjs +++ b/scripts/edit-post.mjs @@ -2,11 +2,11 @@ // Path: scripts/edit-post.mjs import { - readdirSync, - readFileSync, - writeFileSync, - unlinkSync, - mkdirSync, + readdirSync, + readFileSync, + writeFileSync, + unlinkSync, + mkdirSync, } from "fs"; import path from "path"; import inquirer from "inquirer"; @@ -16,84 +16,84 @@ import slugify from "slugify"; // Ask the post name to edit from the list of posts inquirer - .prompt([ - { - type: "list", - name: "year", - message: "Which year do you want to edit?", - choices: readdirSync("./src/content/blog", { withFileTypes: true }) - .filter((dirent) => dirent.isDirectory()) - .map((dirent) => dirent.name), - }, - ]) - .then((answers) => { - const yearSelected = answers.year; + .prompt([ + { + type: "list", + name: "year", + message: "Which year do you want to edit?", + choices: readdirSync("./src/content/blog", { withFileTypes: true }) + .filter((dirent) => dirent.isDirectory()) + .map((dirent) => dirent.name), + }, + ]) + .then((answers) => { + const yearSelected = answers.year; - inquirer - .prompt([ - { - type: "list", - name: "post", - message: "Which post do you want to edit?", - choices: readdirSync(`./src/content/blog/${yearSelected}`, { - withFileTypes: true, - }) - .filter((dirent) => dirent.isDirectory()) - .map((dirent) => dirent.name), - }, - ]) - .then((answers) => { - const postSelected = answers.post; - const currentFilepath = `./src/content/blog/${yearSelected}/${postSelected}/index.md`; + inquirer + .prompt([ + { + type: "list", + name: "post", + message: "Which post do you want to edit?", + choices: readdirSync(`./src/content/blog/${yearSelected}`, { + withFileTypes: true, + }) + .filter((dirent) => dirent.isDirectory()) + .map((dirent) => dirent.name), + }, + ]) + .then((answers) => { + const postSelected = answers.post; + const currentFilepath = `./src/content/blog/${yearSelected}/${postSelected}/index.md`; - inquirer - .prompt([ - { - type: "input", - name: "title", - message: "What is the new title for the post?", - }, - { - type: "input", - name: "date", - message: "What is the new date for the post? (yyyy-LL-dd)", - }, - ]) - .then((answers) => { - const newTitle = answers.title; - const newSlug = slugify(newTitle, { - remove: /[_*+~.()'"!:@]/g, - strict: true, - lower: true, - }); - const newDate = answers.date; - const newYear = newDate.split("-")[0]; - const newFilepath = `./src/content/blog/${newYear}/${newSlug}/index.md`; + inquirer + .prompt([ + { + type: "input", + name: "title", + message: "What is the new title for the post?", + }, + { + type: "input", + name: "date", + message: "What is the new date for the post? (yyyy-LL-dd)", + }, + ]) + .then((answers) => { + const newTitle = answers.title; + const newSlug = slugify(newTitle, { + remove: /[_*+~.()'"!:@]/g, + strict: true, + lower: true, + }); + const newDate = answers.date; + const newYear = newDate.split("-")[0]; + const newFilepath = `./src/content/blog/${newYear}/${newSlug}/index.md`; - const content = readFileSync(currentFilepath, "utf8"); - const lines = content.split("\n"); - const title = lines[1].replace("title: ", ""); - const slug = slugify(title, { - remove: /[_*+~.()'"!:@]/g, - strict: true, - lower: true, - }); - const date = lines[2].replace("date: ", ""); + const content = readFileSync(currentFilepath, "utf8"); + const lines = content.split("\n"); + const title = lines[1].replace("title: ", ""); + const slug = slugify(title, { + remove: /[_*+~.()'"!:@]/g, + strict: true, + lower: true, + }); + const date = lines[2].replace("date: ", ""); - const newContent = content - .replace(title, newTitle) - .replace(slug, newSlug) - .replace(date, newDate); + const newContent = content + .replace(title, newTitle) + .replace(slug, newSlug) + .replace(date, newDate); - mkdirSync(path.dirname(newFilepath), { - recursive: true, - }); - writeFileSync(newFilepath, newContent); + mkdirSync(path.dirname(newFilepath), { + recursive: true, + }); + writeFileSync(newFilepath, newContent); - console.log(chalk.green(`Edited ${newFilepath}`)); + console.log(chalk.green(`Edited ${newFilepath}`)); - // remove old file - unlinkSync(currentFilepath); - }); - }); - }); + // remove old file + unlinkSync(currentFilepath); + }); + }); + }); diff --git a/scripts/generate-og-images.mjs b/scripts/generate-og-images.mjs index 4078079..7f30b6b 100644 --- a/scripts/generate-og-images.mjs +++ b/scripts/generate-og-images.mjs @@ -6,8 +6,8 @@ import chalk from "chalk"; if (!fs.existsSync("./_temp/titles-for-og-images.txt")) { console.log( chalk.red( - "File ./_temp/titles-for-og-images.txt does not exist. Please run `npm run build` first." - ) + "File ./_temp/titles-for-og-images.txt does not exist. Please run `npm run build` first.", + ), ); process.exit(1); } diff --git a/scripts/new-post.mjs b/scripts/new-post.mjs index 9774f79..b75f59f 100644 --- a/scripts/new-post.mjs +++ b/scripts/new-post.mjs @@ -39,7 +39,7 @@ draft: true --- This is a draft post -` +`, ); console.log(chalk.green(`Created ${filepath}`));