correction yaml creation - extraction yaml + html preparation

This commit is contained in:
github_username_here
2026-03-23 19:05:01 +01:00
parent 874ba49512
commit f7e63ce1e1
156 changed files with 8565 additions and 8512 deletions

View File

@@ -14,21 +14,21 @@ func SaveChapter(cfg config.Cfg, chapter *config.Chapter) (error){
var chapterYaml models.Yaml
for i, verse:= range chapter.Verses{
strophe := models.Strophe{}
parts := SplitInPart(verse, cfg.ProperName)
for _, part := range parts{
line := models.Line{
Verse: i+1,
Text: part,
poeticLine := models.PoeticLine{
Who: "",
To: "",
Of: "",
}
}
cola := SplitInPart(verse, cfg.ProperName)
for _, colon := range cola{
strophe.Lines = append(strophe.Lines, line)
poeticLine.Cola = append(poeticLine.Cola, models.Colon{
Verse: i+1,
Text: colon,
})
}
chapterYaml.Strophes = append(chapterYaml.Strophes, strophe)
log.Printf("%v", parts)
chapterYaml.PoeticLines = append(chapterYaml.PoeticLines, poeticLine)
}
yamlData, err := yaml.Marshal(chapterYaml)

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Your short site description (for SEO)">
<title>Comprendre et chanter les Psaumes</title>
<link rel="stylesheet" href="css/style.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
</head>
<body>{{template "content" .}} </body>
</html>

View File

@@ -0,0 +1,19 @@
{{define "content"}}
<section class="psalm">
<div class="psalm__inner">
<ul class="psalm__strophs">
{{range .Strophes}}
<li class="psalm__strophe" data-who="{{.Who}}" data-to="{{.To}}" data-of="{{.Of}}">
{{range .Lines}}
<ul class="psalm__lines">
{{range .}}
<li class="line" data-verse="{{.Number}}">{{.Text}}</li>
{{end}}
</ul>
{{end}}
</li>
{{end}}
</ul>
</div>
</section>
{{end}}

View File

@@ -1,17 +1,28 @@
package models
type Yaml struct {
Strophes []Strophe `yaml:"strophes"`
PoeticLines []PoeticLine `yaml:"poetic-lines"`
}
type Strophe struct {
Lines []Line `yaml:"lines"`
}
type Line struct {
Verse int `yaml:"verse"`
Text string `yaml:"text"`
type PoeticLine struct {
Cola []Colon `yaml:"cola"`
Who string `yaml:"who"`
To string `yaml:"to"`
Of string `yaml:"Of"`
Of string `yaml:"of"`
}
type Colon struct {
Verse int `yaml:"verse"`
Text string `yaml:"text"`
}
type Strophe struct {
Who string
To string
Of string
Colas [][]Colon
}
type Psalm struct {
Strophes []Strophe
}

View File

@@ -0,0 +1,63 @@
package renderer
import (
"log"
"project.hechon.fr/internal/config"
"project.hechon.fr/internal/models"
"gopkg.in/yaml.v3"
"os"
"path"
"strconv"
"fmt"
)
func ExtractChapter(cfg *config.Cfg, chapterNum int) (error){
fileName := path.Join(cfg.YamlPath, cfg.Book.Name + strconv.Itoa(chapterNum) + ".yaml")
file, err := os.Open(fileName)
if err != nil {
log.Printf("cant open %v: %v", fileName, err)
return err
}
var yamlData models.Yaml
if err = yaml.NewDecoder(file).Decode(&yamlData) ; err != nil{
return err
}
log.Printf("%v", yamlData)
if len(yamlData.PoeticLines) == 0 || len(yamlData.PoeticLines[0].Cola) == 0 {
return fmt.Errorf("no data in %v", fileName)
}
var psalm models.Psalm
currentStrophe := models.Strophe{
Who: yamlData.PoeticLines[0].Who,
To: yamlData.PoeticLines[0].To,
Of: yamlData.PoeticLines[0].Of,
}
for _, poeticLine := range yamlData.PoeticLines{
log.Printf("first line: %v - %v - %v", poeticLine.Who, poeticLine.To, poeticLine.Of)
if poeticLine.Who == currentStrophe.Who &&
poeticLine.To == currentStrophe.To &&
poeticLine.Of == currentStrophe.Of {
currentStrophe.Colas = append(currentStrophe.Colas, poeticLine.Cola)
}else{
psalm.Strophes = append(psalm.Strophes, currentStrophe)
currentStrophe.Who = poeticLine.Who
currentStrophe.Of = poeticLine.Of
currentStrophe.To = poeticLine.To
}
}
psalm.Strophes = append(psalm.Strophes, currentStrophe)
log.Printf("%v", psalm)
return nil
}