From 610bb017c13357a84433b45a65b609460d92ff80 Mon Sep 17 00:00:00 2001 From: Streamlet Date: Fri, 10 Nov 2023 17:40:38 +0800 Subject: [PATCH] do not translate assets files --- note/router.go | 10 ++++++++-- note/translator/default.go | 4 ++-- note/translator/text.go | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/note/router.go b/note/router.go index 98f5340..e0d8116 100644 --- a/note/router.go +++ b/note/router.go @@ -282,8 +282,14 @@ func (n *node) GetContent() ([]byte, error) { pageData.BasicItem = item } if n.subItems == nil { - t := translator.New(n.absolutePath) - content, err := t.Translate() + var content []byte + var err error + if n.isNote { + t := translator.New(n.absolutePath) + content, err = t.Translate() + } else { + content, err = os.ReadFile(n.absolutePath) + } if err != nil { if os.IsNotExist(err) { return n.templateExecutor.Get404(), err diff --git a/note/translator/default.go b/note/translator/default.go index 2c81da3..bd73fad 100644 --- a/note/translator/default.go +++ b/note/translator/default.go @@ -1,6 +1,6 @@ package translator -import "io/ioutil" +import "os" type defaultTranslator struct { path string @@ -13,5 +13,5 @@ func newDefaultTranslator(path string) *defaultTranslator { } func (t defaultTranslator) Translate() ([]byte, error) { - return ioutil.ReadFile(t.path) + return os.ReadFile(t.path) } diff --git a/note/translator/text.go b/note/translator/text.go index 9724ff4..a3ce3cf 100644 --- a/note/translator/text.go +++ b/note/translator/text.go @@ -2,7 +2,7 @@ package translator import ( "bytes" - "io/ioutil" + "os" ) type textTranslator struct { @@ -16,7 +16,7 @@ func newTextTranslator(path string) *textTranslator { } func (t textTranslator) Translate() ([]byte, error) { - content, err := ioutil.ReadFile(t.path) + content, err := os.ReadFile(t.path) if err != nil { return nil, err }