Skip to content

Commit

Permalink
add script for adding purls to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
diversen7 committed Nov 19, 2024
1 parent 02a9d52 commit a4cc705
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions bin/update-readme.js
Original file line number Diff line number Diff line change
@@ -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 <!-- Existing PURLs --> section in README.md
const updatedReadme = readmeContent.replace(
/<!-- Existing PURLs -->[\s\S]*<!-- End PURLs -->/,
`<!-- Existing PURLs -->\n${purlsList}\n<!-- End PURLs -->`
);

// Write the updated README.md file
fs.writeFileSync(readmePath, updatedReadme, 'utf8');
console.log('README.md successfully updated.');
});

0 comments on commit a4cc705

Please sign in to comment.