Skip to content

Commit

Permalink
fix(purgecss): try to find the configuration file in subdirectories
Browse files Browse the repository at this point in the history
Fixes #106
  • Loading branch information
razonyang committed Nov 1, 2023
1 parent c599450 commit a343216
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion purgecss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,27 @@ fs.access(stats, fs.F_OK, (err) => {

let config = {};
try {
let rawConfig = fs.readFileSync(path.join(process.env.HUGO_PUBLISHDIR, '.build/purgecss.json'))
let filename = path.join(process.env.HUGO_PUBLISHDIR, ".build", "purgecss.json")
let found = true
if (!fs.existsSync(filename)) {
found = false
const files = fs.readdirSync(process.env.HUGO_PUBLISHDIR)
for (file of files) {
const fp = path.join(process.env.HUGO_PUBLISHDIR, file)
const stats = fs.statSync(fp)
if (stats.isDirectory()) {
filename = path.join(fp, ".build", "purgecss.json")
if (fs.existsSync(filename)) {
found = true
break
}
}
}
}
if (found === false) {
throw new Error('No PurgeCSS configuration found.')
}
let rawConfig = fs.readFileSync(filename)
config = JSON.parse(rawConfig)
} catch (err) {
throw new Error(`Failed to parse runtime PurgeCSS config.\nPlease enable the "--renderToDisk" if you are using Hugo server.\n${err}`)
Expand Down

0 comments on commit a343216

Please sign in to comment.