Skip to content

Commit 5ff59de

Browse files
author
mirkobrombin
committed
chore: process Markdown in article loader to improve performance and reduce API overhead
1 parent 6851b35 commit 5ff59de

3 files changed

Lines changed: 4 additions & 7 deletions

File tree

core/handler_article.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"net/http"
1616

1717
"github.com/gorilla/mux"
18-
"github.com/russross/blackfriday/v2"
1918
)
2019

2120
func HandleArticle(w http.ResponseWriter, r *http.Request) {
@@ -39,9 +38,6 @@ func HandleArticle(w http.ResponseWriter, r *http.Request) {
3938
return
4039
}
4140

42-
parsedBody := blackfriday.Run([]byte(result.Body))
43-
result.Body = string(parsedBody)
44-
4541
w.Header().Set("Content-Type", "application/json")
4642

4743
jsonData, err := json.Marshal(result)

core/loader.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"sync"
2222
"time"
2323

24+
"github.com/russross/blackfriday/v2"
2425
"github.com/vanilla-os/Chronos/settings"
2526
"github.com/vanilla-os/Chronos/structs"
2627
"gopkg.in/yaml.v3"
@@ -367,6 +368,8 @@ func loadArticle(repo structs.Repo, path string) (structs.Article, error) {
367368
return structs.Article{}, fmt.Errorf("failed to load story: %v", err)
368369
}
369370

371+
parsedBody := blackfriday.Run([]byte(body))
372+
370373
article := structs.Article{
371374
StoryId: header.StoryId,
372375
Story: story,
@@ -378,7 +381,7 @@ func loadArticle(repo structs.Repo, path string) (structs.Article, error) {
378381
PublicationDate: header.PublicationDate,
379382
Authors: header.Authors,
380383
Tags: header.Tags,
381-
Body: body,
384+
Body: string(parsedBody),
382385
Path: path,
383386
Url: strings.TrimSuffix(path, filepath.Ext(path)),
384387
Slug: slug,

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module github.com/vanilla-os/Chronos
22

33
go 1.22
44

5-
toolchain go1.22.3
6-
75
require (
86
github.com/allegro/bigcache/v3 v3.1.0
97
github.com/dgraph-io/ristretto v0.2.0

0 commit comments

Comments
 (0)