diff --git a/server/api/v1/openapi.json.head.ts b/server/api/v1/openapi.json.head.ts new file mode 100644 index 00000000..939d6723 --- /dev/null +++ b/server/api/v1/openapi.json.head.ts @@ -0,0 +1 @@ +export { default } from './openapi.json.get' diff --git a/shared/content-negotiation.ts b/shared/content-negotiation.ts index 1a3a533c..bad776ab 100644 --- a/shared/content-negotiation.ts +++ b/shared/content-negotiation.ts @@ -81,7 +81,7 @@ export function decideNegotiation(request: NegotiationRequest): NegotiationDecis const representation = representationFor(accept, request.secFetchDest) if (representation === 'markdown') - return { _tag: 'markdown', location: markdownPath(path) } + return { _tag: 'markdown', location: markdownPath(request.path) } if (representation === 'not-acceptable') return { _tag: 'not-acceptable' } return { _tag: 'html' } @@ -177,8 +177,11 @@ function isPagePath(path: string): boolean { } function markdownPath(path: string): string { - const normalized = path.replace(/\/+$/, '') - return normalized ? `${normalized}.md` : '/index.md' + const index = path.indexOf('?') + const pathname = index === -1 ? path : path.slice(0, index) + const search = index === -1 ? '' : path.slice(index) + const normalized = pathname.replace(/\/+$/, '') + return `${normalized ? `${normalized}.md` : '/index.md'}${search}` } function withoutQuery(path: string): string { diff --git a/test/unit/api-v1-parity.test.ts b/test/unit/api-v1-parity.test.ts index 9fe33ac8..5b489a1e 100644 --- a/test/unit/api-v1-parity.test.ts +++ b/test/unit/api-v1-parity.test.ts @@ -8,7 +8,7 @@ import { describe, expect, it } from 'vitest' */ const OUTSIDE_CONTRACT = [ /^layers\/artifact-delivery\//, - /^server\/api\/v1\/openapi\.json\.get\.ts$/, + /^server\/api\/v1\/openapi\.json\.(?:get|head)\.ts$/, ] const modules = import.meta.glob<{ default: Partial }>([ diff --git a/test/unit/content-negotiation.test.ts b/test/unit/content-negotiation.test.ts index 6f8eeb24..41407018 100644 --- a/test/unit/content-negotiation.test.ts +++ b/test/unit/content-negotiation.test.ts @@ -71,7 +71,6 @@ describe('decideNegotiation: which requests negotiate', () => { describe('decideNegotiation: Markdown location', () => { it.each([ - { path: '/skills/trending?range=week', location: '/skills/trending.md' }, { path: '/', location: '/index.md' }, { path: '/gh/antfu/skills/', location: '/gh/antfu/skills.md' }, ])('$path redirects to $location', ({ path, location }) => {