1
0
Fork 0
mirror of https://github.com/ipfs/awesome-ipfs.git synced 2024-11-27 11:37:23 -05:00
ipfs/scripts/remove-broken-links.js
Russell Dempsey dd28c19ba7
fix: broken-links workflow (#433)
* fix: broken-links workflow

* fix: trim bash var

* fix: string comparison

* fix: github action if condition syntax

* debugging

* debugging: gh action showing 1 changed file.. what is it?

* fix: only count changed data files for scheduled broken link PRs
2022-09-16 09:28:26 -07:00

30 lines
1 KiB
JavaScript

/**
* This file assumes that awesome_bot has already been ran.
*/
const markdownTable = require('../ab-results-README.md-markdown-table.json')
const fs = require('fs').promises
const { join } = require('path')
const dir = join(__dirname, '../data')
if (markdownTable.error) {
const brokenLinks = require('../ab-results-README.md-filtered.json').map((resultsData) => resultsData.link);
(async () => {
const files = (await fs.readdir(dir)).map(file => join(dir, file))
for await (const filePath of files) {
let fileContents = await fs.readFile(filePath, 'utf8')
brokenLinks.forEach((brokenLink) => {
console.log('Searching for "' + brokenLink + '" in ' + filePath)
const regex = new RegExp(brokenLink, 'g')
if (fileContents.match(regex)) {
fileContents = fileContents.replace(regex, '')
console.log('Removed "' + brokenLink + '" from ' + filePath)
}
})
await fs.writeFile(filePath, fileContents, 'utf8')
}
})()
} else {
console.log('No errors reported by awesome_bot.')
}