From 4a13ba939ee3858cb6fa6385782d0e259ba6af3b Mon Sep 17 00:00:00 2001 From: partisan Date: Sat, 24 Aug 2024 19:07:36 +0200 Subject: [PATCH] added /news-assets --- main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.go b/main.go index d961f10..6661b19 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "bytes" "flag" "fmt" "html/template" @@ -106,6 +107,9 @@ func main() { // Serve static files (CSS, JS, etc.) from the /static directory http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir)))) + // Serve files in the /data/news/ directory under /news-assets/ + http.Handle("/news-assets/", http.StripPrefix("/news-assets/", http.FileServer(http.Dir(dataDir+"/news/")))) + // Serve downloads.html at /downloads http.HandleFunc("/download", func(w http.ResponseWriter, r *http.Request) { renderTemplate(w, "download.html", nil) @@ -236,6 +240,8 @@ func renderBlogEntry(w http.ResponseWriter, r *http.Request, blogName string, en htmlContent := blackfriday.Run([]byte(entry.Content)) + htmlContent = bytes.ReplaceAll(htmlContent, []byte("src=\"./"), []byte(fmt.Sprintf("src=\"/news-assets/%d/", entryNumber))) + pageData := PageData{ Title: entry.Title, Date: entry.Date.Format("2006-01-02 15:04"),