Aggiunto supporto per il markdown alle descrizioni degli item in storia e convertito a YAML
This commit is contained in:
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
</div>
|
||||
<div class="date">{{ .Date }}</div>
|
||||
<div class="description">
|
||||
{{ .Description }}
|
||||
{{ raw .Description }}
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
+1
-1
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
+30
-17
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user