diff options
author | Runxi Yu <me@runxiyu.org> | 2025-04-06 09:26:46 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-04-06 09:27:53 +0800 |
commit | da1d8f4e7c332c7109427915e6459b10209cedce (patch) | |
tree | 280b921be3b51f93d82d916b4eaa89387b7102cc /internal/unsorted/resources.go | |
parent | git2c, git2d: Rename cmd1 and cmd2 descriptively (diff) | |
download | forge-da1d8f4e7c332c7109427915e6459b10209cedce.tar.gz forge-da1d8f4e7c332c7109427915e6459b10209cedce.tar.zst forge-da1d8f4e7c332c7109427915e6459b10209cedce.zip |
Move the Go stuff to ./forged/v0.1.32
Diffstat (limited to 'internal/unsorted/resources.go')
-rw-r--r-- | internal/unsorted/resources.go | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/internal/unsorted/resources.go b/internal/unsorted/resources.go deleted file mode 100644 index d09ee60..0000000 --- a/internal/unsorted/resources.go +++ /dev/null @@ -1,56 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only -// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> - -package unsorted - -import ( - "html/template" - "io/fs" - - "github.com/tdewolff/minify/v2" - "github.com/tdewolff/minify/v2/html" - "go.lindenii.runxiyu.org/forge/internal/embed" - "go.lindenii.runxiyu.org/forge/internal/misc" -) - -// loadTemplates minifies and loads HTML templates. -func (s *Server) loadTemplates() (err error) { - minifier := minify.New() - minifierOptions := html.Minifier{ - TemplateDelims: [2]string{"{{", "}}"}, - KeepDefaultAttrVals: true, - } //exhaustruct:ignore - minifier.Add("text/html", &minifierOptions) - - s.templates = template.New("templates").Funcs(template.FuncMap{ - "first_line": misc.FirstLine, - "path_escape": misc.PathEscape, - "query_escape": misc.QueryEscape, - "dereference_error": misc.DereferenceOrZero[error], - "minus": misc.Minus, - }) - - err = fs.WalkDir(embed.Resources, "templates", func(path string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - if !d.IsDir() { - content, err := fs.ReadFile(embed.Resources, path) - if err != nil { - return err - } - - minified, err := minifier.Bytes("text/html", content) - if err != nil { - return err - } - - _, err = s.templates.Parse(misc.BytesToString(minified)) - if err != nil { - return err - } - } - return nil - }) - return err -} |