aboutsummaryrefslogtreecommitdiff
path: root/resources.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-04-06 01:55:21 +0800
committerRunxi Yu <me@runxiyu.org>2025-04-06 02:08:58 +0800
commitfaa5ca8fab23176d390e9522f1485d467851545b (patch)
treed3b1d081e0ea5e7f71a94dc1d301e2540a8abcc8 /resources.go
parentSlight refactor on NewServer (diff)
downloadforge-0.1.28.tar.gz
forge-0.1.28.tar.zst
forge-0.1.28.zip
Move stuff into internal/unsortedv0.1.28
Diffstat (limited to 'resources.go')
-rw-r--r--resources.go63
1 files changed, 0 insertions, 63 deletions
diff --git a/resources.go b/resources.go
deleted file mode 100644
index 514c0ae..0000000
--- a/resources.go
+++ /dev/null
@@ -1,63 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-only
-// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
-
-package forge
-
-import (
- "embed"
- "html/template"
- "io/fs"
-
- "github.com/tdewolff/minify/v2"
- "github.com/tdewolff/minify/v2/html"
- "go.lindenii.runxiyu.org/forge/internal/misc"
-)
-
-//go:embed LICENSE source.tar.gz
-var embeddedSourceFS embed.FS
-
-//go:embed templates/* static/*
-//go:embed hookc/hookc git2d/git2d
-var embeddedResourcesFS embed.FS
-
-// 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(embeddedResourcesFS, "templates", func(path string, d fs.DirEntry, err error) error {
- if err != nil {
- return err
- }
- if !d.IsDir() {
- content, err := fs.ReadFile(embeddedResourcesFS, 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
-}