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.
58 lines
1.0 KiB
Go
58 lines
1.0 KiB
Go
2 years ago
|
package articles
|
||
|
|
||
|
import (
|
||
|
"html/template"
|
||
|
"phc/website/services/server/dev"
|
||
|
"phc/website/services/server/router"
|
||
|
"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
|
||
|
}
|