-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script for adding purls to readme
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | ||
}); |