Compare commits
No commits in common. "8f9260b357463edcfcaaa6ce2bf811becec8d855" and "6110eddf68f384b758de5f14fcb07b6f869a7be9" have entirely different histories.
8f9260b357
...
6110eddf68
5 changed files with 21 additions and 37 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -1,9 +1,2 @@
|
|||
/data
|
||||
/covers
|
||||
/bdm
|
||||
/buch_des_monats.iml
|
||||
/.idea/inspectionProfiles/Project_Default.xml
|
||||
/.idea/.gitignore
|
||||
/.idea/misc.xml
|
||||
/.idea/modules.xml
|
||||
/.idea/vcs.xml
|
||||
|
|
4
go.mod
4
go.mod
|
@ -1,3 +1,5 @@
|
|||
module okoyono.de/buchdesmonats
|
||||
|
||||
go 1.20
|
||||
go 1.16
|
||||
|
||||
require github.com/a-h/gemini v0.0.61
|
||||
|
|
2
go.sum
2
go.sum
|
@ -0,0 +1,2 @@
|
|||
github.com/a-h/gemini v0.0.61 h1:WSV9f5T6Vut9gIATUhqAh9KfsA4/kqcUIbTiDbsn1JY=
|
||||
github.com/a-h/gemini v0.0.61/go.mod h1:p9wvIRDc2s3Lnbkw7CgNzDNgJHPuXDwh3dOF7w0NT8s=
|
43
src/bdm.go
43
src/bdm.go
|
@ -2,13 +2,15 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
//"html/template"
|
||||
xmltpl "text/template"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
xmltpl "text/template"
|
||||
)
|
||||
|
||||
type Item struct {
|
||||
|
@ -16,7 +18,7 @@ type Item struct {
|
|||
Author string
|
||||
Title string
|
||||
Filename string
|
||||
Date string
|
||||
Date string
|
||||
}
|
||||
|
||||
func (i Item) ImageURL() string {
|
||||
|
@ -39,24 +41,14 @@ func (i Item) downloadCover() error {
|
|||
return err
|
||||
}
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
err := Body.Close()
|
||||
if err != nil {
|
||||
log.Fatal("Can not close the response body")
|
||||
}
|
||||
}(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
|
||||
out, err := os.Create(i.targetFilename())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer func(out *os.File) {
|
||||
err := out.Close()
|
||||
if err != nil {
|
||||
log.Fatal("Can not close the file")
|
||||
}
|
||||
}(out)
|
||||
defer out.Close()
|
||||
|
||||
_, err = io.Copy(out, resp.Body)
|
||||
|
||||
|
@ -73,21 +65,16 @@ func getItems(filename string) []Item {
|
|||
log.Fatal(filename + " is missing")
|
||||
}
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
err := Body.Close()
|
||||
if err != nil {
|
||||
log.Fatal("Can not close the response body")
|
||||
}
|
||||
}(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
|
||||
content, err := io.ReadAll(resp.Body)
|
||||
content, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal("Can not download the file. Network problem?")
|
||||
}
|
||||
|
||||
currentYear := ""
|
||||
currentMonth := 0
|
||||
re := regexp.MustCompile(`^[^[]+ \[(?P<author>[^"]+)"(?P<title>[^"]+)"]\([^=]+=(?P<isbn>[0-9]+).*$`)
|
||||
re := regexp.MustCompile(`^[^[]+ \[(?P<author>[^"]+)"(?P<title>[^"]+)"\]\([^=]+=(?P<isbn>[0-9]+).*$`)
|
||||
yearRe := regexp.MustCompile(`^## (?P<year>20[0-9]{2})$`)
|
||||
|
||||
var yearBucket []Item
|
||||
|
@ -99,7 +86,7 @@ func getItems(filename string) []Item {
|
|||
currentMonth = 0
|
||||
|
||||
// Add the bucket in reverse order
|
||||
for i := len(yearBucket) - 1; i >= 0; i-- {
|
||||
for i := len(yearBucket)-1; i >= 0; i-- {
|
||||
items = append(items, yearBucket[i])
|
||||
}
|
||||
yearBucket = nil
|
||||
|
@ -110,10 +97,10 @@ func getItems(filename string) []Item {
|
|||
currentMonth++
|
||||
|
||||
yearBucket = append(yearBucket, Item{
|
||||
Author: strings.Trim(matches[1], " "),
|
||||
Title: strings.Trim(matches[2], " "),
|
||||
ISBN: matches[3],
|
||||
Date: fmt.Sprintf("01-%02d-%s", currentMonth, currentYear),
|
||||
Author: strings.Trim(matches[1], " "),
|
||||
Title: strings.Trim(matches[2], " "),
|
||||
ISBN: matches[3],
|
||||
Date: fmt.Sprintf("01-%02d-%s", currentMonth, currentYear),
|
||||
Filename: filename,
|
||||
})
|
||||
}
|
||||
|
@ -131,7 +118,7 @@ func getTemplate(sourceFile string, templateFilename string, w http.ResponseWrit
|
|||
// Get all items from the git repo
|
||||
items := getItems(sourceFile)
|
||||
|
||||
// Generate the resulting HTML
|
||||
// Generate the restulting HTML
|
||||
t, err := xmltpl.ParseFiles("templates/" + templateFilename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>okoyono.de -- Buch des Monats</title>
|
||||
|
|
Loading…
Reference in a new issue