1
0
mirror of synced 2025-12-22 03:16:52 -05:00
Files
docs/lib/check-images.js
Vanessa Yuen 3df90fc9b8 Hello git history spelunker!
Are you looking for something? Here is all of the GitHub Docs history in one single commit. Enjoy! 🎉
2020-09-27 14:10:11 +02:00

28 lines
783 B
JavaScript

const fs = require('fs')
const path = require('path')
const rewriteAssetPathsToS3 = require('./rewrite-asset-paths-to-s3')
const { promisify } = require('util')
module.exports = async function checkImages ($, version, relativePath, checkedImageCache = {}) {
rewriteAssetPathsToS3($, version, relativePath)
const brokenImages = []
// this does not check S3 images because those live outside of the repo
const images = $('img[src^="/assets"]').get()
for (const image of images) {
const src = $(image).attr('src')
if (checkedImageCache[src]) continue
try {
await promisify(fs.access)(path.join(__dirname, '..', src))
} catch (e) {
brokenImages.push({ 'broken image reference': src })
}
}
return { brokenImages, checkedImageCache }
}