Skip to content

Commit

Permalink
Update scripts to consistent indentation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
reatlat committed Apr 13, 2024
1 parent d722ab7 commit 337bddf
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 82 deletions.
158 changes: 79 additions & 79 deletions scripts/edit-post.mjs
Expand Up @@ -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";
Expand All @@ -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);
});
});
});
4 changes: 2 additions & 2 deletions scripts/generate-og-images.mjs
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/new-post.mjs
Expand Up @@ -39,7 +39,7 @@ draft: true
---
This is a draft post
`
`,
);

console.log(chalk.green(`Created ${filepath}`));
Expand Down

0 comments on commit 337bddf

Please sign in to comment.