-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ptd.ts
65 lines (63 loc) 路 1.59 KB
/
ptd.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
54
55
56
57
58
59
60
61
62
63
64
65
import type { FFFFlavoredFrontmatter } from '../types.ts'
/**
* Supported Post Type
* @beta
* @see {@link https://ptd.spec.indieweb.org/#algorithm}
* @see {@link https://indieweb.org/posts#Types_of_Posts}
*/
export type PostType = 'article' | 'audio' | 'bookmark' | 'event' | 'like' | 'note' | 'photo' | 'reply' | 'repost' | 'rsvp' | 'video'
/**
* Post Type Discovery
* @beta
* @param fm - FFF Flavored Frontmatter
* @returns lower case post type
* @see {@link https://ptd.spec.indieweb.org/#algorithm}
* @see {@link https://indieweb.org/posts#Types_of_Posts}
* @example
* ```ts
* import { postTypeDiscovery } from 'fff-flavored-frontmatter'
*
* const helloWorld = {
* title: 'Hello',
* summary: 'World!',
* }
*
* const fooBar = {
* summary: 'foo',
* tags: ['bar'],
* }
*
* // 'article'
* console.log(postTypeDiscovery(helloWorld))
* // 'note'
* console.log(postTypeDiscovery(fooBar))
* ```
*/
export const postTypeDiscovery = (fm: FFFFlavoredFrontmatter): PostType => {
// TODO: Checkin, Reply with RSVP
/** may be modified in the future */
if (fm.flags?.includes('event'))
return 'event'
else if (
fm.rsvp
&& ['interested', 'maybe', 'no', 'yes'].includes(fm.rsvp.toLowerCase())
)
return 'rsvp'
else if (fm.repost_of)
return 'repost'
else if (fm.like_of)
return 'like'
else if (fm.bookmark_of)
return 'bookmark'
else if (fm.in_reply_to)
return 'reply'
else if (fm.video)
return 'video'
else if (fm.audio)
return 'audio'
else if (fm.title)
return 'article'
else if (fm.images)
return 'photo'
else return 'note'
}