From 97d7fa96dc49e63122302fe40f64aca998605ae6 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Wed, 22 Jun 2022 23:26:30 -0500 Subject: [PATCH] Render article content very simply (untested) --- src/templates/src/education_article.html | 2 +- src/website/education.go | 37 +++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/templates/src/education_article.html b/src/templates/src/education_article.html index e43f716..5d4c4c9 100644 --- a/src/templates/src/education_article.html +++ b/src/templates/src/education_article.html @@ -1,5 +1,5 @@ {{ template "base.html" . }} {{ define "content" }} - O BOY + {{ .Content }} {{ end }} diff --git a/src/website/education.go b/src/website/education.go index 7e6ae55..c8066d6 100644 --- a/src/website/education.go +++ b/src/website/education.go @@ -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