forked from docToolchain/aoc-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
327 lines (287 loc) · 11.1 KB
/
build.gradle
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
import groovy.json.*
buildscript {
dependencies {
classpath 'org.asciidoctor:asciidoctorj-diagram:1.5.4.1'
}
}
//tag::jbakeplugin[]
plugins {
id 'org.jbake.site' version '5.0.0'
}
//end::jbakeplugin[]
repositories {
mavenCentral()
jcenter()
}
//tag::jbakeconfig[]
jbake {
version = '2.6.4'
srcDirName = 'src/site'
destDirName = 'docs/html5/site'
configuration['asciidoctor.option.requires'] = "asciidoctor-diagram"
}
//end::jbakeconfig[]
//configure docToolchain to use the main project's config
project('docToolchain') {
if (project.hasProperty('docDir')) {
docDir = '../.'
inputPath = 'docs'
mainConfigFile = 'docToolchain.config'
} else {
println "="*80
println " please initialize the docToolchain submodule"
println " by executing git submodule update -i"
println "="*80
}
}
task generateIndex() {
// this is ugly as obfuscated, but it works :-)
doLast {
def src = new File('.')
def stats = [coders:0,languages:0,stars:[:],days:[],lang:[:]]
// build up an index of all code
def days = [:]
def languages = [:]
def coders = [:]
src.eachFile { day ->
if (day.name.startsWith('day')) {
days[day.name]=[]
day.eachFile { language ->
if (!language.isFile()) {
language.eachFile { coder ->
if (!coder.isFile()) {
if (!coders[coder.name]) {
coders[coder.name]=[]
}
coders[coder.name] << ([day.name,language.name])
days[day.name] << ([coder.name, language.name])
if (!languages[language.name]) {
languages[language.name]=[]
}
languages[language.name] << ([coder.name, day.name])
if (!stats.lang[language.name]) {
stats.lang[language.name]=[:]
}
if (!stats.lang[language.name][day.name]) {
stats.lang[language.name][day.name]=[]
}
stats.lang[language.name][day.name]<<coder.name
}
}
}
}
}
}
days.sort({k1, k2 -> k1.substring(3).toInteger() <=> k2.substring(3).toInteger()} as Comparator)
new File(projectDir, "build/.").mkdirs()
new File(projectDir, 'src/site/content/generated/.').mkdirs()
def coderIndex = ""
stats.coders = coders.size()
coders.sort{it.key.toLowerCase()}.each { coder, data ->
// * anoff
def daysFile = new File(projectDir, "src/site/content/generated/coder/${coder}/generatedDays.adoc")
new File(projectDir, "src/site/content/generated/coder/${coder}").mkdirs()
daysFile.write("""
:jbake-type: page_toc
:jbake-title: $coder
:jbake-status: published
:toc: left
include::../../../config.adoc[]
== $coder
include::../../../../../../profiles/${coder}.adoc[]
""")
coderIndex += "* link:../generated/coder/$coder/generatedDays.html[$coder]\n\n"
data.sort{it[0]}.each { datum ->
//=== Day 1
//
//include::../../day01/python/rdmueller/README.adoc[leveloffset=+2]
def link = "${datum[0]}/${datum[1]}/${coder}/README.adoc"
File readme = new File(link)
def currentFolder = new File("${datum[0]}/${datum[1]}/${coder}/.")
if (!readme.exists()) {
def text ="""
[small]#this documentation is autogenerated. Add a `README.adoc` to your solution to take over the control of this :-)#
== ${datum[1]}
"""
currentFolder.eachFile { File file ->
text += """
.${file.canonicalPath-(currentFolder.canonicalPath+'/')}
[source]
....
include::${file.canonicalPath-(currentFolder.canonicalPath+'/')}[]
....
"""
}
readme.write(text)
}
if (readme.exists()) {
daysFile.append("""
++++
<a id="${datum[0]}" />
++++
""")
daysFile.append("=== Day ${datum[0]-"day"}: ${datum[1]}\n\n")
daysFile.append("include::../../../../../../${datum[0]}/${datum[1]}/${coder}/README.adoc[leveloffset=+2]\n\n")
}
}
}
new File(projectDir, 'src/site/content/generated/byCoder.adoc').write(coderIndex)
def dayIndex = ""
days.sort{it.key}.each { day, data ->
def dayNum = (day - "day").replaceAll("^0", "")
stats.days << dayNum
dayIndex += """
=== Day ${day-"day"}
"""
if (day!="day00") {
dayIndex += """
The riddle for day ${day - "day"} can be found at https://adventofcode.com/2021/day/${(day - "day").replaceAll("^0", "")}.
"""
}
dayIndex += """
[cols="2"]
|===
"""
def lastCoder = ""
data.sort{it[0].toLowerCase()}.eachWithIndex { datum, i ->
def coder = datum[0]
def language = datum[1].replaceAll("[+]","p")
dayIndex += """\
| ${lastCoder==coder?"":coder} | link:/generated/coder/${coder}/generatedDays.html#_day_${day-"day"}_${language}[$language]
"""
dayNum = (day - "day").replaceAll("^0", "")
if (lastCoder!=coder) {
if (!stats.stars[coder]) {
stats.stars[coder] = [:]
}
stats.stars[coder][dayNum]=1
}
lastCoder = coder
}
dayIndex += "|===\n"
}
new File('src/site/content/generated/byDay.adoc').write(dayIndex)
def langIndex = ""
stats.languages = languages.size()
languages.sort{it.key.toLowerCase()}each { language, data ->
langIndex += """
=== ${language}
[cols="2"]
|===
"""
def lastDay = ""
data.sort{it[1]}.eachWithIndex { datum, i ->
def coder = datum[0]
def day = datum[1]
langIndex += """\
| ${lastDay==day?"":"Day "+(day-"day")} | link:/generated/coder/${coder}/generatedDays.html#_day_${day-"day"}_${language}[$coder]
"""
lastDay = day
}
langIndex += "|===\n"
}
new File('src/site/content/generated/byLanguage.adoc').write(langIndex)
def statsFile = """
= Stats and Leaderboard
Here are some stats for those who are interested.
The repository contains solutions in ${stats.languages} languages by ${stats.coders} developers.
include::../../../../profiles/allUsers.adoc[]
[cols="${stats.days.size()+3}"]
|===
2+^.>| ${stats.days.size()}+^| Day .2+^.>| Sum
2+^.>| Developer ^| ${stats.days.collect{"$it"}.join(' ^| ')}
"""
def emojis=['👋','🕯','🎄','🎶','❄','🔔','🧦','☃','🕯🕯','🎁','🎄','🔔','☃','❄','⛪','🕯🕯🕯','🦌','🧝','🤶','🎄','☃','❄','🕯🕯🕯🕯','🎶','🎅','👪👼🦌']
stats.stars.sort{e1, e2 -> e2.value.size() <=> e1.value.size()}.each{ coder, stars ->
statsFile += "a| image::{${coder}-avatar}[width=32px] a| link:/generated/coder/${coder}/generatedDays.html[$coder] "
def dayList = stats.days.collect {
def entry = '-'
if (stars[it]) {
def emojiOfTheDay = emojis[it as Integer]
def currentDayAnchor = it.toString().padLeft(2, '0')
entry = "link:/generated/coder/${coder}/generatedDays.html#day${currentDayAnchor}[${emojiOfTheDay}]"
}
return entry
}.join(' ^| ')
statsFile += "^| ${dayList} "
statsFile += "^| ${stars.size()}\n"
}
statsFile += """
|===
"""
new File('src/site/content/generated/stats.adoc').write(statsFile, 'utf-8')
// Solutions by Language as stats
def statsFile2 = """
include::../../../../profiles/allUsers.adoc[]
[cols="${stats.days.size()+3}"]
|===
.2+^.>| Language ${stats.days.size()}+^| Day .2+^.>| #Days .2+^.>| #Sol
^| ${stats.days.collect{"$it"}.join(' ^| ')}
"""
println stats
stats.lang.sort{e1, e2 -> e2.value.size() <=> e1.value.size()}.each{ currentLanguage ->
statsFile2 += "a| ${currentLanguage.key} "
def langCoders = 0
def langDays = 0
def codersForLang = currentLanguage.value
def dayList = stats.days.collect { currentDay ->
def entry = '-'
def currentDayAnchor = "day"+currentDay.toString().padLeft(2, '0')
if (codersForLang[currentDayAnchor]) {
langDays ++
entry = codersForLang[currentDayAnchor].collect { coder ->
langCoders ++
"image:{${coder}-avatar}[width=32,link=/generated/coder/${coder}/generatedDays.html#_day_${currentDay.padLeft(2,'0')}_${currentLanguage.key}]"
}.join(" ")
}
return entry
}.join(' ^| ')
statsFile2 += "^| ${dayList} "
statsFile2 += "^| ${langDays} ^| ${langCoders}\n"
}
statsFile2 += """
|===
"""
new File('src/site/content/generated/stats2.adoc').write(statsFile2, 'utf-8')
// End Solutions by Language
def userInfo = ""
def allUsers = ""
stats.stars.each {coder, stars->
File coderProfile = new File("./profiles/${coder}.adoc")
allUsers += "include::${coder}.adoc[tags=!free-form]\n"
if (!coderProfile.exists()) {
def api = "https://api.github.com/users/"
def res = []
try {
res = new JsonSlurper().parseText(new URL(api + coder).text)
} catch (Exception e) {
println "couldn't read $coder : $e"
}
coderProfile.write("""
:${coder}-avatar: ${res['avatar_url']}
:${coder}-twitter: -
:${coder}-realName: ${res['name']}
:${coder}-blog: -
//tag::free-form[]
[cols="1,5"]
|===
| image:{${coder}-avatar}[]
a| **$coder** +
//{${coder}-realName} +
icon:github[]: ${res['html_url']}[${coder}]
ifeval::[{${coder}-twitter} != -]
icon:twitter[] : https://twitter.com/{${coder}-twitter}[${coder}-twitter] +
endif::[]
ifeval::[{${coder}-blog} != -]
Blog : {${coder}-blog}
endif::[]
|===
=== About me
Nothing here yet. Update your profile at https://github.com/docToolchain/aoc-2021/blob/master/profiles/${coder}.adoc[/profiles/${coder}.adoc]
//end::free-form[]
""")
}
}
new File("./profiles/allUsers.adoc").write(allUsers)
}
}