Compare commits

..

No commits in common. "0ada92efa91ffd355abec7bf6c506e33aca1d4e9" and "a66205742dff5bafc1b8ed443b16bfac86c175ce" have entirely different histories.

7 changed files with 17 additions and 114 deletions

2
go.mod
View file

@ -1,5 +1,3 @@
module okoyono.de/buchdesmonats
go 1.16
require github.com/a-h/gemini v0.0.61

2
go.sum
View file

@ -1,2 +0,0 @@
github.com/a-h/gemini v0.0.61 h1:WSV9f5T6Vut9gIATUhqAh9KfsA4/kqcUIbTiDbsn1JY=
github.com/a-h/gemini v0.0.61/go.mod h1:p9wvIRDc2s3Lnbkw7CgNzDNgJHPuXDwh3dOF7w0NT8s=

View file

@ -2,23 +2,18 @@ package main
import (
"fmt"
//"html/template"
xmltpl "text/template"
"html/template"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
"strings"
)
type Item struct {
ISBN string
Author string
Title string
Filename string
Date string
}
func (i Item) ImageURL() string {
@ -72,61 +67,27 @@ func getItems(filename string) []Item {
log.Fatal("Can not download the file. Network problem?")
}
currentYear := ""
currentMonth := 0
re := regexp.MustCompile(`^[^[]+ \[(?P<author>[^"]+)"(?P<title>[^"]+)"\]\([^=]+=(?P<isbn>[0-9]+).*$`)
yearRe := regexp.MustCompile(`^## (?P<year>20[0-9]{2})$`)
re := regexp.MustCompile(`[0-9]{13}`)
matches := re.FindAllString(string(content), -1)
var yearBucket []Item
for _, line := range strings.Split(string(content), "\n") {
// Do we find a year?
yearMatches := yearRe.FindStringSubmatch(line)
if len(yearMatches) > 0 {
currentYear = yearMatches[1]
currentMonth = 0
// Add the bucket in reverse order
for i := len(yearBucket)-1; i >= 0; i-- {
items = append(items, yearBucket[i])
}
yearBucket = nil
}
matches := re.FindStringSubmatch(line)
if len(matches) == 4 {
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),
Filename: filename,
})
}
}
log.Printf("Output all items:")
for _, i := range items {
log.Printf("%v", i)
for _, isbn := range matches {
items = append(items, Item{ISBN: isbn, Filename: filename})
}
return items
}
func getTemplate(sourceFile string, templateFilename string, w http.ResponseWriter) {
func getHTML(filename string, w http.ResponseWriter) {
// Get all items from the git repo
items := getItems(sourceFile)
items := getItems(filename)
// Generate the restulting HTML
t, err := xmltpl.ParseFiles("templates/" + templateFilename)
t, err := template.ParseFiles("templates/" + filename + ".html")
if err != nil {
panic(err)
}
err = t.Execute(w, map[string]interface{}{
"Items": items,
})
err = t.Execute(w, items)
if err != nil {
panic(err)
}
@ -154,7 +115,6 @@ func main() {
err := item.downloadCover()
if err != nil {
fmt.Printf("%v", err)
fmt.Printf("ERROR: File %s not found\n", item.ImageURL())
}
}
@ -162,25 +122,15 @@ func main() {
http.HandleFunc("/book", func(w http.ResponseWriter, r *http.Request) {
log.Print("/book")
getTemplate("BOOK.mkd", "book.html", w)
getHTML("BOOK.mkd", w)
})
http.HandleFunc("/comic", func(w http.ResponseWriter, r *http.Request) {
log.Print("/comic")
getTemplate("COMIC.mkd", "comic.html", w)
})
http.HandleFunc("/book.xml", func(w http.ResponseWriter, r *http.Request) {
log.Print("/book.xml")
w.Header().Add("Content-Type", "Application/rss+xml")
getTemplate("BOOK.mkd", "book.xml", w)
})
http.HandleFunc("/comic.xml", func(w http.ResponseWriter, r *http.Request) {
log.Print("/comic.xml")
w.Header().Add("Content-Type", "Application/rss+xml")
getTemplate("COMIC.mkd", "comic.xml", w)
getHTML("COMIC.mkd", w)
})
// Spawn the webserver (blocking)
log.Print("Spawn webserver on port :9783 and waiting for requests ... ...")
log.Print("Spawn webserver on port :9783 and waiting for requests ...")
err := http.ListenAndServe(":9783", nil)
if err != nil {
panic(err)

View file

@ -11,19 +11,19 @@
</head>
<body>
<h1>Buch des Monats</h1>
<p>Handerlesen und für gut befunden seit 2010
<p>Handverlesen und für gut befunden seit 2010
von <a href="https://social.okoyono.de/@mezzo" rel="author">Michael
Reutter</a>. Jeden Monat ein neues Buch aus seiner Sammlung zu den
Themengebieten Netzkultur, Geektum, Computerspiele und Cyberpunk. Diese
Bücherliste ist mittlerweile Anlaufstelle für so manchen Leser der nach
neuem Stoff sucht. Die Buchlinks gehen zu <a href="https://mojoreads.com/">mojoreads</a>, <a href="https://git.okoyono.de/mezzo/buch_des_monats">der
Code</a> von <a href="https://aaron-fischer.net/">Aaron Fischer</a>.
Code</a> ist von <a href="https://aaron-fischer.net/">Aaron Fischer</a>.
Ein <a href="https://okoyono.de/">økoyono</a> Projekt.</p>
<div id="covers">
{{ range . }}
<div class="cover-item">
<a target="_blank" href="https://mojoreads.de/book/?isbn={{ .ISBN }}&ref=mezzo&aff=mr"><img src="/covers/{{ .ISBN }}.jpg" alt="{{ .Author | html }} - {{ .Title | html }}" title="zu Mojoreads" /></a>
<a href="https://mojoreads.de/book/?isbn={{ .ISBN }}&ref=mezzo&aff=mr" target="_blank" ><img src="/covers/{{ .ISBN }}.jpg" alt="Mojoreads cover" title="zu Mojoreads" /></a>
</div>
{{ end }}
</div>

View file

@ -16,9 +16,9 @@
Code</a> ist von <a href="https://aaron-fischer.net/">Aaron Fischer</a>. Ein <a href="https://okoyono.de/">økoyono</a> Projekt. (Eine Seite mit Buchempfehlungen findet Ihr <a href="https://buchdesmonats.okoyono.de">hier</a>)</p>
<div id="covers">
{{ range .Items }}
{{ range . }}
<div class="cover-item">
<a target="_blank" href="https://mojoreads.de/book/?isbn={{ .ISBN }}&ref=mezzo&aff=mr"><img src="/covers/{{ .ISBN }}.jpg" alt="{{ .Author | html }} - {{ .Title | html }}" title="zu Mojoreads" /></a>
<a href="https://mojoreads.de/book/?isbn={{ .ISBN }}&ref=mezzo&aff=mr" target="_blank"><img src="/covers/{{ .ISBN }}.jpg" alt="Mojoreads cover" title="zu Mojoreads" /></a>
</div>
{{ end }}
</div>

View file

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>okoyono.de -- Buch des Monats</title>
<link href="https://buchdesmonats.okoyono.de/"/>
<updated>{{ (index .Items 0).Date }}T00:00:00Z</updated>
<author>
<name>Michael Reutter</name>
</author>
<id>urn:uuid:{{ (index .Items 0).ISBN }}</id>
{{ range .Items }}
<entry>
<title>{{ .Author | html }} - "{{ .Title | html }}"</title>
<link href="https://mojoreads.de/book/?isbn={{ .ISBN }}&amp;ref=mezzo&amp;aff=mr"/>
<id>urn:uuid:{{ .ISBN }}</id>
<updated>{{ .Date }}T00:00:00Z</updated>
<summary>{{ .Author | html }} - "{{ .Title | html }}"</summary>
</entry>
{{ end }}
</feed>

View file

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>okoyono.de -- Comic des Monats</title>
<link href="https://comicdesmonats.okoyono.de/"/>
<updated>{{ (index .Items 0).Date }}T00:00:00Z</updated>
<author>
<name>Michael Reutter</name>
</author>
<id>urn:uuid:{{ (index .Items 0).ISBN }}</id>
{{ range .Items }}
<entry>
<title>{{ .Author | html }} - "{{ .Title | html }}"</title>
<link href="https://mojoreads.de/book/?isbn={{ .ISBN }}&amp;ref=mezzo&amp;aff=mr"/>
<id>urn:uuid:{{ .ISBN }}</id>
<updated>{{ .Date }}T00:00:00Z</updated>
<summary>{{ .Author | html }} - "{{ .Title | html }}"</summary>
</entry>
{{ end }}
</feed>