Build with make
This commit is contained in:
parent
ff9ad5f107
commit
3e1c06bad7
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
book.pdf
|
||||
book.tex
|
||||
|
11
Makefile
Normal file
11
Makefile
Normal 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
|
@ -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 len(os.Args) != 3 {
|
||||
fmt.Fprintf(os.Stderr, "usage: %s <infile> <outfile>\n", os.Args[0])
|
||||
os.Exit(64) // command line usage error
|
||||
}
|
||||
inpath := os.Args[1]
|
||||
outpath := os.Args[2]
|
||||
|
||||
text, err := os.ReadFile(inpath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, path := range paths {
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var edited = b
|
||||
for _, r := range replacers {
|
||||
edited = r.re.ReplaceAll(edited, []byte(r.replacement))
|
||||
}
|
||||
edited = footnoteRE.ReplaceAllFunc(edited, replaceFootnote)
|
||||
|
||||
outpath := filepath.Join("edited", filepath.Base(path))
|
||||
err = os.WriteFile(outpath, edited, 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, r := range replacers {
|
||||
text = r.re.ReplaceAll(text, []byte(r.replacement))
|
||||
}
|
||||
text = footnoteRE.ReplaceAllFunc(text, replaceFootnote)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
@ -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
|
Loading…
Reference in New Issue
Block a user