From 095355edeb841fd490353e4b22f9ea3909344260 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sun, 3 Oct 2021 11:21:48 +0300 Subject: [PATCH] Move templates to external files --- go.mod | 2 +- hr-pkg.tmpl | 77 +++++++++++++++++++++++++++++++++++++++++ hr-root.tmpl | 12 +++++++ hr.go | 97 ++++------------------------------------------------ list.go | 36 +++++-------------- list.tmpl | 13 +++++++ root.tmpl | 11 ++++++ 7 files changed, 130 insertions(+), 118 deletions(-) create mode 100644 hr-pkg.tmpl create mode 100644 hr-root.tmpl create mode 100644 list.tmpl create mode 100644 root.tmpl diff --git a/go.mod b/go.mod index fe82390..2d35c1f 100644 --- 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 index 0000000..2f1590d --- /dev/null +++ b/hr-pkg.tmpl @@ -0,0 +1,77 @@ +` + + + {{.Version}}: package {{.PkgName}} + + +
+ {{with .Info.Name}}
Name
{{.}}
{{end}} + {{with .Info.Version}}
Version
{{.}}
{{end}} + + {{with .Info.Platform}}
Platform
    + {{range .}}
  • {{.}}
  • + {{end}}
{{end}} + + {{with .Info.SupportedPlatform}}
SupportedPlatform
    + {{range .}}
  • {{.}}
  • + {{end}}
{{end}} + +
Summary
{{.Info.Summary}}
+
Description
+{{.Info.Description}}
+      
+ + {{with .Info.DescriptionContentType}}
DescriptionContentType
{{.}}
{{end}} + {{with .Info.Keywords}}
Keywords
{{.}}
{{end}} + {{with .Info.HomePage}}
HomePage
{{.}}
{{end}} + {{with .Info.Author}}
Author
{{.}}
{{end}} + {{with .Info.AuthorEmail}}
AuthorEmail
{{.}}
{{end}} + {{with .Info.Maintainer}}
Maintainer
{{.}}
{{end}} + {{with .Info.MaintainerEmail}}
MaintainerEmail
{{.}}
{{end}} + {{with .Info.License}}
License
{{.}}
{{end}} + + {{with .Info.Classifier}}
Classifier
    + {{range .}}
  • {{.}}
  • + {{end}}
{{end}} + + {{with .Info.RequiresDist}}
RequiresDist
    + {{range .}}
  • {{.}}
  • + {{end}}
{{end}} + + {{with .Info.RequiresPython}}
RequiresPython
{{.}}
{{end}} + + {{with .Info.RequiresExternal}}
RequiresExternal
    + {{range .}}
  • {{.}}
  • + {{end}}
{{end}} + + {{with .Info.ProjectURL}}
ProjectURL
    + {{range .}}
  • {{.}}
  • + {{end}}
{{end}} + + {{with .Info.ProvidesExtra}}
ProvidesExtra
    + {{range .}}
  • {{.}}
  • + {{end}}
{{end}} +
+ +

Releases

+ + + + + + + + + {{range .Releases}}{{if .Size}} + + + {{end}}{{end}} +
FilenameVersionUploadedSizeDigests
{{.Filename}} + {{.Version}} + {{.UploadTimeISO8601}} + {{.Size}} +
    {{range $a, $d := .Digests}} +
  • {{$a}}: {{$d}}
  • + {{end}}
+ + diff --git a/hr-root.tmpl b/hr-root.tmpl new file mode 100644 index 0000000..ce59f5b --- /dev/null +++ b/hr-root.tmpl @@ -0,0 +1,12 @@ + + + + {{.Version}}: packages + + + + + diff --git a/hr.go b/hr.go index b751e4d..64c8335 100644 --- 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(` - - - {{.Version}}: packages - - - - - -`)) - HRPkgTmpl = template.Must(template.New("hr-pkg").Parse(` - - - {{.Version}}: package {{.PkgName}} - - -
- {{with .Info.Name}}
Name
{{.}}
{{end}} - {{with .Info.Version}}
Version
{{.}}
{{end}} + //go:embed hr-root.tmpl + HRRootTmplRaw string + HRRootTmpl = template.Must(template.New("hr-root").Parse(HRRootTmplRaw)) - {{with .Info.Platform}}
Platform
    - {{range .}}
  • {{.}}
  • - {{end}}
{{end}} - - {{with .Info.SupportedPlatform}}
SupportedPlatform
    - {{range .}}
  • {{.}}
  • - {{end}}
{{end}} - -
Summary
{{.Info.Summary}}
-
Description
-{{.Info.Description}}
-      
- - {{with .Info.DescriptionContentType}}
DescriptionContentType
{{.}}
{{end}} - {{with .Info.Keywords}}
Keywords
{{.}}
{{end}} - {{with .Info.HomePage}}
HomePage
{{.}}
{{end}} - {{with .Info.Author}}
Author
{{.}}
{{end}} - {{with .Info.AuthorEmail}}
AuthorEmail
{{.}}
{{end}} - {{with .Info.Maintainer}}
Maintainer
{{.}}
{{end}} - {{with .Info.MaintainerEmail}}
MaintainerEmail
{{.}}
{{end}} - {{with .Info.License}}
License
{{.}}
{{end}} - - {{with .Info.Classifier}}
Classifier
    - {{range .}}
  • {{.}}
  • - {{end}}
{{end}} - - {{with .Info.RequiresDist}}
RequiresDist
    - {{range .}}
  • {{.}}
  • - {{end}}
{{end}} - - {{with .Info.RequiresPython}}
RequiresPython
{{.}}
{{end}} - - {{with .Info.RequiresExternal}}
RequiresExternal
    - {{range .}}
  • {{.}}
  • - {{end}}
{{end}} - - {{with .Info.ProjectURL}}
ProjectURL
    - {{range .}}
  • {{.}}
  • - {{end}}
{{end}} - - {{with .Info.ProvidesExtra}}
ProvidesExtra
    - {{range .}}
  • {{.}}
  • - {{end}}
{{end}} -
- -

Releases

- - - - - - - - - {{range .Releases}}{{if .Size}} - - - {{end}}{{end}} -
FilenameVersionUploadedSizeDigests
{{.Filename}} - {{.Version}} - {{.UploadTimeISO8601}} - {{.Size}} -
    {{range $a, $d := .Digests}} -
  • {{$a}}: {{$d}}
  • - {{end}}
- - -`)) + //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 9c4c291..f38eab3 100644 --- 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(` - - - - Simple index - - {{$Refresh := .RefreshURLPath}}{{range .Packages}} - {{.}}
-{{- end}} - - -`)) - HTMLReleasesTmpl = template.Must(template.New("list").Parse(` - - - - Links for {{.PkgName}} - - {{$Refresh := .RefreshURLPath}}{{$PkgName := .PkgName}}{{range .Releases}} - {{.Filename}}
-{{- end}} - - -`)) - 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 index 0000000..a3f40ac --- /dev/null +++ b/list.tmpl @@ -0,0 +1,13 @@ + + + + + Links for {{.PkgName}} + + {{$Refresh := .RefreshURLPath}}{{$PkgName := .PkgName}}{{range .Releases}} + {{.Filename}}
+{{- end}} + + diff --git a/root.tmpl b/root.tmpl new file mode 100644 index 0000000..630fa32 --- /dev/null +++ b/root.tmpl @@ -0,0 +1,11 @@ + + + + + Simple index + + {{$Refresh := .RefreshURLPath}}{{range .Packages}} + {{.}}
+{{- end}} + + -- 2.44.0