-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebfinger.ts
53 lines (49 loc) · 1.37 KB
/
webfinger.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Page } from 'lume/core/file.ts'
import { merge } from 'lume/core/utils/object.ts'
import type { Webfinger } from '../../deps/fedikit/webfinger.ts'
export interface Options {
/**
* If false, then output `/.well-known/*` files to `/well-known/*`.
* @defaultValue `true`
*/
dotdir: boolean
/** Generated Webfinger. */
webfinger: Partial<Webfinger>
}
export const defaults = (site: Lume.Site): Options => ({
dotdir: true,
webfinger: {
subject:
`acct:${site.options.location.hostname}@${site.options.location.hostname}`,
aliases: [
new URL('/actor', site.options.location).href,
site.options.location.href,
],
links: [
{
href: site.options.location.href,
rel: 'http://webfinger.net/rel/profile-page',
type: 'text/html',
},
{
href: new URL('/actor', site.options.location).href,
rel: 'self',
type: 'application/activity+json',
},
],
},
})
export default (userOptions?: Partial<Options>) => (site: Lume.Site) => {
const { dotdir, webfinger } = merge(defaults(site), userOptions)
site.addEventListener('beforeRender', (event) =>
event.pages.push(
Page.create({
url: dotdir ? '/.well-known/webfinger' : '/well-known/webfinger',
content: JSON.stringify(
webfinger,
null,
2,
),
}),
))
}