-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoText.ts
More file actions
50 lines (39 loc) · 1.45 KB
/
toText.ts
File metadata and controls
50 lines (39 loc) · 1.45 KB
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
import { getParentsByTagId, getTagAliases, getTagById, getTags, tagToString } from "./tags"
import type { Tag } from "./tags"
// Some quick settings
const includeTagIdInTagName = true
const includeDisambiguationInTagName = true
const includeDisambiguationSection = true
const includeAliasesSection = true
const includeParentsSection = true
let tagList = ""
await Bun.write( Bun.file( "./tags.md" ), createTagList() )
function createTagList(): string {
const tags = getTags()
for ( const tag of tags ) {
tagList += `${ listTag( tag ) }\n\n`
}
return tagList.trim()
}
function listTag( tag: Tag ): string {
const tagParents = getParentsByTagId( tag.id )
const tagAliases = getTagAliases( tag.id )
let tagStr = `# ${ tagToString( tag, includeTagIdInTagName, includeDisambiguationInTagName ) }`
if ( tag.disambiguation_id && includeDisambiguationSection ) {
const disambiguationTag = getTagById( tag.disambiguation_id )
tagStr += `\n\nDisambiguation: ${ tagToString( disambiguationTag, includeTagIdInTagName, includeDisambiguationInTagName ) }`
}
if ( tagAliases.length > 0 && includeAliasesSection ) {
tagStr += `\n\nAliases:`
for ( const tagAlias of tagAliases ) {
tagStr += `\n- ${ tagAlias }`
}
}
if ( tagParents.length > 0 && includeParentsSection ) {
tagStr += `\n\nParents:`
for ( const tagParent of tagParents ) {
tagStr += `\n- ${ tagToString( tagParent, includeTagIdInTagName, includeDisambiguationInTagName ) }`
}
}
return tagStr
}