Generate page from yaml config
Some checks failed
Deployment / build (push) Failing after 2m44s

This commit is contained in:
fleaz 2025-07-26 18:38:30 +02:00
parent 0458fd6fd1
commit 3abc7deba3
Signed by: fleaz
GPG key ID: 935474624265FE8F
19 changed files with 108 additions and 42 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use nix

View file

@ -32,7 +32,7 @@ jobs:
go run main.go
mv index.html dist/
mv previews/ dist/
mv talks/ dist/
mv pdf/ dist/
- uses: https://github.com/jakejarvis/s3-sync-action@master
with:

8
go.mod
View file

@ -1,8 +1,10 @@
module git.rainbownerds.de/felix/slides.fleaz.me
go 1.21
go 1.22
toolchain go1.24.4
require (
gopkg.in/gographics/imagick.v2 v2.6.4
gopkg.in/gographics/imagick.v3 v3.5.3
gopkg.in/gographics/imagick.v3 v3.7.2
gopkg.in/yaml.v2 v2.4.0
)

10
go.sum
View file

@ -1,4 +1,6 @@
gopkg.in/gographics/imagick.v2 v2.6.4 h1:H7UgF2ZAdV85sMB9YU2c6r3dpp9SP4N6UF+bG3OK728=
gopkg.in/gographics/imagick.v2 v2.6.4/go.mod h1:/QVPLV/iKdNttRKthmDkeeGg+vdHurVEPc8zkU0XgBk=
gopkg.in/gographics/imagick.v3 v3.5.3 h1:Ho8/2Uu76Y1Z5P65dUBhh5ZeKS3ZcvYH12amWZNpSFA=
gopkg.in/gographics/imagick.v3 v3.5.3/go.mod h1:+Q9nyA2xRZXrDyTtJ/eko+8V/5E7bWYs08ndkZp8UmA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/gographics/imagick.v3 v3.7.2 h1:PmsYCf60YS/7f1omBTDaoS6yp4817Wv61S0JpWH4cMc=
gopkg.in/gographics/imagick.v3 v3.7.2/go.mod h1:7I4S9VWdwr88yzYi7g+ZL4H8oZuH9cmSQI7GsZCcYFM=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

54
main.go
View file

@ -4,66 +4,62 @@ import (
"fmt"
"html/template"
"os"
"path/filepath"
"regexp"
"sort"
"gopkg.in/gographics/imagick.v2/imagick"
"gopkg.in/gographics/imagick.v3/imagick"
"gopkg.in/yaml.v2"
)
type Talk struct {
Title string
Date string
Preview string
Path string
PDF string
Description string
}
func generatePreview(path string) Talk {
r := regexp.MustCompile("talks\\/(.*)\\.pdf")
result := r.FindStringSubmatch(path)
imagePath := fmt.Sprintf("previews/%s.jpg", result[1])
func generatePreview(path string) {
pdfPath := fmt.Sprintf("pdfs/%s", path)
imagePath := fmt.Sprintf("previews/%s.png", path)
mw := imagick.NewMagickWand()
defer mw.Destroy()
err := mw.ReadImage(path)
fmt.Println(pdfPath)
err := mw.ReadImage(pdfPath)
if err != nil {
panic(err)
}
mw.SetIteratorIndex(0)
mw.SetImageFormat("jpg")
mw.SetImageFormat("png")
err = mw.WriteImage(imagePath)
if err != nil {
panic(err)
}
return Talk{Title: result[1], Preview: imagePath, Path: path, Description: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."}
}
func main() {
var files []string
data, err := os.ReadFile("talks.yaml")
if err != nil {
panic(err)
}
root := "talks/"
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}
files = append(files, path)
return nil
})
var talks []Talk
err = yaml.Unmarshal(data, &talks)
if err != nil {
panic(err)
}
imagick.Initialize()
defer imagick.Terminate()
var data []Talk
for _, file := range files {
t := generatePreview(file)
data = append(data, t)
for _, t := range talks {
generatePreview(t.PDF)
}
for i := len(data)/2 - 1; i >= 0; i-- {
opp := len(data) - 1 - i
data[i], data[opp] = data[opp], data[i]
}
sort.Slice(talks, func(i, j int) bool {
return talks[i].Date > talks[j].Date
})
tmpl, err := template.ParseFiles("template.html")
if err != nil {
@ -76,5 +72,5 @@ func main() {
}
defer f.Close()
tmpl.Execute(f, data)
tmpl.Execute(f, talks)
}

11
shell.nix Normal file
View file

@ -0,0 +1,11 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [
pkg-config
imagemagick
gcc
ghostscript
];
}

BIN
slides.fleaz.me Executable file

Binary file not shown.

52
talks.yaml Normal file
View file

@ -0,0 +1,52 @@
---
- date: 2025-07-25
title: "Einfach mal Nix machen!"
pdf: nixos.pdf
description: "Description comming soon..."
- date: 2016-10-18
title: B.Sc. Endvortrag
pdf: bsc.pdf
description: "Description comming soon..."
- date: 2016-12-13
title: RSpamd
pdf: rspamd.pdf
description: "Description comming soon..."
- date: 2017-06-06
title: "BorgBackup"
pdf: borgbackup.pdf
description: "Description comming soon..."
- date: 2018-10-20
title: "Hacktoberfest 2018 @ CCCDA"
pdf: hacktoberfest18.pdf
description: "Description comming soon..."
- date: 2018-10-30
title: "WikiSpy"
pdf: wikispy.pdf
description: "Description comming soon..."
- date: 2019-02-22
title:
pdf: 3d-printing.pdf
description: "Description comming soon..."
- date: 2019-03-07
title: "git happens ¯__(ツ)__¯"
pdf: git.pdf
description: "Description comming soon..."
- date: 2019-10-19
title: "Hacktoberfest 2019 @ CCCDA"
pdf: hacktoberfest19.pdf
description: "Description comming soon..."
- date: 2022-12-29
title: "Mechanical Keyboards"
pdf: keebs.pdf
description: "Description comming soon..."

View file

@ -15,6 +15,9 @@
margin: 20px;
padding: 20px;
}
.description {
margin: 20px;
}
</style>
</head>
@ -22,13 +25,12 @@
<div class="container mx-auto">
{{ range . }}
<div class="block clearfix">
<a href="{{ .Path }}">
<span class="text-2xl underline">{{ .Title }}</span>
<img class="h-48 float-right shadow-xl" src="{{ .Preview }}" />
<p>
<span class="text-2xl underline">{{ .Title }} ({{ .Date }})</span>
<img class="h-48 float-right shadow-xl" src="previews/{{ .PDF }}.png" />
<p class="description">
{{ .Description }}
</p>
</a>
<a href="talks/{{ .PDF }}">Download PDF</a>
</div>
{{ end }}
</div>