Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/marketing/blogPlugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, it } from 'vitest'
import { makeBlogAssetUrlsMountSafe } from './blogPlugin'

describe('makeBlogAssetUrlsMountSafe', () => {
it('keeps blog media under the current mount path', () => {
const html = [
'<img src="/blog/example.png">',
'<video><source src="/blog/example.mp4"></video>',
'<a href="/blog/example.mp4">Watch the video</a>',
'<a href="/docs">Read the docs</a>',
].join('')

expect(makeBlogAssetUrlsMountSafe(html)).toBe(
[
'<img src="./example.png">',
'<video><source src="./example.mp4"></video>',
'<a href="./example.mp4">Watch the video</a>',
'<a href="/docs">Read the docs</a>',
].join(''),
)
})
})
8 changes: 7 additions & 1 deletion src/marketing/blogPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ function inlineSvgImages(html: string): string {
})
}

// Blog pages are mounted at /developers/blog in production and /blog in
// previews. Relative media URLs preserve the active mount path in both places.
export function makeBlogAssetUrlsMountSafe(html: string): string {
return html.replace(/(\b(?:src|href)=["'])\/blog\//g, '$1./')
}

const CATEGORY_SLUGS = ['network-upgrades', 'events', 'technical', 'case-studies']

// ALL-CAPS markdown files (AGENTS.md, DIAGRAMS.md, …) are documentation for
Expand Down Expand Up @@ -148,7 +154,7 @@ async function renderPost(filename: string): Promise<SearchablePost> {
)
}

const html = inlineSvgImages(String(await processor.process(content)))
const html = makeBlogAssetUrlsMountSafe(inlineSvgImages(String(await processor.process(content))))

return {
slug,
Expand Down
Loading