diff options
-rw-r--r-- | Dockerfile.scratch | 1 | ||||
-rw-r--r-- | handler.go | 39 | ||||
-rw-r--r-- | templates/index.html | 37 | ||||
-rw-r--r-- | templates/package.html | 11 |
4 files changed, 61 insertions, 27 deletions
diff --git a/Dockerfile.scratch b/Dockerfile.scratch index f78f304..f6cf130 100644 --- a/Dockerfile.scratch +++ b/Dockerfile.scratch @@ -3,4 +3,5 @@ FROM scratch EXPOSE 8080 ADD sally.yaml / ADD _tmp/sally / +ADD templates /templates ENTRYPOINT ["/sally"] @@ -8,6 +8,18 @@ import ( "github.com/julienschmidt/httprouter" ) +var indexTemplate, packageTemplate *template.Template + +func init() { + tmpls := template.Must(template.ParseGlob("templates/*.html")) + if indexTemplate = tmpls.Lookup("index.html"); indexTemplate == nil { + panic("Missing index.html template") + } + if packageTemplate = tmpls.Lookup("package.html"); packageTemplate == nil { + panic("Missing package.html template") + } +} + // CreateHandler creates a Sally http.Handler func CreateHandler(config *Config) http.Handler { router := httprouter.New() @@ -38,19 +50,6 @@ func (h indexHandler) Handle(w http.ResponseWriter, r *http.Request, _ httproute } } -var indexTemplate = template.Must(template.New("index").Parse(` -<!DOCTYPE html> -<html> - <body> - <ul> - {{ range $key, $value := .Packages }} - <li>{{ $key }} - {{ $value.Repo }}</li> - {{ end }} - </ul> - </body> -</html> -`)) - type packageHandler struct { pkgName string pkg Package @@ -72,17 +71,3 @@ func (h packageHandler) Handle(w http.ResponseWriter, r *http.Request, ps httpro http.Error(w, err.Error(), 500) } } - -var packageTemplate = template.Must(template.New("package").Parse(` -<!DOCTYPE html> -<html> - <head> - <meta name="go-import" content="{{ .CanonicalURL }} git https://{{ .Repo }}"> - <meta name="go-source" content="{{ .CanonicalURL }} https://{{ .Repo }} https://{{ .Repo }}/tree/master{/dir} https://{{ .Repo }}/tree/master{/dir}/{file}#L{line}"> - <meta http-equiv="refresh" content="0; url={{ .GodocURL }}"> - </head> - <body> - Nothing to see here. Please <a href="{{ .GodocURL }}">move along</a>. - </body> -</html> -`)) diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..802996c --- /dev/null +++ b/templates/index.html @@ -0,0 +1,37 @@ +<!DOCTYPE html> +<html> + <head> + <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css" /> + </head> + <body> + <div class="container"> + <div class="row"> + <table class="u-full-width"> + <thead> + <tr> + <th>Package</th> + <th>Source</th> + <th>Documentation</th> + </tr> + </thead> + <tbody> + {{ range $key, $value := .Packages }} + {{ $importPath := printf "%v/%v" $.URL $key }} + <tr> + <td>{{ $importPath }}</td> + <td> + <a href="//{{ $value.Repo }}">{{ $value.Repo }}</a> + </td> + <td> + <a href="//godoc.org/{{ $importPath }}"> + <img src="//godoc.org/{{ $importPath }}?status.svg" alt="GoDoc" /> + </a> + </td> + </tr> + {{ end }} + </tbody> + </table> + </div> + </div> + </body> +</html> diff --git a/templates/package.html b/templates/package.html new file mode 100644 index 0000000..38deaf3 --- /dev/null +++ b/templates/package.html @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<html> + <head> + <meta name="go-import" content="{{ .CanonicalURL }} git https://{{ .Repo }}"> + <meta name="go-source" content="{{ .CanonicalURL }} https://{{ .Repo }} https://{{ .Repo }}/tree/master{/dir} https://{{ .Repo }}/tree/master{/dir}/{file}#L{line}"> + <meta http-equiv="refresh" content="0; url={{ .GodocURL }}"> + </head> + <body> + Nothing to see here. Please <a href="{{ .GodocURL }}">move along</a>. + </body> +</html> |