Update: remove trailing slashes in URLs

This commit is contained in:
Arthur McLain
2025-01-29 15:12:19 +01:00
parent b146b0b539
commit a9e509a4b3
3 changed files with 376 additions and 375 deletions

View File

@@ -8,7 +8,7 @@ function create(file, fileName, emoji) {
let result = [];
let lineCount = 0;
const lines = data.split('\n');
const outputDir = './filter';
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
@@ -50,17 +50,18 @@ function format(file = "README.md") {
const updatedData = data
.split('\n')
.map(line => {
line = line.replace(/https:\/\/www\./g, 'https://');
if (line.startsWith('- [')) {
const parts = line.split(' - ');
if (parts.length >= 2) {
let description = parts[1];
description = description.replace(/^A\s+/i, '').replace(/^An\s+/i, '');
description = description.charAt(0).toUpperCase() + description.slice(1);
parts[1] = description;
line = parts.join(' - ');
}
}
// line = line.replace(/https:\/\/www\./g, 'https://'); // removes www.
line = line.replace(/\((https?:\/\/.*?)\/\)/g, "($1)"); // removes trailing /
// if (line.startsWith('- [')) {
// const parts = line.split(' - ');
// if (parts.length >= 2) {
// let description = parts[1];
// description = description.replace(/^A\s+/i, '').replace(/^An\s+/i, '');
// description = description.charAt(0).toUpperCase() + description.slice(1);
// parts[1] = description;
// line = parts.join(' - ');
// }
// }
return line;
})
.join('\n');
@@ -141,7 +142,7 @@ function findAF(file, name, message, suffix) {
const endMarker = `<!-- AF-END -->`.trim();
const startIndex = data.indexOf(startMarker);
if (startIndex !== -1) {
const cleanStartIndex = data.indexOf(">", startIndex) + 1;
@@ -207,4 +208,4 @@ if (args.includes('--analyze')) {
console.log(" node index.js --analyze Print some info about README.md");
console.log(" node index.js --toc Update the table of contents");
console.log(" node index.js --all Run all the commands (format, categorize, links)");
}
}