Render article content very simply (untested)

This commit is contained in:
Ben Visness 2022-06-22 23:26:30 -05:00
parent 33352e13b7
commit 97d7fa96dc
2 changed files with 37 additions and 2 deletions

View File

@ -1,5 +1,5 @@
{{ template "base.html" . }}
{{ define "content" }}
O BOY
{{ .Content }}
{{ end }}

View File

@ -1,6 +1,14 @@
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 {
type indexData struct {
@ -33,10 +41,37 @@ func EducationGlossary(c *RequestContext) ResponseData {
func EducationArticle(c *RequestContext) ResponseData {
type articleData struct {
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{
BaseData: getBaseData(c, "Handmade Education", nil),
Content: template.HTML(article.CurrentVersion.ContentHTML),
}
var res ResponseData