]> Cypherpunks.ru repositories - gocheese.git/blobdiff - list.go
Move templates to external files
[gocheese.git] / list.go
diff --git a/list.go b/list.go
index 9c4c2912cb65e0d133df894441fa7145087e8b09..f38eab35f83b2f1d8bfde9a995ba1aa313a70bce 100644 (file)
--- a/list.go
+++ b/list.go
@@ -19,6 +19,7 @@ package main
 
 import (
        "bytes"
+       _ "embed"
        "encoding/hex"
        "errors"
        "fmt"
@@ -37,33 +38,14 @@ import (
 
 // https://warehouse.pypa.io/api-reference/legacy.html
 var (
-       HTMLRootTmpl = template.Must(template.New("root").Parse(`<!DOCTYPE html>
-<html>
-  <head>
-    <meta name="pypi:repository-version" content="1.0">
-    <title>Simple index</title>
-  </head>
-  <body>{{$Refresh := .RefreshURLPath}}{{range .Packages}}
-    <a href="{{$Refresh}}{{.}}/">{{.}}</a><br/>
-{{- end}}
-  </body>
-</html>
-`))
-       HTMLReleasesTmpl = template.Must(template.New("list").Parse(`<!DOCTYPE html>
-<html>
-  <head>
-    <meta name="pypi:repository-version" content="1.0">
-    <title>Links for {{.PkgName}}</title>
-  </head>
-  <body>{{$Refresh := .RefreshURLPath}}{{$PkgName := .PkgName}}{{range .Releases}}
-    <a href="{{$Refresh}}{{$PkgName}}/{{.Filename -}}
-        #{{range $a, $d := .Digests}}{{$a}}={{$d}}{{end -}}
-        {{with .HasSig}} data-gpg-sig=true{{end}}">{{.Filename}}</a><br/>
-{{- end}}
-  </body>
-</html>
-`))
-       KnownExts = []string{".tar.bz2", ".tar.gz", ".whl", ".zip", ".egg",
+       //go:embed root.tmpl
+       HTMLRootTmplRaw string
+       HTMLRootTmpl    = template.Must(template.New("root").Parse(HTMLRootTmplRaw))
+
+       //go:embed list.tmpl
+       HTMLReleasesTmplRaw string
+       HTMLReleasesTmpl    = template.Must(template.New("list").Parse(HTMLReleasesTmplRaw))
+       KnownExts           = []string{".tar.bz2", ".tar.gz", ".whl", ".zip", ".egg",
                ".exe", ".dmg", ".msi", ".rpm", ".deb", ".tgz"}
 )