Add robots.txt, clean up index template

This commit is contained in:
Ken-Håvard Lieng 2018-11-14 10:11:15 +01:00
parent 764475b2a5
commit 4dcf674c4b
3 changed files with 27 additions and 15 deletions

View File

@ -6,28 +6,29 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#f0f0f0" /> <meta name="theme-color" content="#f0f0f0">
<title>Dispatch</title> <title>Dispatch</title>
<meta name="description" content="Web-based IRC client.">
<% if sw { %> <% if sw { %>
<link rel="preload" href="/data" as="fetch" crossorigin="anonymous" /> <link rel="preload" href="/data" as="fetch" crossorigin>
<% } %> <% } %>
<script> <script>
<%== inlineScript %> <%== inlineScript %>
</script> </script>
<link rel="preload" href="/font/fontello.woff2?48901973" as="font" type="font/woff2" crossorigin="anonymous" /> <link rel="preload" href="/font/fontello.woff2?48901973" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/font/RobotoMono-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous" /> <link rel="preload" href="/font/RobotoMono-Regular.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/font/Montserrat-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous" /> <link rel="preload" href="/font/Montserrat-Regular.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/font/Montserrat-Bold.woff2" as="font" type="font/woff2" crossorigin="anonymous" /> <link rel="preload" href="/font/Montserrat-Bold.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/font/RobotoMono-Bold.woff2" as="font" type="font/woff2" crossorigin="anonymous" /> <link rel="preload" href="/font/RobotoMono-Bold.woff2" as="font" type="font/woff2" crossorigin>
<% if cssPath != "" { %> <% if cssPath != "" { %>
<link href="<%== cssPath %>" rel="stylesheet" /> <link href="<%== cssPath %>" rel="stylesheet">
<% } %> <% } %>
<link rel="manifest" href="/manifest.json"> <link rel="manifest" href="/manifest.json">
@ -43,6 +44,8 @@
<% for _, script := range scripts { %> <% for _, script := range scripts { %>
<script src="<%== script %>"></script> <script src="<%== script %>"></script>
<% } %> <% } %>
<noscript>This page needs JavaScript enabled to function.</noscript>
</body> </body>
</html> </html>

View File

@ -8,17 +8,17 @@ import (
) )
func IndexTemplate(w io.Writer, data *indexData, cssPath string, inlineScript string, scripts []string, sw bool) error { func IndexTemplate(w io.Writer, data *indexData, cssPath string, inlineScript string, scripts []string, sw bool) error {
io.WriteString(w, "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /><meta name=\"theme-color\" content=\"#f0f0f0\" /><title>Dispatch</title>") io.WriteString(w, "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><meta name=\"theme-color\" content=\"#f0f0f0\"><title>Dispatch</title><meta name=\"description\" content=\"Web-based IRC client.\">")
if sw { if sw {
io.WriteString(w, "<link rel=\"preload\" href=\"/data\" as=\"fetch\" crossorigin=\"anonymous\" />") io.WriteString(w, "<link rel=\"preload\" href=\"/data\" as=\"fetch\" crossorigin>")
} }
io.WriteString(w, "<script>") io.WriteString(w, "<script>")
io.WriteString(w, inlineScript ) io.WriteString(w, inlineScript )
io.WriteString(w, "</script><link rel=\"preload\" href=\"/font/fontello.woff2?48901973\" as=\"font\" type=\"font/woff2\" crossorigin=\"anonymous\" /><link rel=\"preload\" href=\"/font/RobotoMono-Regular.woff2\" as=\"font\" type=\"font/woff2\" crossorigin=\"anonymous\" /><link rel=\"preload\" href=\"/font/Montserrat-Regular.woff2\" as=\"font\" type=\"font/woff2\" crossorigin=\"anonymous\" /><link rel=\"preload\" href=\"/font/Montserrat-Bold.woff2\" as=\"font\" type=\"font/woff2\" crossorigin=\"anonymous\" /><link rel=\"preload\" href=\"/font/RobotoMono-Bold.woff2\" as=\"font\" type=\"font/woff2\" crossorigin=\"anonymous\" />") io.WriteString(w, "</script><link rel=\"preload\" href=\"/font/fontello.woff2?48901973\" as=\"font\" type=\"font/woff2\" crossorigin><link rel=\"preload\" href=\"/font/RobotoMono-Regular.woff2\" as=\"font\" type=\"font/woff2\" crossorigin><link rel=\"preload\" href=\"/font/Montserrat-Regular.woff2\" as=\"font\" type=\"font/woff2\" crossorigin><link rel=\"preload\" href=\"/font/Montserrat-Bold.woff2\" as=\"font\" type=\"font/woff2\" crossorigin><link rel=\"preload\" href=\"/font/RobotoMono-Bold.woff2\" as=\"font\" type=\"font/woff2\" crossorigin>")
if cssPath != "" { if cssPath != "" {
io.WriteString(w, "<link href=\"") io.WriteString(w, "<link href=\"")
io.WriteString(w, cssPath ) io.WriteString(w, cssPath )
io.WriteString(w, "\" rel=\"stylesheet\" />") io.WriteString(w, "\" rel=\"stylesheet\">")
} }
io.WriteString(w, "<link rel=\"manifest\" href=\"/manifest.json\"></head><body><div id=\"root\"></div>") io.WriteString(w, "<link rel=\"manifest\" href=\"/manifest.json\"></head><body><div id=\"root\"></div>")
if data != nil { if data != nil {
@ -31,6 +31,6 @@ io.WriteString(w, "<script src=\"")
io.WriteString(w, script ) io.WriteString(w, script )
io.WriteString(w, "\"></script>") io.WriteString(w, "\"></script>")
} }
io.WriteString(w, "</body></html>") io.WriteString(w, "<noscript>This page needs JavaScript enabled to function.</noscript></body></html>")
return nil return nil
} }

View File

@ -69,6 +69,8 @@ var (
".json": "application/json", ".json": "application/json",
} }
robots = []byte("User-agent: *\nDisallow: /")
hstsHeader string hstsHeader string
cspEnabled bool cspEnabled bool
) )
@ -232,6 +234,13 @@ func (d *Dispatch) serveFiles(w http.ResponseWriter, r *http.Request) {
return return
} }
if r.URL.Path == "/robots.txt" {
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Content-Length", strconv.Itoa(len(robots)))
w.Write(robots)
return
}
for _, file := range files { for _, file := range files {
if strings.HasSuffix(r.URL.Path, file.Path) { if strings.HasSuffix(r.URL.Path, file.Path) {
d.serveFile(w, r, file) d.serveFile(w, r, file)