use markdown for title and introduction

This commit is contained in:
Mark McGranaghan 2012-10-08 11:06:20 -07:00
parent cdd12d7400
commit 29494bd028
6 changed files with 49 additions and 40 deletions

View File

@ -28,7 +28,7 @@ div#title h1 {
font-size: 72px;
margin-top: 4em;
}
div#title h4 {
div#title h3 {
font-size: 24px;
margin-top: 4em;
margin-bottom: 18em;

View File

@ -1,30 +0,0 @@
<h2>Introduction</h2>
<p>Go is an open-source programming language designed for
building simple, fast, and reliable software. It's
powerful to use and fun to learn.</p>
<p>This book is a hands-on introduction to Go. It gives
you the tools you need to understand the why of Go and
how to write real Go programs.</p>
<h3>Intended Audience</h3>
<p>This book is intended for experienced programmers who
may be new to Go. If you have previous experience with
languages like Ruby, Python, Javascript, C#, or Java,
you should find this book immediately approachable even
if this is your first introduction to Go. Even if
you've worked with Go before, you may find that the
material covers ideas and techniques that you haven't
seen elsewhere.</p>
<h3>An Example-Based Approach</h3>
<p>We believe that programmers learn to program by writing
programs. <i>Go by Example</i> therefore teaches Go
exclusively via working example programs, with each
chapter trying to provide the programmer a new tool for
writing her own programs.</p>

28
src/introduction.md Normal file
View File

@ -0,0 +1,28 @@
## Introduction
Go is an open-source programming language designed for
building simple, fast, and reliable software.
It's powerful to use and fun to learn.
This book is a hands-on introduction to Go. It gives you
the tools you need to understand the why of Go and how to
write real Go programs.
### Intended Audience
This book is intended for experienced programmers who may
be new to Go. If you have previous experience with
languages like Ruby, Python, Javascript, C#, or Java, you
should find this book immediately approachable even if
this is your first introduction to Go. Even if you've
worked with Go before, you may find that the material
covers ideas and techniques that you haven't seen
elsewhere.
### An Example-Based Approach
Programmers learn to program by writing programs.
_Go by Example_ therefore teaches Go exclusively via
working example programs, with each chapter trying to
provide the programmer a new tool for writing her own
programs.

View File

@ -1,5 +0,0 @@
<div class="chapter" id="title">
<h1>Go by Example</h1>
<h4>Mark McGranaghan</h4>
</div>

3
src/title.md Normal file
View File

@ -0,0 +1,3 @@
# Go by Example
### Mark McGranaghan

View File

@ -69,11 +69,22 @@ func cachedRender(bin string, arg []string, src string) string {
return string(renderBytes)
}
func cachedPygmentize(lex string, src string) string {
return cachedRender(
"/usr/local/bin/pygmentize",
[]string{"-l", lex, "-f", "html"},
src)
}
func ensureCache() {
mkdirErr := os.MkdirAll(cacheDir, 0700)
check(mkdirErr)
}
func markdown(src string) string {
return string(blackfriday.MarkdownCommon([]byte(src)))
}
func readLines(path string) []string {
src := mustReadFile(path)
return strings.Split(src, "\n")
@ -170,10 +181,10 @@ func parseAndRenderSegs(sourcePath string) []*seg {
lexer := whichLexer(sourcePath)
for _, seg := range segs {
if seg.docs != "" {
seg.docsRendered = string(blackfriday.MarkdownCommon([]byte(seg.docs)))
seg.docsRendered = markdown(seg.docs)
}
if seg.code != "" {
seg.codeRendered = cachedRender("/usr/local/bin/pygmentize", []string{"-l", lexer, "-f", "html"}, seg.code)
seg.codeRendered = cachedPygmentize(lexer, seg.code)
}
}
return segs
@ -199,7 +210,9 @@ func main() {
<body>`)
// Title page
fmt.Fprint(outF, mustReadFile("src/title.html"))
fmt.Fprintf(outF,
`<div class="chapter" id="title">%s</div>`,
markdown(mustReadFile("src/title.md")))
// Contents page
chapterIds := readLines("src/contents.txt")
@ -220,7 +233,7 @@ func main() {
for _, chapterId := range chapterIds {
fmt.Fprintf(outF, `<div class="chapter" id="%s">`, chapterId)
if chapterId == "introduction" {
fmt.Fprint(outF, mustReadFile("src/introduction.html"))
fmt.Fprint(outF, markdown(mustReadFile("src/introduction.md")))
} else {
chapterPath := "src/" + chapterId
fmt.Fprintf(outF,