-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgendocs.js
53 lines (48 loc) · 1.58 KB
/
gendocs.js
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
const { readFileSync, writeFileSync } = require('fs')
const getName = (filter) =>
filter == 'yt-neuter'
? filter
: `yt-neuter ${filter.replace('filter/', '')}`
function generateInstallLink(filter) {
filter = filter.replace('filters/', 'filter/')
const listURL = `https://neuter.mchang.xyz/${filter}`
const installURL = `https://subscribe.adblockplus.org/?location=${encodeURIComponent(listURL)}&title=${encodeURIComponent(getName(filter))}`
return `# Install\n\n[Subscribe](${installURL}) | [View List](${listURL})\n`
}
function syncReadFile(filter) {
const filename = `./${filter}.txt`
const contents = readFileSync(filename, 'utf-8')
const arr = contents.split(/\r?\n/)
// remove header
arr.shift()
while (arr[0].startsWith('!') && arr[0] !== '') arr.shift()
const commentLines = arr.filter(line => line.startsWith('!'))
// format comments into markdown
const comments = commentLines.map(line => line
.replace(/\#(\d+)/, '[#$1](https://github.com/mchangrh/yt-neuter/issues/$1)')
.replace(/\! install link/, generateInstallLink(filter))
.replace(/\!\!\!\!/, '##')
.replace(/\!\!\!/, '###')
.replace(/\!\!/, '*')
.replace(/\!/, ' *')
)
return comments.join('\n')
}
const filters = [
"yt-neuter",
"filters/hyper",
"filters/misc",
"filters/nolive",
"filters/nomusic",
"filters/noshorts",
"filters/notrack",
"filters/noview",
"filters/premium",
"filters/requests",
"filters/sponsorblock",
"filters/ytkids"
]
for (const filter of filters) {
const result = syncReadFile(filter)
writeFileSync(`./docs/${filter}.md`, result)
}