Skip to content

Commit

Permalink
Generate template files when making new blog
Browse files Browse the repository at this point in the history
GitHub #1
  • Loading branch information
johnjago committed Jul 21, 2019
1 parent d118a83 commit 5aa51d6
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 43 deletions.
14 changes: 10 additions & 4 deletions blognow.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ import (
"gitlab.com/golang-commonmark/markdown"
)

const sampleConfig string = `
baseURL = "https://example.org/"
const sampleConfig string = `baseURL = "https://example.org/"
title = "My Blog"
tagline = "Don't sail too close to the wind"
`
const samplePost string = `
---
const samplePost string = `---
title = "My First Post"
date = 2019-05-05
---
Expand Down Expand Up @@ -73,6 +71,14 @@ func makeBlogDir(path string) {
fmt.Println("Created a new blog: " + path)
createFile(path+"/config.toml", sampleConfig)
createFile(postsPath+"/sample.md", samplePost)

// Template files
templatesPath := filepath.Join(path, "templates")
os.MkdirAll(templatesPath, os.ModePerm)
createFile(filepath.Join(templatesPath, "base.html"), baseTmpl)
createFile(filepath.Join(templatesPath, "header.html"), headerTmpl)
createFile(filepath.Join(templatesPath, "post.html"), postTmpl)
createFile(filepath.Join(templatesPath, "archive.html"), archiveTmpl)
}

// build collects all the necessary information from configuration files
Expand Down
48 changes: 48 additions & 0 deletions templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

const baseTmpl string = `{{define "base"}}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>{{template "title" .}}</title>
</head>
<body>
{{template "header" .}}
{{template "body" .}}
</body>
</html>
{{end}}
`

const headerTmpl string = `{{define "header"}}
<h1><a href="/">{{.Blog.Title}}</a></h1>
<p>{{.Blog.Tagline}}</p>
{{end}}
`

const postTmpl string = `{{define "title"}}
{{.Post.Title}} - {{.Blog.Title}}
{{end}}
{{define "body"}}
<h2>{{.Post.Title}}</h2>
{{.Post.Content}}
<p>Posted: {{.Post.Date | formatDate}}</p>
<a href="/archive/">See all posts »</a>
{{end}}
`

const archiveTmpl string = `{{define "title"}}
All Posts - {{.Blog.Title}}
{{end}}
{{define "body"}}
<ul>
{{range .Posts}}
<li>{{.Date | formatDate}} <a href="/{{.Slug}}">{{.Title}}</a></li>
{{end}}
</ul>
{{end}}
`
11 changes: 0 additions & 11 deletions templates/archive.html

This file was deleted.

14 changes: 0 additions & 14 deletions templates/base.html

This file was deleted.

4 changes: 0 additions & 4 deletions templates/header.html

This file was deleted.

10 changes: 0 additions & 10 deletions templates/post.html

This file was deleted.

0 comments on commit 5aa51d6

Please sign in to comment.