adding summarization and restructure project

This commit is contained in:
2025-01-09 23:36:12 +01:00
parent 706ebe25a0
commit 38d4f1ad38
28 changed files with 579 additions and 209 deletions

View File

@@ -0,0 +1,31 @@
package main
import (
"crowsnest/internal/model"
"html/template"
"net/http"
)
// List the latest articles using the base template.
func (app *App) Index(w http.ResponseWriter, req *http.Request) {
// get articles
articles, err := app.articles.All(30)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// convert to viewmodel
articleVMs := make([]*model.ArticleViewModel, 0, len(articles))
for _, a := range articles {
articleVMs = append(articleVMs, a.ViewModel())
}
// render template
t := template.Must(template.ParseFiles("assets/templates/article.html", "assets/templates/layout.html"))
err = t.ExecuteTemplate(w, "base", articleVMs)
if err != nil {
http.Error(w, "Failed to render template", http.StatusInternalServerError)
return
}
}