diff --git a/src/contents.txt b/meta/contents.txt
similarity index 97%
rename from src/contents.txt
rename to meta/contents.txt
index 617ba3a..2de652e 100644
--- a/src/contents.txt
+++ b/meta/contents.txt
@@ -1,4 +1,3 @@
-introduction
hello-world
values
variables
diff --git a/src/introduction.md b/meta/introduction.md
similarity index 100%
rename from src/introduction.md
rename to meta/introduction.md
diff --git a/src/title.md b/src/title.md
deleted file mode 100644
index f7b5481..0000000
--- a/src/title.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Go by Example
-
-### Mark McGranaghan
diff --git a/src/style.css b/style/site.css
similarity index 100%
rename from src/style.css
rename to style/site.css
diff --git a/tool/generate.go b/tool/generate.go
index 6f7c60f..9b76fbb 100644
--- a/tool/generate.go
+++ b/tool/generate.go
@@ -14,6 +14,7 @@ import (
)
var cacheDir = "/tmp/gobyexample-cache"
+var siteDir = "site"
func check(err error) {
if err != nil {
@@ -31,6 +32,11 @@ func filterStrings(vs []string, f func(string) bool) []string {
return vsf
}
+func ensureDir(dir string) {
+ err := os.MkdirAll(dir, 0700)
+ check(err)
+}
+
func pipe(bin string, arg []string, src string) []byte {
cmd := exec.Command(bin, arg...)
in, _ := cmd.StdinPipe()
@@ -58,6 +64,7 @@ func mustReadFile(path string) string {
}
func cachedPygmentize(lex string, src string) string {
+ ensureDir(cacheDir)
arg := []string{"-l", lex, "-f", "html"}
bin := "/usr/local/bin/pygmentize"
cachePath := cacheDir + "/pygmentize-" + strings.Join(arg, "-") + "-" + sha1Sum(src)
@@ -71,11 +78,6 @@ func cachedPygmentize(lex string, src string) string {
return string(renderBytes)
}
-func ensureCache() {
- mkdirErr := os.MkdirAll(cacheDir, 0700)
- check(mkdirErr)
-}
-
func markdown(src string) string {
return string(blackfriday.MarkdownCommon([]byte(src)))
}
@@ -185,78 +187,66 @@ func parseAndRenderSegs(sourcePath string) []*seg {
return segs
}
-func main() {
- if len(os.Args) != 2 {
- panic("Wrong number of args")
- }
- outF, err := os.Create(os.Args[1])
+func generateIndex() {
+ indexF, err := os.Create(siteDir + "/index.html")
check(err)
- ensureCache()
-
- // Header
- fmt.Fprint(outF,
+ fmt.Fprint(indexF,
`
-
-
-
- Go by Example
-
-
- `)
-
- // Title page
- fmt.Fprintf(outF,
- `%s
`,
- markdown(mustReadFile("src/title.md")))
-
- // Contents page
- chapterIds := readLines("src/contents.txt")
- fmt.Fprint(outF, `Contents
`)
+
+
+
+ Go by Example
+
+
+
+ Contents
`)
+ chapterIds := readLines("meta/contents.txt")
for _, chapterId := range chapterIds {
- var chapterName string
- if chapterId == "introduction" {
- chapterName = "Introduction"
- } else {
- chapterLines := readLines("src/" + chapterId + "/" + chapterId + ".go")
- chapterName = chapterLines[0][6:]
- }
- fmt.Fprintf(outF, `- %s
`, chapterId, chapterName)
+ chapterLines := readLines("src/" + chapterId + "/" + chapterId + ".go")
+ chapterName := chapterLines[0][6:]
+ fmt.Fprintf(indexF, `- %s
`, chapterId, chapterName)
}
- fmt.Fprint(outF, `
`)
-
- // Content chapters
- for _, chapterId := range chapterIds {
- fmt.Fprintf(outF, ``, chapterId)
- if chapterId == "introduction" {
- fmt.Fprint(outF, markdown(mustReadFile("src/introduction.md")))
- } else {
- chapterPath := "src/" + chapterId
- fmt.Fprintf(outF,
- `
`,
- chapterPath)
- sourcePaths := mustGlob(chapterPath + "/*")
- for _, sourcePath := range sourcePaths {
- if strings.HasSuffix(sourcePath, ".go") || strings.HasSuffix(sourcePath, ".sh") {
- segs := parseAndRenderSegs(sourcePath)
- for _, seg := range segs {
- codeClasses := "code"
- if seg.code == "" {
- codeClasses = codeClasses + " empty"
- }
- fmt.Fprintf(outF,
- `
- %s |
- %s |
-
`,
- seg.docsRendered, codeClasses, seg.codeRendered)
- }
- }
- }
- fmt.Fprint(outF, `
`)
- }
- fmt.Fprintf(outF, `
`)
- }
-
- // Footer
- fmt.Fprint(outF, ``)
+ fmt.Fprint(indexF, `
`)
}
+
+func main() {
+ ensureDir(siteDir)
+ generateIndex()
+}
+
+//
+// // Content chapters
+// for _, chapterId := range chapterIds {
+// fmt.Fprintf(outF, ``, chapterId)
+// if chapterId == "introduction" {
+// fmt.Fprint(outF, markdown(mustReadFile("src/introduction.md")))
+// } else {
+// chapterPath := "src/" + chapterId
+// fmt.Fprintf(outF,
+// `
`,
+// chapterPath)
+// sourcePaths := mustGlob(chapterPath + "/*")
+// for _, sourcePath := range sourcePaths {
+// if strings.HasSuffix(sourcePath, ".go") || strings.HasSuffix(sourcePath, ".sh") {
+// segs := parseAndRenderSegs(sourcePath)
+// for _, seg := range segs {
+// codeClasses := "code"
+// if seg.code == "" {
+// codeClasses = codeClasses + " empty"
+// }
+// fmt.Fprintf(outF,
+// `
+// %s |
+// %s |
+//
`,
+// seg.docsRendered, codeClasses, seg.codeRendered)
+// }
+// }
+// }
+// fmt.Fprint(outF, `
`)
+// }
+// fmt.Fprintf(outF, `
`)
+// }
+//
+// // Footer
+// fmt.Fprint(outF, `