diff --git a/_content/storia.json b/_content/storia.json deleted file mode 100644 index 5755c4a..0000000 --- a/_content/storia.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "macchinisti": [ - { - "uid": "minnocci", - "fullName": "Francesco Minnocci", - "entryDate": "2022/02" - }, - { - "uid": "manicastri", - "fullName": "Francesco Manicastri", - "entryDate": "2022/05" - }, - { - "uid": "delucreziis", - "fullName": "Antonio De Lucreziis", - "entryDate": "2019/??" - }, - { - "uid": "caporali", - "fullName": "Francesco Caporali", - "entryDate": "2018/??", - "exitDate": "2022/03" - }, - { - "uid": "dachille", - "fullName": "Letizia D'Achille", - "entryDate": "2018/??", - "exitDate": "2022/03" - } - ], - "eventi": [ - { - "type": "simple", - "title": "Nuovo sito del PHC", - "description": "Featuring: ricerca utenti, dark mode, nuovo logo e molto altro!", - "date": "2022/09", - "icon": "fa-solid fa-star" - }, - { - "type": "simple", - "title": "Data di pubblicazione del sito Poisson originale", - "date": "1996/06/17", - "description": "Visitalo sul Web Archive: web.archive.org/web/19971017065805/http://poisson.dm.unipi.it", - "icon": "fa-solid fa-upload" - }, - { - "type": "simple", - "title": "Apertura del PHC", - "date": "1994", - "icon": "fa-solid fa-flag-checkered" - } - ] -} diff --git a/_content/storia.yaml b/_content/storia.yaml new file mode 100644 index 0000000..3afd3cb --- /dev/null +++ b/_content/storia.yaml @@ -0,0 +1,35 @@ +macchinisti: +- uid: minnocci + fullName: Francesco Minnocci + entryDate: 2022/02 +- uid: manicastri + fullName: Francesco Manicastri + entryDate: 2022/05 +- uid: delucreziis + fullName: Antonio De Lucreziis + entryDate: 2019/?? +- uid: caporali + fullName: Francesco Caporali + entryDate: 2018/?? + exitDate: 2022/03 +- uid: dachille + fullName: Letizia D'Achille + entryDate: 2018/?? + exitDate: 2022/03 +eventi: +- type: simple + title: Nuovo sito del PHC + description: | + Featuring: ricerca utenti, dark mode, nuovo logo e molto altro! + date: 2022/09 + icon: fa-solid fa-star +- type: simple + title: Data di pubblicazione del sito Poisson originale + date: 1996/06/17 + description: | + Visitalo sul [Web Archive](https://web.archive.org/web/19971017065805/http://poisson.dm.unipi.it) + icon: fa-solid fa-upload +- type: simple + title: Apertura del PHC + date: 1994 + icon: fa-solid fa-flag-checkered diff --git a/_views/storia.html b/_views/storia.html index f894ac3..8b4f83a 100644 --- a/_views/storia.html +++ b/_views/storia.html @@ -27,7 +27,7 @@
{{ .Date }}
- {{ .Description }} + {{ raw .Description }}
{{ end }} diff --git a/articles/article.go b/articles/article.go index 7ce27b0..4374877 100644 --- a/articles/article.go +++ b/articles/article.go @@ -102,7 +102,7 @@ func (article *Article) Render() (string, error) { if article.renderedHTML == "" { var buf bytes.Buffer - if err := articleMarkdown.Convert([]byte(article.markdownSource), &buf); err != nil { + if err := Markdown.Convert([]byte(article.markdownSource), &buf); err != nil { return "", err } diff --git a/articles/markdown.go b/articles/markdown.go index f081395..3a86114 100644 --- a/articles/markdown.go +++ b/articles/markdown.go @@ -14,7 +14,7 @@ import ( highlighting "github.com/yuin/goldmark-highlighting" ) -var articleMarkdown goldmark.Markdown +var Markdown goldmark.Markdown // https://github.com/yuin/goldmark-highlighting/blob/9216f9c5aa010c549cc9fc92bb2593ab299f90d4/highlighting_test.go#L27 func customCodeBlockWrapper(w util.BufWriter, c highlighting.CodeBlockContext, entering bool) { @@ -35,7 +35,7 @@ func customCodeBlockWrapper(w util.BufWriter, c highlighting.CodeBlockContext, e } func init() { - articleMarkdown = goldmark.New( + Markdown = goldmark.New( goldmark.WithExtensions( extension.GFM, extension.Typographer, diff --git a/cmd/phc-website-server/main.go b/cmd/phc-website-server/main.go index 81ded2c..c5843f1 100644 --- a/cmd/phc-website-server/main.go +++ b/cmd/phc-website-server/main.go @@ -33,7 +33,7 @@ func main() { NewsArticlesRegistry: articles.NewRegistry("./_content/news"), GuideArticlesRegistry: articles.NewRegistry("./_content/guide"), Storia: &storia.JsonFileStoria{ - Path: "./_content/storia.json", + Path: "./_content/storia.yaml", }, ListaUtenti: listaUtentiService, } diff --git a/storia/storia.go b/storia/storia.go index 1505607..679bbef 100644 --- a/storia/storia.go +++ b/storia/storia.go @@ -1,14 +1,16 @@ package storia import ( - "encoding/json" + "bytes" "math" "os" "sort" "strconv" "strings" + "git.phc.dm.unipi.it/phc/website/articles" "git.phc.dm.unipi.it/phc/website/util" + "gopkg.in/yaml.v3" ) type StoriaService interface { @@ -17,34 +19,34 @@ type StoriaService interface { type GenericEvent struct { // Campi principali - Type string `json:"type"` - Date string `json:"date"` + Type string `yaml:"type"` + Date string `yaml:"date"` // Altri campi utilizzati ogni tanto - Title string `json:"title"` - Description string `json:"description"` + Title string `yaml:"title"` + Description string `yaml:"description"` // Se il tipo di evento è riferito ad un utente usiamo anche questo campo apposta - Uid string `json:"uid"` - FullName string `json:"fullName"` + Uid string `yaml:"uid"` + FullName string `yaml:"fullName"` // Se il tipo è "spacer" questa è la sua dimensione - Size int `json:"size"` + Size int `yaml:"size"` // Icona opzionale per il tipo "simple" - Icon string `json:"icon"` + Icon string `yaml:"icon"` } type Macchinista struct { - Uid string `json:"uid"` - FullName string `json:"fullName"` - EntryDate string `json:"entryDate"` - ExitDate string `json:"exitDate"` + Uid string `yaml:"uid"` + FullName string `yaml:"fullName"` + EntryDate string `yaml:"entryDate"` + ExitDate string `yaml:"exitDate"` } type storiaDB struct { - Macchinisti []*Macchinista `json:"macchinisti"` - GenericEvent []*GenericEvent `json:"eventi"` + Macchinisti []*Macchinista `yaml:"macchinisti"` + GenericEvent []*GenericEvent `yaml:"eventi"` } type JsonFileStoria struct { @@ -91,18 +93,29 @@ func (db *JsonFileStoria) GetStoria() ([]*GenericEvent, error) { sort.Sort(byEventDateDescending(events)) + // render descriptions to markdown + + for _, event := range events { + var buf bytes.Buffer + if err := articles.Markdown.Convert([]byte(event.Description), &buf); err != nil { + return nil, err + } + + event.Description = buf.String() + } + return withSpacers(events), nil } func (db *JsonFileStoria) GetRawStoria() (*storiaDB, error) { var rawHistory storiaDB - historyDB, err := os.ReadFile(db.Path) + f, err := os.Open(db.Path) if err != nil { return nil, err } - if err := json.Unmarshal(historyDB, &rawHistory); err != nil { + if err := yaml.NewDecoder(f).Decode(&rawHistory); err != nil { return nil, err } diff --git a/templates/templates.go b/templates/templates.go index b74a217..1e62722 100644 --- a/templates/templates.go +++ b/templates/templates.go @@ -1,6 +1,7 @@ package templates import ( + "fmt" "html/template" "io" "log" @@ -23,7 +24,9 @@ func NewCacheTemplate(loadPatterns ...string) *CachedTemplate { PreLoadTemplatePatterns: loadPatterns, cachedTmpl: nil, } - template.Must(cachedTemplate.Load(template.New(""))) + + template.Must(cachedTemplate.Load(nil)) + return cachedTemplate } @@ -33,7 +36,11 @@ func (ct *CachedTemplate) Load(t *template.Template) (*template.Template, error) return ct.cachedTmpl, nil } - ct.cachedTmpl = t + ct.cachedTmpl = template.New("").Funcs(template.FuncMap{ + "raw": func(value any) template.HTML { + return template.HTML(fmt.Sprint(value)) + }, + }) for _, pattern := range ct.PreLoadTemplatePatterns { var err error