unused-files.js 667 B

1234567891011121314151617181920212223242526
  1. const glob = require('glob');
  2. const fs = require('fs')
  3. const path = require('path')
  4. const srcDir = path.join(__dirname, '../src')
  5. let foundFiles = []
  6. glob.sync(`${srcDir}/pages/**/*.{html,md}`).forEach((file) => {
  7. let fileContent = fs.readFileSync(file)
  8. fileContent.toString().replace(/\{% include(_cached)? "([a-z0-9\/_-]+\.html)"/g, (f, c, filename) => {
  9. filename = `${srcDir}/pages/_includes/${filename}`
  10. if (!foundFiles.includes(filename)) {
  11. foundFiles.push(filename)
  12. }
  13. })
  14. })
  15. let includeFiles = glob.sync(`${srcDir}/pages/_includes/**/*.html`)
  16. includeFiles.forEach((file) => {
  17. if (!foundFiles.includes(file)) {
  18. console.log('file', file)
  19. }
  20. })