diff --git a/meta/contents.txt b/meta/contents.txt deleted file mode 100644 index 2de652e..0000000 --- a/meta/contents.txt +++ /dev/null @@ -1,84 +0,0 @@ -hello-world -values -variables -inline-assignment -constants -for -if-else -switch -arrays -slices -maps -range -functions -multiple-return-values -varadic-functions -closures -recursion -defer -panic -pointers -new -structs -methods -embedding -interfaces -errors -ok-guards -goroutines -concurrent-goroutines -channels -channel-buffering -channel-directions -synchronization -select -timeouts -scatter-gather -rate-limiting -worker-pools -non-blocking-channel-operations -closing-channels -timers -tickers -state-goroutine -state-mutex -sorting -sorting-by-functions -collection-functions -string-functions -string-formatting -regexs -bytes -json -time -epochs -elapsed-time -random-numbers -number-parsing -urls -sha1-hashes -base64-encoding -reading-files -writing-files -line-filters -command-line-arguments -command-line-flags -environment-variables -spawning-processes -execing-processes -signals -exit -http-client -https-client -redis -postgres -hello-web -responses -request-routing -request-logging -static-content -basic-authentication -canonical-hosts -middleware -graceful-shutdown -https-servers \ No newline at end of file diff --git a/tool/generate.go b/tool/generate.go index b102b14..6f60176 100644 --- a/tool/generate.go +++ b/tool/generate.go @@ -187,7 +187,14 @@ func parseAndRenderSegs(sourcePath string) []*seg { return segs } -func generateIndex() { +func buildChapters() []string { + chapterLines := readLines("meta/chapters.txt") + return filterStrings(chapterLines, func(ch string) bool { + return (ch != "") && !strings.HasPrefix(ch, "#") + }) +} + +func renderIndex(chapterIds []string) { indexF, err := os.Create(siteDir + "/index.html") check(err) fmt.Fprint(indexF, @@ -200,7 +207,7 @@ func generateIndex() {

Contents

`) } -func generateChapters() { - chapterIds := readLines("meta/contents.txt") +func renderChapters(chapterIds []string) { for _, chapterId := range chapterIds { chapterLines := readLines("src/" + chapterId + "/" + chapterId + ".go") chapterName := chapterLines[0][6:] @@ -251,6 +257,7 @@ func generateChapters() { func main() { ensureDir(siteDir) - generateIndex() - generateChapters() + chapters := buildChapters() + renderIndex(chapters) + renderChapters(chapters) }