Closed mmcloughlin closed 4 years ago
Temp converversion script.
package main
import (
"fmt"
"log"
"os"
"github.com/nickng/bibtex"
"gopkg.in/yaml.v2"
)
type Reference struct {
Title string `yaml:"title"`
URL string `yaml:"url"`
Author string `yaml:"author"`
Note string `yaml:"note,omitempty"`
Section string `yaml:"section,omitempty"`
Highlight bool `yaml:"highlight,omitempty"`
Queued bool `yaml:"queued,omitempty"`
// ---------------------
ID string `yaml:"id"`
Type string `yaml:"type,omitempty"`
Fields map[string]string `yaml:"fields,omitempty"`
}
func main() {
filename := "bibliography.bib"
f, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
defer f.Close()
bib, err := bibtex.Parse(f)
if err != nil {
log.Fatal(err)
}
var refs []Reference
for _, e := range bib.Entries {
var r Reference
r.ID = e.CiteName
if e.Type != "misc" {
r.Type = e.Type
}
r.Title = e.Fields["title"].String()
delete(e.Fields, "title")
r.URL = e.Fields["url"].String()
delete(e.Fields, "url")
r.Author = e.Fields["author"].String()
delete(e.Fields, "author")
if len(e.Fields) > 0 {
r.Fields = map[string]string{}
for k, v := range e.Fields {
r.Fields[k] = v.String()
}
}
refs = append(refs, r)
}
b, err := yaml.Marshal(refs)
if err != nil {
log.Fatal(err)
}
fmt.Print(string(b))
}
Generate the bibliography file from the references database.
This would only output a subset of the references, specifically those that define an
id
field and have enough supplemental fields.