You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package articles
|
|
|
|
import (
|
|
"html/template"
|
|
|
|
"git.phc.dm.unipi.it/phc/website/services/server/dev"
|
|
"git.phc.dm.unipi.it/phc/website/services/server/router"
|
|
"git.phc.dm.unipi.it/phc/website/sl"
|
|
)
|
|
|
|
func Configure(l *sl.ServiceLocator) error {
|
|
router.UseRouteTemplatedPage(l, "/articles",
|
|
"pages/articles/index.html",
|
|
func(w dev.ResponseWriter, r dev.Request) error {
|
|
tmpl := template.New("")
|
|
|
|
tmpl, err := tmpl.Parse(string(r.Page()))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
ctx := map[string]any{
|
|
"Example": "Bla bla",
|
|
}
|
|
|
|
if err := tmpl.Execute(w, ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
},
|
|
)
|
|
|
|
router.UseRouteTemplatedPage(l, "/articles/:slug",
|
|
"pages/articles/article.html",
|
|
func(w dev.ResponseWriter, r dev.Request) error {
|
|
tmpl := template.New("")
|
|
|
|
tmpl, err := tmpl.Parse(string(r.Page()))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
ctx := map[string]any{
|
|
"Title": r.Param("slug"),
|
|
"Example": "Bla bla " + r.Param("slug"),
|
|
}
|
|
|
|
if err := tmpl.Execute(w, ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
},
|
|
)
|
|
|
|
return nil
|
|
}
|