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>
|
||||||
<div class="date">{{ .Date }}</div>
|
<div class="date">{{ .Date }}</div>
|
||||||
<div class="description">
|
<div class="description">
|
||||||
{{ .Description }}
|
{{ raw .Description }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|||||||
+1
-1
@@ -102,7 +102,7 @@ func (article *Article) Render() (string, error) {
|
|||||||
|
|
||||||
if article.renderedHTML == "" {
|
if article.renderedHTML == "" {
|
||||||
var buf bytes.Buffer
|
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
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
highlighting "github.com/yuin/goldmark-highlighting"
|
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
|
// https://github.com/yuin/goldmark-highlighting/blob/9216f9c5aa010c549cc9fc92bb2593ab299f90d4/highlighting_test.go#L27
|
||||||
func customCodeBlockWrapper(w util.BufWriter, c highlighting.CodeBlockContext, entering bool) {
|
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() {
|
func init() {
|
||||||
articleMarkdown = goldmark.New(
|
Markdown = goldmark.New(
|
||||||
goldmark.WithExtensions(
|
goldmark.WithExtensions(
|
||||||
extension.GFM,
|
extension.GFM,
|
||||||
extension.Typographer,
|
extension.Typographer,
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func main() {
|
|||||||
NewsArticlesRegistry: articles.NewRegistry("./_content/news"),
|
NewsArticlesRegistry: articles.NewRegistry("./_content/news"),
|
||||||
GuideArticlesRegistry: articles.NewRegistry("./_content/guide"),
|
GuideArticlesRegistry: articles.NewRegistry("./_content/guide"),
|
||||||
Storia: &storia.JsonFileStoria{
|
Storia: &storia.JsonFileStoria{
|
||||||
Path: "./_content/storia.json",
|
Path: "./_content/storia.yaml",
|
||||||
},
|
},
|
||||||
ListaUtenti: listaUtentiService,
|
ListaUtenti: listaUtentiService,
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-17
@@ -1,14 +1,16 @@
|
|||||||
package storia
|
package storia
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"bytes"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.phc.dm.unipi.it/phc/website/articles"
|
||||||
"git.phc.dm.unipi.it/phc/website/util"
|
"git.phc.dm.unipi.it/phc/website/util"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StoriaService interface {
|
type StoriaService interface {
|
||||||
@@ -17,34 +19,34 @@ type StoriaService interface {
|
|||||||
|
|
||||||
type GenericEvent struct {
|
type GenericEvent struct {
|
||||||
// Campi principali
|
// Campi principali
|
||||||
Type string `json:"type"`
|
Type string `yaml:"type"`
|
||||||
Date string `json:"date"`
|
Date string `yaml:"date"`
|
||||||
|
|
||||||
// Altri campi utilizzati ogni tanto
|
// Altri campi utilizzati ogni tanto
|
||||||
Title string `json:"title"`
|
Title string `yaml:"title"`
|
||||||
Description string `json:"description"`
|
Description string `yaml:"description"`
|
||||||
|
|
||||||
// Se il tipo di evento è riferito ad un utente usiamo anche questo campo apposta
|
// Se il tipo di evento è riferito ad un utente usiamo anche questo campo apposta
|
||||||
Uid string `json:"uid"`
|
Uid string `yaml:"uid"`
|
||||||
FullName string `json:"fullName"`
|
FullName string `yaml:"fullName"`
|
||||||
|
|
||||||
// Se il tipo è "spacer" questa è la sua dimensione
|
// Se il tipo è "spacer" questa è la sua dimensione
|
||||||
Size int `json:"size"`
|
Size int `yaml:"size"`
|
||||||
|
|
||||||
// Icona opzionale per il tipo "simple"
|
// Icona opzionale per il tipo "simple"
|
||||||
Icon string `json:"icon"`
|
Icon string `yaml:"icon"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Macchinista struct {
|
type Macchinista struct {
|
||||||
Uid string `json:"uid"`
|
Uid string `yaml:"uid"`
|
||||||
FullName string `json:"fullName"`
|
FullName string `yaml:"fullName"`
|
||||||
EntryDate string `json:"entryDate"`
|
EntryDate string `yaml:"entryDate"`
|
||||||
ExitDate string `json:"exitDate"`
|
ExitDate string `yaml:"exitDate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type storiaDB struct {
|
type storiaDB struct {
|
||||||
Macchinisti []*Macchinista `json:"macchinisti"`
|
Macchinisti []*Macchinista `yaml:"macchinisti"`
|
||||||
GenericEvent []*GenericEvent `json:"eventi"`
|
GenericEvent []*GenericEvent `yaml:"eventi"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type JsonFileStoria struct {
|
type JsonFileStoria struct {
|
||||||
@@ -91,18 +93,29 @@ func (db *JsonFileStoria) GetStoria() ([]*GenericEvent, error) {
|
|||||||
|
|
||||||
sort.Sort(byEventDateDescending(events))
|
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
|
return withSpacers(events), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *JsonFileStoria) GetRawStoria() (*storiaDB, error) {
|
func (db *JsonFileStoria) GetRawStoria() (*storiaDB, error) {
|
||||||
var rawHistory storiaDB
|
var rawHistory storiaDB
|
||||||
|
|
||||||
historyDB, err := os.ReadFile(db.Path)
|
f, err := os.Open(db.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(historyDB, &rawHistory); err != nil {
|
if err := yaml.NewDecoder(f).Decode(&rawHistory); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@@ -23,7 +24,9 @@ func NewCacheTemplate(loadPatterns ...string) *CachedTemplate {
|
|||||||
PreLoadTemplatePatterns: loadPatterns,
|
PreLoadTemplatePatterns: loadPatterns,
|
||||||
cachedTmpl: nil,
|
cachedTmpl: nil,
|
||||||
}
|
}
|
||||||
template.Must(cachedTemplate.Load(template.New("")))
|
|
||||||
|
template.Must(cachedTemplate.Load(nil))
|
||||||
|
|
||||||
return cachedTemplate
|
return cachedTemplate
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +36,11 @@ func (ct *CachedTemplate) Load(t *template.Template) (*template.Template, error)
|
|||||||
return ct.cachedTmpl, nil
|
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 {
|
for _, pattern := range ct.PreLoadTemplatePatterns {
|
||||||
var err error
|
var err error
|
||||||
|
|||||||
Reference in New Issue
Block a user