Skip to content

Commit

Permalink
fix: fallback in case of any errors with automd transform
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 9, 2024
1 parent 7ee37d2 commit b36931c
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions app/modules/content/runtime/unstorage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,30 @@ export default (driverOpts) => {
// Automd transform
if (docsConfig.automd) {
if (key.endsWith('.md') && typeof val === 'string') {
if (!automdConfig) {
automdConfig = await loadConfig(docsConfig.dir, docsConfig.automd)
}
const url = pathToFileURL(join(driverOpts.base, key.replace(/:/g, '/')))
const res = await transform(val, automdConfig, url)
if (res.hasChanged && !res.hasIssues) {
_fs.setItem(key, res.contents).catch(console.error)
}
if (res.hasIssues) {
console.warn(
`[undocs] [automd] Issues for updating \`${key}\`:`,
res.updates
.flatMap((u) => u.result.issues)
.map((i) => `\n - ${i}`)
.join('\n'),
)
try {
if (!automdConfig) {
automdConfig = await loadConfig(docsConfig.dir, docsConfig.automd)
}
const url = pathToFileURL(join(driverOpts.base, key.replace(/:/g, '/')))
const res = await transform(val, automdConfig, url)
if (res.hasChanged && !res.hasIssues) {
_fs.setItem(key, res.contents).catch(console.error)
}
if (res.hasIssues) {
console.warn(
`[undocs] [automd] Issues for updating \`${key}\`:`,
res.updates
.flatMap((u) => u.result.issues)
.map((i) => `\n - ${i}`)
.join('\n'),
)
return val // Fallback to original content
}
return res.contents
} catch (error) {
console.error(`[undocs] [automd] Error transforming \`${key}\`:`, error)
return val // Fallback to original content
}
return res.contents
} else if (key.endsWith('.md$')) {
return { mtime: new Date() }
}
Expand Down

0 comments on commit b36931c

Please sign in to comment.