-
Notifications
You must be signed in to change notification settings - Fork 11
/
findTopics.groovy
40 lines (33 loc) · 1.07 KB
/
findTopics.groovy
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
// Copyright (c) 2019-2022 Egon Willighagen <[email protected]>
//
// GPL v3
// find all topics and makes a data file to be converted into an Index
//
// it takes one optional argument, which is appended to the output
import groovy.xml.XmlSlurper
if (args.length == 0) {
println "groovy findTopics.groovy <directory>"
System.exit(0)
}
def folder = args[0]
def topicCounter = 0
def basedir = new File(folder)
files = basedir.listFiles().grep(~/.*i.md$/)
files.each { file ->
topicCounter = 0
context = file.name.substring(0, file.name.indexOf("."))
file.eachLine { line ->
while (line.contains("<topic")) {
topicStart = line.indexOf("<topic")
topicEnd = line.indexOf("</topic>")
topicsXML = line.substring(topicStart, topicEnd+8)
def topicsInstruction = new XmlSlurper().parseText(topicsXML)
topics = topicsInstruction.text()
if (!topics.isEmpty()) {
topicCounter++
println "${topics}\t${context}\ttp${topicCounter}"
}
line = line.substring(0, topicStart) + line.substring(topicEnd+7)
}
}
}