Add new build tool.

bibliogra.py requires Python 2, which is a pain to deal with.  This
commit adds a Go tool that compiles CensorBib from BibTeX to HTML.  The
tool does the bare minimum and is quite strict in the BibTeX format it
expects.
This commit is contained in:
Philipp Winter 2024-03-09 16:28:23 -06:00
parent d432134ed4
commit 4be5f7bfb2
21 changed files with 2381 additions and 0 deletions

55
src/decode.go Normal file
View file

@ -0,0 +1,55 @@
package main
import (
"log"
"strings"
)
type conversion struct {
from string
to string
}
func decodeTitle(title string) string {
for _, convert := range []conversion{
{`\#`, "#"},
{`--`, ``},
{"``", "“"},
{"''", "”"},
{"'", ""}, // U+2019
{`$\cdot$`, `·`}, // U+00B7.
} {
title = strings.Replace(title, convert.from, convert.to, -1)
}
// Get rid of all curly brackets. We're displaying titles without changing
// their casing.
title = strings.ReplaceAll(title, "{", "")
title = strings.ReplaceAll(title, "}", "")
return title
}
func decodeAuthors(authors string) string {
for _, convert := range []conversion{
{"'", ""},
} {
authors = strings.Replace(authors, convert.from, convert.to, -1)
}
// For simplicity, we expect authors to be formatted as "John Doe" instead
// of "Doe, John".
if strings.Contains(authors, ",") {
log.Fatalf("author %q contains a comma", authors)
}
authorSlice := strings.Split(authors, " and ")
return strings.Join(authorSlice, ", ")
}
func decodeProceedings(proceedings string) string {
for _, convert := range []conversion{
{`\&`, "&"},
} {
proceedings = strings.Replace(proceedings, convert.from, convert.to, -1)
}
return proceedings
}