Render article content very simply (untested)
This commit is contained in:
parent
33352e13b7
commit
97d7fa96dc
|
@ -1,5 +1,5 @@
|
||||||
{{ template "base.html" . }}
|
{{ template "base.html" . }}
|
||||||
|
|
||||||
{{ define "content" }}
|
{{ define "content" }}
|
||||||
O BOY
|
{{ .Content }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
package website
|
package website
|
||||||
|
|
||||||
import "git.handmade.network/hmn/hmn/src/templates"
|
import (
|
||||||
|
"errors"
|
||||||
|
"html/template"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"git.handmade.network/hmn/hmn/src/db"
|
||||||
|
"git.handmade.network/hmn/hmn/src/models"
|
||||||
|
"git.handmade.network/hmn/hmn/src/templates"
|
||||||
|
)
|
||||||
|
|
||||||
func EducationIndex(c *RequestContext) ResponseData {
|
func EducationIndex(c *RequestContext) ResponseData {
|
||||||
type indexData struct {
|
type indexData struct {
|
||||||
|
@ -33,10 +41,37 @@ func EducationGlossary(c *RequestContext) ResponseData {
|
||||||
func EducationArticle(c *RequestContext) ResponseData {
|
func EducationArticle(c *RequestContext) ResponseData {
|
||||||
type articleData struct {
|
type articleData struct {
|
||||||
templates.BaseData
|
templates.BaseData
|
||||||
|
|
||||||
|
Content template.HTML
|
||||||
|
}
|
||||||
|
|
||||||
|
type articleResult struct {
|
||||||
|
Article models.EducationArticle `db:"a"`
|
||||||
|
CurrentVersion models.EducationArticleVersion `db:"v"`
|
||||||
|
}
|
||||||
|
|
||||||
|
article, err := db.QueryOne[articleResult](c.Context(), c.Conn,
|
||||||
|
`
|
||||||
|
SELECT $columns
|
||||||
|
FROM
|
||||||
|
education_article AS a
|
||||||
|
JOIN education_article_version AS v ON a.current_version = v.id
|
||||||
|
WHERE
|
||||||
|
slug = $1
|
||||||
|
AND type = $2
|
||||||
|
`,
|
||||||
|
c.PathParams["slug"],
|
||||||
|
models.EducationArticleTypeArticle,
|
||||||
|
)
|
||||||
|
if errors.Is(err, db.NotFound) {
|
||||||
|
return FourOhFour(c)
|
||||||
|
} else if err != nil {
|
||||||
|
return c.ErrorResponse(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl := articleData{
|
tmpl := articleData{
|
||||||
BaseData: getBaseData(c, "Handmade Education", nil),
|
BaseData: getBaseData(c, "Handmade Education", nil),
|
||||||
|
Content: template.HTML(article.CurrentVersion.ContentHTML),
|
||||||
}
|
}
|
||||||
|
|
||||||
var res ResponseData
|
var res ResponseData
|
||||||
|
|
Loading…
Reference in New Issue