Skip to content

Commit

Permalink
Handle 404s on images and internal links
Browse files Browse the repository at this point in the history
  • Loading branch information
amozoss committed Sep 29, 2023
1 parent 0c1736d commit 2de602f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/markdoc/convertDocId.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@ function getFrontmatter(filePath) {
}

export function convertDocId(href) {
if (href?.includes('docs.storj.io')) {
const siteHost = new URL(process.env.SITE_URL).host
if (href?.includes(siteHost)) {
const url = new URL(href)
let dir = path.resolve('./app')
const filePath = path.join(dir, url.pathname, 'page.md')
if (
process.env.NODE_ENV !== 'production' ||
(url.host === new URL(process.env.SITE_URL).host && existsSync(filePath))
) {
if (existsSync(filePath)) {
let { docId } = getFrontmatter(filePath)
throw new Error(
`Internal links should use the docId. replace ${href} with docId:${docId}`
)
}
throw new Error(`Could not find document for ${href}`)
}

if (!href?.startsWith('docId')) {
Expand Down
6 changes: 5 additions & 1 deletion src/markdoc/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ const nodes = {
let result = imageSizeCache[hash]
if (!result) {
console.warn(`image size not cached, probing... ${attributes.src}`)
result = await probe(attributes.src)
try {
result = await probe(attributes.src)
} catch (err) {
throw new Error(`${err}\nOccurred on ${attributes.src}`)
}
}

return new Tag(
Expand Down

0 comments on commit 2de602f

Please sign in to comment.