From a4cc7054800018b7e63ba73fe7a891f932c947da Mon Sep 17 00:00:00 2001 From: Dennis Iversen Date: Tue, 19 Nov 2024 09:52:10 +0100 Subject: [PATCH] add script for adding purls to readme --- bin/update-readme.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 bin/update-readme.js diff --git a/bin/update-readme.js b/bin/update-readme.js new file mode 100644 index 0000000..0a10229 --- /dev/null +++ b/bin/update-readme.js @@ -0,0 +1,44 @@ +const fs = require('fs'); +const path = require('path'); +const csv = require('csv-parser'); + +// File paths +const readmePath = path.join('README.md'); +const csvPath = path.join('bin', 'redirects.csv'); + +// Read the README.md file +let readmeContent = fs.readFileSync(readmePath, 'utf8'); + +// Placeholder for PURLs +const purls = []; + +// Read and parse the CSV file +fs.createReadStream(csvPath) + .pipe(csv()) + .on('data', (row) => { + if (row.File && row.URL) { + const purlLink = `[https://purl.aarhusstadsarkiv.dk/${row.File}](https://purl.aarhusstadsarkiv.dk/${row.File})` + const realURL = `[${row.URL}](${row.URL})` + purls.push(`* ${purlLink} -> `); + purls.push(`${realURL}`); + + } + }) + .on('end', () => { + console.log('CSV file successfully processed.'); + + // Generate the new PURLs list + const purlsList = purls.join('\n'); + + console.log(purlsList); + + // Replace the section in README.md + const updatedReadme = readmeContent.replace( + /[\s\S]*/, + `\n${purlsList}\n` + ); + + // Write the updated README.md file + fs.writeFileSync(readmePath, updatedReadme, 'utf8'); + console.log('README.md successfully updated.'); + });