]> Cypherpunks.ru repositories - gocheese.git/commitdiff
Move templates to external files
authorSergey Matveev <stargrave@stargrave.org>
Sun, 3 Oct 2021 08:21:48 +0000 (11:21 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 3 Oct 2021 08:21:48 +0000 (11:21 +0300)
go.mod
hr-pkg.tmpl [new file with mode: 0644]
hr-root.tmpl [new file with mode: 0644]
hr.go
list.go
list.tmpl [new file with mode: 0644]
root.tmpl [new file with mode: 0644]

diff --git a/go.mod b/go.mod
index fe8239028d07f357fd1dd40505eb4a7850f3ea9b..2d35c1f441ed201eba4100262022c2f1df8ac798 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
 module go.cypherpunks.ru/gocheese/v3
 
-go 1.12
+go 1.16
 
 require (
        go.cypherpunks.ru/recfile v0.4.3
diff --git a/hr-pkg.tmpl b/hr-pkg.tmpl
new file mode 100644 (file)
index 0000000..2f1590d
--- /dev/null
@@ -0,0 +1,77 @@
+`<!DOCTYPE html>
+<html>
+  <head>
+    <title>{{.Version}}: package {{.PkgName}}</title>
+  </head>
+  <body>
+    <dl>
+      {{with .Info.Name}}<dt>Name</dt><dd>{{.}}</dd>{{end}}
+      {{with .Info.Version}}<dt>Version</dt><dd>{{.}}</dd>{{end}}
+
+      {{with .Info.Platform}}<dt>Platform</dt><dd><ul>
+      {{range .}}<li>{{.}}</li>
+      {{end}}</ul></dd>{{end}}
+
+      {{with .Info.SupportedPlatform}}<dt>SupportedPlatform</dt><dd><ul>
+      {{range .}}<li>{{.}}</li>
+      {{end}}</ul></dd>{{end}}
+
+      <dt>Summary</dt><dd>{{.Info.Summary}}</dd>
+      <dt>Description</dt><dd><pre>
+{{.Info.Description}}
+      </pre></dd>
+
+      {{with .Info.DescriptionContentType}}<dt>DescriptionContentType</dt><dd>{{.}}</dd>{{end}}
+      {{with .Info.Keywords}}<dt>Keywords</dt><dd>{{.}}</dd>{{end}}
+      {{with .Info.HomePage}}<dt>HomePage</dt><dd>{{.}}</dd>{{end}}
+      {{with .Info.Author}}<dt>Author</dt><dd>{{.}}</dd>{{end}}
+      {{with .Info.AuthorEmail}}<dt>AuthorEmail</dt><dd>{{.}}</dd>{{end}}
+      {{with .Info.Maintainer}}<dt>Maintainer</dt><dd>{{.}}</dd>{{end}}
+      {{with .Info.MaintainerEmail}}<dt>MaintainerEmail</dt><dd>{{.}}</dd>{{end}}
+      {{with .Info.License}}<dt>License</dt><dd>{{.}}</dd>{{end}}
+
+      {{with .Info.Classifier}}<dt>Classifier</dt><dd><ul>
+      {{range .}}<li>{{.}}</li>
+      {{end}}</ul></dd>{{end}}
+
+      {{with .Info.RequiresDist}}<dt>RequiresDist</dt><dd><ul>
+      {{range .}}<li>{{.}}</li>
+      {{end}}</ul></dd>{{end}}
+
+      {{with .Info.RequiresPython}}<dt>RequiresPython</dt><dd>{{.}}</dd>{{end}}
+
+      {{with .Info.RequiresExternal}}<dt>RequiresExternal</dt><dd><ul>
+      {{range .}}<li>{{.}}</li>
+      {{end}}</ul></dd>{{end}}
+
+      {{with .Info.ProjectURL}}<dt>ProjectURL</dt><dd><ul>
+      {{range .}}<li>{{.}}</li>
+      {{end}}</ul></dd>{{end}}
+
+      {{with .Info.ProvidesExtra}}<dt>ProvidesExtra</dt><dd><ul>
+      {{range .}}<li>{{.}}</li>
+      {{end}}</ul></dd>{{end}}
+    </dl>
+
+    <h2>Releases</h2>
+    <table border=1>
+    <tr>
+      <th>Filename</th>
+      <th>Version</th>
+      <th>Uploaded</th>
+      <th>Size</th>
+      <th>Digests</th>
+    </tr>
+    {{range .Releases}}{{if .Size}}
+    <tr>
+      <td>{{.Filename}}</th>
+      <td>{{.Version}}</th>
+      <td>{{.UploadTimeISO8601}}</th>
+      <td>{{.Size}}</th>
+      <td><ul>{{range $a, $d := .Digests}}
+        <li>{{$a}}: <tt>{{$d}}</tt></li>
+      {{end}}</ul></td>
+    </tr>{{end}}{{end}}
+    </table>
+  </body>
+</html>
diff --git a/hr-root.tmpl b/hr-root.tmpl
new file mode 100644 (file)
index 0000000..ce59f5b
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>{{.Version}}: packages</title>
+  </head>
+  <body>
+    <ul>{{range .Packages}}
+      <li><a href="/hr/{{.}}/">{{.}}</a></li>
+{{- end}}
+    </ul>
+  </body>
+</html>
diff --git a/hr.go b/hr.go
index b751e4dd2ccd9aae55c33fdc8ddf3bcbc7caf928..64c83355f98676e561b8c6b10d94f5641d31dd3a 100644 (file)
--- a/hr.go
+++ b/hr.go
@@ -19,6 +19,7 @@ package main
 
 import (
        "bytes"
+       _ "embed"
        "html/template"
        "io/ioutil"
        "log"
@@ -29,97 +30,13 @@ import (
 )
 
 var (
-       HRRootTmpl = template.Must(template.New("hr-root").Parse(`<!DOCTYPE html>
-<html>
-  <head>
-    <title>{{.Version}}: packages</title>
-  </head>
-  <body>
-    <ul>{{range .Packages}}
-      <li><a href="/hr/{{.}}/">{{.}}</a></li>
-{{- end}}
-    </ul>
-  </body>
-</html>
-`))
-       HRPkgTmpl = template.Must(template.New("hr-pkg").Parse(`<!DOCTYPE html>
-<html>
-  <head>
-    <title>{{.Version}}: package {{.PkgName}}</title>
-  </head>
-  <body>
-    <dl>
-      {{with .Info.Name}}<dt>Name</dt><dd>{{.}}</dd>{{end}}
-      {{with .Info.Version}}<dt>Version</dt><dd>{{.}}</dd>{{end}}
+       //go:embed hr-root.tmpl
+       HRRootTmplRaw string
+       HRRootTmpl    = template.Must(template.New("hr-root").Parse(HRRootTmplRaw))
 
-      {{with .Info.Platform}}<dt>Platform</dt><dd><ul>
-      {{range .}}<li>{{.}}</li>
-      {{end}}</ul></dd>{{end}}
-
-      {{with .Info.SupportedPlatform}}<dt>SupportedPlatform</dt><dd><ul>
-      {{range .}}<li>{{.}}</li>
-      {{end}}</ul></dd>{{end}}
-
-      <dt>Summary</dt><dd>{{.Info.Summary}}</dd>
-      <dt>Description</dt><dd><pre>
-{{.Info.Description}}
-      </pre></dd>
-
-      {{with .Info.DescriptionContentType}}<dt>DescriptionContentType</dt><dd>{{.}}</dd>{{end}}
-      {{with .Info.Keywords}}<dt>Keywords</dt><dd>{{.}}</dd>{{end}}
-      {{with .Info.HomePage}}<dt>HomePage</dt><dd>{{.}}</dd>{{end}}
-      {{with .Info.Author}}<dt>Author</dt><dd>{{.}}</dd>{{end}}
-      {{with .Info.AuthorEmail}}<dt>AuthorEmail</dt><dd>{{.}}</dd>{{end}}
-      {{with .Info.Maintainer}}<dt>Maintainer</dt><dd>{{.}}</dd>{{end}}
-      {{with .Info.MaintainerEmail}}<dt>MaintainerEmail</dt><dd>{{.}}</dd>{{end}}
-      {{with .Info.License}}<dt>License</dt><dd>{{.}}</dd>{{end}}
-
-      {{with .Info.Classifier}}<dt>Classifier</dt><dd><ul>
-      {{range .}}<li>{{.}}</li>
-      {{end}}</ul></dd>{{end}}
-
-      {{with .Info.RequiresDist}}<dt>RequiresDist</dt><dd><ul>
-      {{range .}}<li>{{.}}</li>
-      {{end}}</ul></dd>{{end}}
-
-      {{with .Info.RequiresPython}}<dt>RequiresPython</dt><dd>{{.}}</dd>{{end}}
-
-      {{with .Info.RequiresExternal}}<dt>RequiresExternal</dt><dd><ul>
-      {{range .}}<li>{{.}}</li>
-      {{end}}</ul></dd>{{end}}
-
-      {{with .Info.ProjectURL}}<dt>ProjectURL</dt><dd><ul>
-      {{range .}}<li>{{.}}</li>
-      {{end}}</ul></dd>{{end}}
-
-      {{with .Info.ProvidesExtra}}<dt>ProvidesExtra</dt><dd><ul>
-      {{range .}}<li>{{.}}</li>
-      {{end}}</ul></dd>{{end}}
-    </dl>
-
-    <h2>Releases</h2>
-    <table border=1>
-    <tr>
-      <th>Filename</th>
-      <th>Version</th>
-      <th>Uploaded</th>
-      <th>Size</th>
-      <th>Digests</th>
-    </tr>
-    {{range .Releases}}{{if .Size}}
-    <tr>
-      <td>{{.Filename}}</th>
-      <td>{{.Version}}</th>
-      <td>{{.UploadTimeISO8601}}</th>
-      <td>{{.Size}}</th>
-      <td><ul>{{range $a, $d := .Digests}}
-        <li>{{$a}}: <tt>{{$d}}</tt></li>
-      {{end}}</ul></td>
-    </tr>{{end}}{{end}}
-    </table>
-  </body>
-</html>
-`))
+       //go:embed hr-pkg.tmpl
+       HRPkgTmplRaw string
+       HRPkgTmpl    = template.Must(template.New("hr-pkg").Parse(HRPkgTmplRaw))
 )
 
 func serveHRRoot(w http.ResponseWriter, r *http.Request) {
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"}
 )
 
diff --git a/list.tmpl b/list.tmpl
new file mode 100644 (file)
index 0000000..a3f40ac
--- /dev/null
+++ b/list.tmpl
@@ -0,0 +1,13 @@
+<!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>
diff --git a/root.tmpl b/root.tmpl
new file mode 100644 (file)
index 0000000..630fa32
--- /dev/null
+++ b/root.tmpl
@@ -0,0 +1,11 @@
+<!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>