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.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 (
"bytes"
"log"
"fmt"
"os"
"path/filepath"
"regexp"
)
@ -74,34 +73,35 @@ func replaceFootnote(src []byte) []byte {
}
func run() error {
paths, err := filepath.Glob("original/*.markdown")
if err != nil {
return err
if len(os.Args) != 3 {
fmt.Fprintf(os.Stderr, "usage: %s <infile> <outfile>\n", os.Args[0])
os.Exit(64) // command line usage error
}
for _, path := range paths {
b, err := os.ReadFile(path)
inpath := os.Args[1]
outpath := os.Args[2]
text, err := os.ReadFile(inpath)
if err != nil {
return err
}
var edited = b
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, edited, 0666)
err = os.WriteFile(outpath, text, 0666)
if err != nil {
return err
}
}
return nil
}
func main() {
err := run()
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