A generate.go => generate.go +38 -0
@@ 0,0 1,38 @@
+package main
+
+import (
+ "html/template"
+ "os"
+ "strconv"
+ "time"
+)
+
+
+// generate takes a page in the format `{page}.html` and creates
+// a compiled html file under the `build/` directory. If any failures
+// happen, it alerts the user via stdout.
+func generate(page string) error {
+ var templates = template.Must(template.ParseFiles(
+ "templates/head.html",
+ "templates/footer.html",
+ "templates/nav.html",
+ "templates/" + page))
+
+ templates.New("year").Parse(strconv.Itoa(time.Now().Year()))
+
+ file, err := os.Create("build/" + page)
+ if err != nil {
+ return err
+ }
+
+ err = templates.ExecuteTemplate(file, page, nil)
+ if err != nil {
+ return err
+ }
+
+ if err := file.Close(); err != nil {
+ return err
+ }
+ return nil
+}
+
M main.go => main.go +0 -31
@@ 2,41 2,10 @@ package main
import (
"fmt"
- "html/template"
"io/ioutil"
"net/http"
- "os"
- "time"
)
-// generate takes a page in the format `{page}.html` and creates
-// a compiled html file under the `build/` directory. If any failures
-// happen, it alerts the user via stdout.
-func generate(page string) error {
- var templates = template.Must(template.ParseFiles(
- "templates/head.html",
- "templates/footer.html",
- "templates/nav.html",
- "templates/" + page))
-
- templates.New("year").Parse(fmt.Sprint(time.Now().Year()))
-
- file, err := os.Create("build/" + page)
- if err != nil {
- return err
- }
-
- err = templates.ExecuteTemplate(file, page, nil)
- if err != nil {
- return err
- }
-
- if err := file.Close(); err != nil {
- return err
- }
- return nil
-}
-
func main() {
fmt.Println("COMPILING STATIC PAGES")
pages, err := ioutil.ReadDir("templates")