Skip to content

Commit

Permalink
feat: allow defining entries with absolute urls
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Apr 4, 2024
1 parent 95384c5 commit 829ecf6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/collection/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ export class Collection {
dbEntries.forEach((entry) => {
const collectionEntry = new CollectionEntry({
...entry,
permalink: this.#applyPrefix(this.#normalizeUri(entry.permalink)),
permalink: entry.absolute
? this.#normalizeUri(entry.permalink)
: this.#applyPrefix(this.#normalizeUri(entry.permalink)),
})

/**
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type { IncomingMessage, ServerResponse } from 'node:http'
* file.
*/
export type DatabaseEntry = {
absolute?: boolean
permalink: string
contentPath: string
title: string
Expand Down
28 changes: 28 additions & 0 deletions tests/collection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,4 +501,32 @@ test.group('Collection', (group) => {
},
])
})

test('do not prefix absolute URLs', async ({ assert, fs }) => {
await fs.create(
'db.json',
JSON.stringify([
{
absolute: true,
permalink: '/hello',
contentPath: 'home.md',
title: 'Hello world',
},
{
permalink: '/hi',
contentPath: 'hi.md',
title: 'Hi world',
},
])
)

const collection = Collection.create()
collection.db(new URL('db.json', fs.baseUrl)).urlPrefix('/docs')
await collection.boot()

assert.deepEqual(
collection.all().map((entry) => entry.permalink),
['/hello', '/docs/hi']
)
})
})

0 comments on commit 829ecf6

Please sign in to comment.