Build with make

This commit is contained in:
Brandon Dyck 2023-08-03 19:19:07 -06:00
parent ff9ad5f107
commit 3e1c06bad7
4 changed files with 32 additions and 28 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
book.pdf book.pdf
book.tex

11
Makefile Normal file
View File

@ -0,0 +1,11 @@
chapters := 01 02 03 04 05 06 07 08 09 10 11 12 appendix
edited_chapters := $(foreach chapter,$(chapters),edited/$(chapter).markdown)
book.pdf: $(edited_chapters) title.txt Makefile
pandoc -o book.pdf title.txt $(edited_chapters) --table-of-contents --number-sections -V documentclass=book
edited/%.markdown: original/%.markdown edit-chapter.go Makefile
go run edit-chapter.go $< $@
book.tex: $(edited_chapters) title.txt Makefile
pandoc -o book.tex title.txt $(edited_chapters) --table-of-contents --number-sections -V documentclass=book

View File

@ -4,9 +4,8 @@ package main
import ( import (
"bytes" "bytes"
"log" "fmt"
"os" "os"
"path/filepath"
"regexp" "regexp"
) )
@ -74,34 +73,35 @@ func replaceFootnote(src []byte) []byte {
} }
func run() error { func run() error {
paths, err := filepath.Glob("original/*.markdown") if len(os.Args) != 3 {
if err != nil { fmt.Fprintf(os.Stderr, "usage: %s <infile> <outfile>\n", os.Args[0])
return err os.Exit(64) // command line usage error
} }
for _, path := range paths { inpath := os.Args[1]
b, err := os.ReadFile(path) outpath := os.Args[2]
text, err := os.ReadFile(inpath)
if err != nil { if err != nil {
return err return err
} }
var edited = b
for _, r := range replacers { for _, r := range replacers {
edited = r.re.ReplaceAll(edited, []byte(r.replacement)) text = r.re.ReplaceAll(text, []byte(r.replacement))
} }
edited = footnoteRE.ReplaceAllFunc(edited, replaceFootnote) text = footnoteRE.ReplaceAllFunc(text, replaceFootnote)
outpath := filepath.Join("edited", filepath.Base(path)) err = os.WriteFile(outpath, text, 0666)
err = os.WriteFile(outpath, edited, 0666)
if err != nil { if err != nil {
return err return err
} }
}
return nil return nil
} }
func main() { func main() {
err := run() err := run()
if err != nil { if err != nil {
log.Fatal(err) fmt.Fprintln(os.Stderr, err)
os.Exit(1)
} }
} }

View File

@ -1,8 +0,0 @@
#!/usr/bin/env bash
pandoc -o book.pdf title.txt \
edited/{01,02,03,04,05,06,07,08,09,10,11,12}.markdown \
edited/appendix.markdown \
--table-of-contents \
--number-sections \
-V documentclass=book