forked from brunoluiz/urlzap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.go
More file actions
36 lines (31 loc) · 751 Bytes
/
generate.go
File metadata and controls
36 lines (31 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package urlzap
import (
"context"
"text/template"
)
type redirectHTMLArgs struct {
Title string
URL string
MetaTags []string
}
const redirectHTMLTemplate = `<!DOCTYPE html>
<html>
<head>
<title>{{.Title}}</title>
<link rel="canonical" href="{{.URL}}"/>
<meta name="robots" content="noindex">
<meta charset="utf-8" />
<meta http-equiv="refresh" content="0; url={{.URL}}" />
{{ range $key, $value := .MetaTags }}
{{ $value }}{{ end }}
</head>
</html>
`
// Generate generate static files with HTML redirects
func Generate(ctx context.Context, c Config) error {
tmpl, err := template.New("redirect").Parse(redirectHTMLTemplate)
if err != nil {
return err
}
return Read(ctx, "", c.URLs, HTMLFileCallback(c, tmpl))
}