- commit
- b77aa87
- parent
- e594875
- author
- Eric Bower
- date
- 2022-07-29 13:00:56 +0000 UTC
chore: update static paths for template and public files
13 files changed,
+129,
-105
M
go.mod
+0,
-2
1@@ -7,7 +7,6 @@ go 1.18
2 require (
3 git.sr.ht/~adnano/go-gemini v0.2.3
4 git.sr.ht/~aw/gorilla-feeds v1.1.4
5- git.sr.ht/~erock/lists.sh v0.0.0-20220729004305-bc7f4fd43f42
6 github.com/alecthomas/chroma v0.10.0
7 github.com/charmbracelet/bubbles v0.13.0
8 github.com/charmbracelet/bubbletea v0.22.0
9@@ -28,7 +27,6 @@ require (
10 )
11
12 require (
13- git.sr.ht/~erock/wish v0.0.0-20220729004215-0881364c2120 // indirect
14 github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
15 github.com/atotto/clipboard v0.1.4 // indirect
16 github.com/caarlos0/sshmarshal v0.1.0 // indirect
M
go.sum
+1,
-5
1@@ -2,10 +2,6 @@ git.sr.ht/~adnano/go-gemini v0.2.3 h1:oJ+Y0/mheZ4Vg0ABjtf5dlmvq1yoONStiaQvmWWkof
2 git.sr.ht/~adnano/go-gemini v0.2.3/go.mod h1:hQ75Y0i5jSFL+FQ7AzWVAYr5LQsaFC7v3ZviNyj46dY=
3 git.sr.ht/~aw/gorilla-feeds v1.1.4 h1:bL78pZ1DtHEhumHK0iWQi30uwEkWtetMfnyt9TFcdlc=
4 git.sr.ht/~aw/gorilla-feeds v1.1.4/go.mod h1:VLpbtNDEWoaJKU41Crj6r3ChvlqYvBm56c0O6IM457g=
5-git.sr.ht/~erock/lists.sh v0.0.0-20220729004305-bc7f4fd43f42 h1:ZT0cN4f8dXOq5zvXVMfqC8IYjNBVzrmNI1rZMLotAYs=
6-git.sr.ht/~erock/lists.sh v0.0.0-20220729004305-bc7f4fd43f42/go.mod h1:dnJtCor8uSE2ZciYWTOqfhcm5VtzP0uLAaDQw0rfzOk=
7-git.sr.ht/~erock/wish v0.0.0-20220729004215-0881364c2120 h1:9O4PKFF8JGvK9g3aVHr2wgozHK0s6BaVISPRl8MAovs=
8-git.sr.ht/~erock/wish v0.0.0-20220729004215-0881364c2120/go.mod h1:QZKk7m9jc9iXah90daPGhQkSfNfxSVvpb6nfVeI+MM0=
9 github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek=
10 github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s=
11 github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
12@@ -45,8 +41,8 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
13 github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
14 github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
15 github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
16+github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
17 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
18-github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
19 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
20 github.com/lib/pq v1.10.6 h1:jbk+ZieJ0D7EVGJYpL9QTz7/YW6UHbmdnZWYyK5cdBs=
21 github.com/lib/pq v1.10.6/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
+33,
-26
1@@ -10,7 +10,7 @@ import (
2 "strconv"
3 "time"
4
5- "git.sr.ht/~erock/pico/lists.sh/pkg"
6+ "git.sr.ht/~erock/pico/lists/pkg"
7 "git.sr.ht/~erock/pico/wish/cms/db"
8 "git.sr.ht/~erock/pico/wish/cms/db/postgres"
9 "github.com/gorilla/feeds"
10@@ -76,14 +76,14 @@ func isRequestTrackable(r *http.Request) bool {
11 return true
12 }
13
14-func renderTemplate(templates []string) (*template.Template, error) {
15+func renderTemplate(cfg *ConfigSite, templates []string) (*template.Template, error) {
16 files := make([]string, len(templates))
17 copy(files, templates)
18 files = append(
19 files,
20- "./html/footer.partial.tmpl",
21- "./html/marketing-footer.partial.tmpl",
22- "./html/base.layout.tmpl",
23+ cfg.StaticPath("html/footer.partial.tmpl"),
24+ cfg.StaticPath("html/marketing-footer.partial.tmpl"),
25+ cfg.StaticPath("html/base.layout.tmpl"),
26 )
27
28 ts, err := template.ParseFiles(files...)
29@@ -97,7 +97,7 @@ func createPageHandler(fname string) http.HandlerFunc {
30 return func(w http.ResponseWriter, r *http.Request) {
31 logger := GetLogger(r)
32 cfg := GetCfg(r)
33- ts, err := renderTemplate([]string{fname})
34+ ts, err := renderTemplate(cfg, []string{cfg.StaticPath(fname)})
35
36 if err != nil {
37 logger.Error(err)
38@@ -158,9 +158,9 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
39 return
40 }
41
42- ts, err := renderTemplate([]string{
43- "./html/blog.page.tmpl",
44- "./html/list.partial.tmpl",
45+ ts, err := renderTemplate(cfg, []string{
46+ cfg.StaticPath("html/blog.page.tmpl"),
47+ cfg.StaticPath("html/list.partial.tmpl"),
48 })
49
50 if err != nil {
51@@ -331,9 +331,9 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
52 }
53 }
54
55- ts, err := renderTemplate([]string{
56- "./html/post.page.tmpl",
57- "./html/list.partial.tmpl",
58+ ts, err := renderTemplate(cfg, []string{
59+ cfg.StaticPath("html/post.page.tmpl"),
60+ cfg.StaticPath("html/list.partial.tmpl"),
61 })
62
63 if err != nil {
64@@ -360,10 +360,10 @@ func transparencyHandler(w http.ResponseWriter, r *http.Request) {
65 }
66
67 ts, err := template.ParseFiles(
68- "./html/transparency.page.tmpl",
69- "./html/footer.partial.tmpl",
70- "./html/marketing-footer.partial.tmpl",
71- "./html/base.layout.tmpl",
72+ cfg.StaticPath("html/transparency.page.tmpl"),
73+ cfg.StaticPath("html/footer.partial.tmpl"),
74+ cfg.StaticPath("html/marketing-footer.partial.tmpl"),
75+ cfg.StaticPath("html/base.layout.tmpl"),
76 )
77
78 if err != nil {
79@@ -394,8 +394,8 @@ func readHandler(w http.ResponseWriter, r *http.Request) {
80 return
81 }
82
83- ts, err := renderTemplate([]string{
84- "./html/read.page.tmpl",
85+ ts, err := renderTemplate(cfg, []string{
86+ cfg.StaticPath("html/read.page.tmpl"),
87 })
88
89 if err != nil {
90@@ -458,7 +458,10 @@ func rssBlogHandler(w http.ResponseWriter, r *http.Request) {
91 return
92 }
93
94- ts, err := template.ParseFiles("./html/rss.page.tmpl", "./html/list.partial.tmpl")
95+ ts, err := template.ParseFiles(
96+ cfg.StaticPath("html/rss.page.tmpl"),
97+ cfg.StaticPath("html/list.partial.tmpl"),
98+ )
99 if err != nil {
100 logger.Error(err)
101 http.Error(w, err.Error(), http.StatusInternalServerError)
102@@ -549,7 +552,10 @@ func rssHandler(w http.ResponseWriter, r *http.Request) {
103 return
104 }
105
106- ts, err := template.ParseFiles("./html/rss.page.tmpl", "./html/list.partial.tmpl")
107+ ts, err := template.ParseFiles(
108+ cfg.StaticPath("html/rss.page.tmpl"),
109+ cfg.StaticPath("html/list.partial.tmpl"),
110+ )
111 if err != nil {
112 logger.Error(err)
113 http.Error(w, err.Error(), http.StatusInternalServerError)
114@@ -608,8 +614,9 @@ func rssHandler(w http.ResponseWriter, r *http.Request) {
115 func serveFile(file string, contentType string) http.HandlerFunc {
116 return func(w http.ResponseWriter, r *http.Request) {
117 logger := GetLogger(r)
118+ cfg := GetCfg(r)
119
120- contents, err := ioutil.ReadFile(fmt.Sprintf("./public/%s", file))
121+ contents, err := ioutil.ReadFile(cfg.StaticPath(fmt.Sprintf("public/%s", file)))
122 if err != nil {
123 logger.Error(err)
124 http.Error(w, "file not found", 404)
125@@ -638,11 +645,11 @@ func createStaticRoutes() []Route {
126
127 func createMainRoutes(staticRoutes []Route) []Route {
128 routes := []Route{
129- NewRoute("GET", "/", createPageHandler("./html/marketing.page.tmpl")),
130- NewRoute("GET", "/spec", createPageHandler("./html/spec.page.tmpl")),
131- NewRoute("GET", "/ops", createPageHandler("./html/ops.page.tmpl")),
132- NewRoute("GET", "/privacy", createPageHandler("./html/privacy.page.tmpl")),
133- NewRoute("GET", "/help", createPageHandler("./html/help.page.tmpl")),
134+ NewRoute("GET", "/", createPageHandler("html/marketing.page.tmpl")),
135+ NewRoute("GET", "/spec", createPageHandler("html/spec.page.tmpl")),
136+ NewRoute("GET", "/ops", createPageHandler("html/ops.page.tmpl")),
137+ NewRoute("GET", "/privacy", createPageHandler("html/privacy.page.tmpl")),
138+ NewRoute("GET", "/help", createPageHandler("html/help.page.tmpl")),
139 NewRoute("GET", "/transparency", transparencyHandler),
140 NewRoute("GET", "/read", readHandler),
141 }
+5,
-0
1@@ -5,6 +5,7 @@ import (
2 "html/template"
3 "log"
4 "net/url"
5+ "path"
6
7 "git.sr.ht/~erock/pico/wish/cms/config"
8 "go.uber.org/zap"
9@@ -109,6 +110,10 @@ func (c *ConfigSite) ReadURL() string {
10 return "/read"
11 }
12
13+func (c *ConfigSite) StaticPath(fname string) string {
14+ return path.Join(c.Space, fname)
15+}
16+
17 func CreateLogger() *zap.SugaredLogger {
18 logger, err := zap.NewProduction()
19 if err != nil {
+1,
-1
1@@ -5,7 +5,7 @@ import (
2 "io"
3 "time"
4
5- "git.sr.ht/~erock/lists.sh/pkg"
6+ "git.sr.ht/~erock/pico/lists/pkg"
7 "git.sr.ht/~erock/pico/wish/cms/db"
8 "git.sr.ht/~erock/pico/wish/cms/util"
9 sendutils "git.sr.ht/~erock/pico/wish/send/utils"
+32,
-26
1@@ -16,21 +16,21 @@ import (
2 "git.sr.ht/~adnano/go-gemini"
3 "git.sr.ht/~adnano/go-gemini/certificate"
4 feeds "git.sr.ht/~aw/gorilla-feeds"
5- "git.sr.ht/~erock/lists.sh/internal"
6- "git.sr.ht/~erock/lists.sh/pkg"
7+ "git.sr.ht/~erock/pico/lists"
8+ "git.sr.ht/~erock/pico/lists/pkg"
9 "git.sr.ht/~erock/pico/wish/cms/db"
10 "git.sr.ht/~erock/pico/wish/cms/db/postgres"
11 "golang.org/x/exp/slices"
12 )
13
14-func renderTemplate(templates []string) (*template.Template, error) {
15+func renderTemplate(cfg *internal.ConfigSite, templates []string) (*template.Template, error) {
16 files := make([]string, len(templates))
17 copy(files, templates)
18 files = append(
19 files,
20- "./gmi/footer.partial.tmpl",
21- "./gmi/marketing-footer.partial.tmpl",
22- "./gmi/base.layout.tmpl",
23+ cfg.StaticPath("gmi/footer.partial.tmpl"),
24+ cfg.StaticPath("gmi/marketing-footer.partial.tmpl"),
25+ cfg.StaticPath("gmi/base.layout.tmpl"),
26 )
27
28 ts, err := template.ParseFiles(files...)
29@@ -44,7 +44,7 @@ func createPageHandler(fname string) gemini.HandlerFunc {
30 return func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
31 logger := GetLogger(ctx)
32 cfg := GetCfg(ctx)
33- ts, err := renderTemplate([]string{fname})
34+ ts, err := renderTemplate(cfg, []string{cfg.StaticPath(fname)})
35
36 if err != nil {
37 logger.Error(err)
38@@ -82,9 +82,9 @@ func blogHandler(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request
39 return
40 }
41
42- ts, err := renderTemplate([]string{
43- "./gmi/blog.page.tmpl",
44- "./gmi/list.partial.tmpl",
45+ ts, err := renderTemplate(cfg, []string{
46+ cfg.StaticPath("gmi/blog.page.tmpl"),
47+ cfg.StaticPath("gmi/list.partial.tmpl"),
48 })
49
50 if err != nil {
51@@ -167,8 +167,8 @@ func readHandler(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request
52 return
53 }
54
55- ts, err := renderTemplate([]string{
56- "./gmi/read.page.tmpl",
57+ ts, err := renderTemplate(cfg, []string{
58+ cfg.StaticPath("gmi/read.page.tmpl"),
59 })
60
61 if err != nil {
62@@ -286,9 +286,9 @@ func postHandler(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request
63 Items: parsedText.Items,
64 }
65
66- ts, err := renderTemplate([]string{
67- "./gmi/post.page.tmpl",
68- "./gmi/list.partial.tmpl",
69+ ts, err := renderTemplate(cfg, []string{
70+ cfg.StaticPath("gmi/post.page.tmpl"),
71+ cfg.StaticPath("gmi/list.partial.tmpl"),
72 })
73
74 if err != nil {
75@@ -316,10 +316,10 @@ func transparencyHandler(ctx context.Context, w gemini.ResponseWriter, r *gemini
76 }
77
78 ts, err := template.ParseFiles(
79- "./gmi/transparency.page.tmpl",
80- "./gmi/footer.partial.tmpl",
81- "./gmi/marketing-footer.partial.tmpl",
82- "./gmi/base.layout.tmpl",
83+ cfg.StaticPath("gmi/transparency.page.tmpl"),
84+ cfg.StaticPath("gmi/footer.partial.tmpl"),
85+ cfg.StaticPath("gmi/marketing-footer.partial.tmpl"),
86+ cfg.StaticPath("gmi/base.layout.tmpl"),
87 )
88
89 if err != nil {
90@@ -357,7 +357,10 @@ func rssBlogHandler(ctx context.Context, w gemini.ResponseWriter, r *gemini.Requ
91 return
92 }
93
94- ts, err := template.ParseFiles("./gmi/rss.page.tmpl", "./gmi/list.partial.tmpl")
95+ ts, err := template.ParseFiles(
96+ cfg.StaticPath("gmi/rss.page.tmpl"),
97+ cfg.StaticPath("gmi/list.partial.tmpl"),
98+ )
99 if err != nil {
100 logger.Error(err)
101 w.WriteHeader(gemini.StatusTemporaryFailure, err.Error())
102@@ -448,7 +451,10 @@ func rssHandler(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request)
103 return
104 }
105
106- ts, err := template.ParseFiles("./gmi/rss.page.tmpl", "./gmi/list.partial.tmpl")
107+ ts, err := template.ParseFiles(
108+ cfg.StaticPath("gmi/rss.page.tmpl"),
109+ cfg.StaticPath("gmi/list.partial.tmpl"),
110+ )
111 if err != nil {
112 logger.Error(err)
113 w.WriteHeader(gemini.StatusTemporaryFailure, err.Error())
114@@ -518,11 +524,11 @@ func StartServer() {
115 }
116
117 routes := []Route{
118- NewRoute("/", createPageHandler("./gmi/marketing.page.tmpl")),
119- NewRoute("/spec", createPageHandler("./gmi/spec.page.tmpl")),
120- NewRoute("/help", createPageHandler("./gmi/help.page.tmpl")),
121- NewRoute("/ops", createPageHandler("./gmi/ops.page.tmpl")),
122- NewRoute("/privacy", createPageHandler("./gmi/privacy.page.tmpl")),
123+ NewRoute("/", createPageHandler("gmi/marketing.page.tmpl")),
124+ NewRoute("/spec", createPageHandler("gmi/spec.page.tmpl")),
125+ NewRoute("/help", createPageHandler("gmi/help.page.tmpl")),
126+ NewRoute("/ops", createPageHandler("gmi/ops.page.tmpl")),
127+ NewRoute("/privacy", createPageHandler("gmi/privacy.page.tmpl")),
128 NewRoute("/transparency", transparencyHandler),
129 NewRoute("/read", readHandler),
130 NewRoute("/rss", rssHandler),
+1,
-1
1@@ -5,7 +5,7 @@ import (
2 "regexp"
3
4 "git.sr.ht/~adnano/go-gemini"
5- "git.sr.ht/~erock/lists.sh/internal"
6+ "git.sr.ht/~erock/pico/lists"
7 "git.sr.ht/~erock/pico/wish/cms/db"
8 "go.uber.org/zap"
9 )
1@@ -8,7 +8,7 @@
2 <a href="/ops">ops</a> |
3 <a href="/help">help</a> |
4 <a href="/rss">rss</a> |
5- <a href="https://git.sr.ht/~erock/lists.sh">source</a>
6+ <a href="https://git.sr.ht/~erock/pico/lists">source</a>
7 </div>
8 </footer>
9 {{end}}
+20,
-19
1@@ -59,14 +59,14 @@ type TransparencyPageData struct {
2 Analytics *db.Analytics
3 }
4
5-func renderTemplate(templates []string) (*template.Template, error) {
6+func renderTemplate(cfg *ConfigSite, templates []string) (*template.Template, error) {
7 files := make([]string, len(templates))
8 copy(files, templates)
9 files = append(
10 files,
11- "./html/footer.partial.tmpl",
12- "./html/marketing-footer.partial.tmpl",
13- "./html/base.layout.tmpl",
14+ cfg.StaticPath("html/footer.partial.tmpl"),
15+ cfg.StaticPath("html/marketing-footer.partial.tmpl"),
16+ cfg.StaticPath("html/base.layout.tmpl"),
17 )
18
19 ts, err := template.ParseFiles(files...)
20@@ -80,7 +80,7 @@ func createPageHandler(fname string) http.HandlerFunc {
21 return func(w http.ResponseWriter, r *http.Request) {
22 logger := GetLogger(r)
23 cfg := GetCfg(r)
24- ts, err := renderTemplate([]string{fname})
25+ ts, err := renderTemplate(cfg, []string{cfg.StaticPath(fname)})
26
27 if err != nil {
28 logger.Error(err)
29@@ -140,8 +140,8 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
30 return
31 }
32
33- ts, err := renderTemplate([]string{
34- "./html/blog.page.tmpl",
35+ ts, err := renderTemplate(cfg, []string{
36+ cfg.StaticPath("html/blog.page.tmpl"),
37 })
38
39 if err != nil {
40@@ -260,8 +260,8 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
41 }
42 }
43
44- ts, err := renderTemplate([]string{
45- "./html/post.page.tmpl",
46+ ts, err := renderTemplate(cfg, []string{
47+ cfg.StaticPath("html/post.page.tmpl"),
48 })
49
50 if err != nil {
51@@ -321,10 +321,10 @@ func transparencyHandler(w http.ResponseWriter, r *http.Request) {
52 }
53
54 ts, err := template.ParseFiles(
55- "./html/transparency.page.tmpl",
56- "./html/footer.partial.tmpl",
57- "./html/marketing-footer.partial.tmpl",
58- "./html/base.layout.tmpl",
59+ cfg.StaticPath("html/transparency.page.tmpl"),
60+ cfg.StaticPath("html/footer.partial.tmpl"),
61+ cfg.StaticPath("html/marketing-footer.partial.tmpl"),
62+ cfg.StaticPath("html/base.layout.tmpl"),
63 )
64
65 if err != nil {
66@@ -345,8 +345,9 @@ func transparencyHandler(w http.ResponseWriter, r *http.Request) {
67 func serveFile(file string, contentType string) http.HandlerFunc {
68 return func(w http.ResponseWriter, r *http.Request) {
69 logger := GetLogger(r)
70+ cfg := GetCfg(r)
71
72- contents, err := ioutil.ReadFile(fmt.Sprintf("./public/%s", file))
73+ contents, err := ioutil.ReadFile(cfg.StaticPath(fmt.Sprintf("public/%s", file)))
74 if err != nil {
75 logger.Error(err)
76 http.Error(w, "file not found", 404)
77@@ -376,11 +377,11 @@ func createStaticRoutes() []Route {
78
79 func createMainRoutes(staticRoutes []Route) []Route {
80 routes := []Route{
81- NewRoute("GET", "/", createPageHandler("./html/marketing.page.tmpl")),
82- NewRoute("GET", "/spec", createPageHandler("./html/spec.page.tmpl")),
83- NewRoute("GET", "/ops", createPageHandler("./html/ops.page.tmpl")),
84- NewRoute("GET", "/privacy", createPageHandler("./html/privacy.page.tmpl")),
85- NewRoute("GET", "/help", createPageHandler("./html/help.page.tmpl")),
86+ NewRoute("GET", "/", createPageHandler("html/marketing.page.tmpl")),
87+ NewRoute("GET", "/spec", createPageHandler("html/spec.page.tmpl")),
88+ NewRoute("GET", "/ops", createPageHandler("html/ops.page.tmpl")),
89+ NewRoute("GET", "/privacy", createPageHandler("html/privacy.page.tmpl")),
90+ NewRoute("GET", "/help", createPageHandler("html/help.page.tmpl")),
91 NewRoute("GET", "/transparency", transparencyHandler),
92 }
93
+5,
-0
1@@ -5,6 +5,7 @@ import (
2 "html/template"
3 "log"
4 "net/url"
5+ "path"
6
7 "git.sr.ht/~erock/pico/wish/cms/config"
8 "go.uber.org/zap"
9@@ -118,6 +119,10 @@ func (c *ConfigSite) ReadURL() string {
10 return "/read"
11 }
12
13+func (c *ConfigSite) StaticPath(fname string) string {
14+ return path.Join(c.Space, fname)
15+}
16+
17 func CreateLogger() *zap.SugaredLogger {
18 logger, err := zap.NewProduction()
19 if err != nil {
+24,
-23
1@@ -80,14 +80,14 @@ func isRequestTrackable(r *http.Request) bool {
2 return true
3 }
4
5-func renderTemplate(templates []string) (*template.Template, error) {
6+func renderTemplate(cfg *ConfigSite, templates []string) (*template.Template, error) {
7 files := make([]string, len(templates))
8 copy(files, templates)
9 files = append(
10 files,
11- "./html/footer.partial.tmpl",
12- "./html/marketing-footer.partial.tmpl",
13- "./html/base.layout.tmpl",
14+ cfg.StaticPath("html/footer.partial.tmpl"),
15+ cfg.StaticPath("html/marketing-footer.partial.tmpl"),
16+ cfg.StaticPath("html/base.layout.tmpl"),
17 )
18
19 ts, err := template.ParseFiles(files...)
20@@ -101,7 +101,7 @@ func createPageHandler(fname string) http.HandlerFunc {
21 return func(w http.ResponseWriter, r *http.Request) {
22 logger := GetLogger(r)
23 cfg := GetCfg(r)
24- ts, err := renderTemplate([]string{fname})
25+ ts, err := renderTemplate(cfg, []string{cfg.StaticPath(fname)})
26
27 if err != nil {
28 logger.Error(err)
29@@ -200,8 +200,8 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
30 onSubdomain := cfg.IsSubdomains() && strings.Contains(hostDomain, appDomain)
31 withUserName := (!onSubdomain && hostDomain == appDomain) || !cfg.IsCustomdomains()
32
33- ts, err := renderTemplate([]string{
34- "./html/blog.page.tmpl",
35+ ts, err := renderTemplate(cfg, []string{
36+ cfg.StaticPath("html/blog.page.tmpl"),
37 })
38
39 if err != nil {
40@@ -416,8 +416,8 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
41 logger.Infof("post not found %s/%s", username, filename)
42 }
43
44- ts, err := renderTemplate([]string{
45- "./html/post.page.tmpl",
46+ ts, err := renderTemplate(cfg, []string{
47+ cfg.StaticPath("html/post.page.tmpl"),
48 })
49
50 if err != nil {
51@@ -444,10 +444,10 @@ func transparencyHandler(w http.ResponseWriter, r *http.Request) {
52 }
53
54 ts, err := template.ParseFiles(
55- "./html/transparency.page.tmpl",
56- "./html/footer.partial.tmpl",
57- "./html/marketing-footer.partial.tmpl",
58- "./html/base.layout.tmpl",
59+ cfg.StaticPath("html/transparency.page.tmpl"),
60+ cfg.StaticPath("html/footer.partial.tmpl"),
61+ cfg.StaticPath("html/marketing-footer.partial.tmpl"),
62+ cfg.StaticPath("html/base.layout.tmpl"),
63 )
64
65 if err != nil {
66@@ -501,8 +501,8 @@ func readHandler(w http.ResponseWriter, r *http.Request) {
67 return
68 }
69
70- ts, err := renderTemplate([]string{
71- "./html/read.page.tmpl",
72+ ts, err := renderTemplate(cfg, []string{
73+ cfg.StaticPath("html/read.page.tmpl"),
74 })
75
76 if err != nil {
77@@ -566,7 +566,7 @@ func rssBlogHandler(w http.ResponseWriter, r *http.Request) {
78 return
79 }
80
81- ts, err := template.ParseFiles("./html/rss.page.tmpl")
82+ ts, err := template.ParseFiles(cfg.StaticPath("html/rss.page.tmpl"))
83 if err != nil {
84 logger.Error(err)
85 http.Error(w, err.Error(), http.StatusInternalServerError)
86@@ -672,7 +672,7 @@ func rssHandler(w http.ResponseWriter, r *http.Request) {
87 return
88 }
89
90- ts, err := template.ParseFiles("./html/rss.page.tmpl")
91+ ts, err := template.ParseFiles(cfg.StaticPath("html/rss.page.tmpl"))
92 if err != nil {
93 logger.Error(err)
94 http.Error(w, err.Error(), http.StatusInternalServerError)
95@@ -745,8 +745,9 @@ func rssHandler(w http.ResponseWriter, r *http.Request) {
96 func serveFile(file string, contentType string) http.HandlerFunc {
97 return func(w http.ResponseWriter, r *http.Request) {
98 logger := GetLogger(r)
99+ cfg := GetCfg(r)
100
101- contents, err := ioutil.ReadFile(fmt.Sprintf("./public/%s", file))
102+ contents, err := ioutil.ReadFile(cfg.StaticPath(fmt.Sprintf("public/%s", file)))
103 if err != nil {
104 logger.Error(err)
105 http.Error(w, "file not found", 404)
106@@ -776,11 +777,11 @@ func createStaticRoutes() []Route {
107
108 func createMainRoutes(staticRoutes []Route) []Route {
109 routes := []Route{
110- NewRoute("GET", "/", createPageHandler("./html/marketing.page.tmpl")),
111- NewRoute("GET", "/spec", createPageHandler("./html/spec.page.tmpl")),
112- NewRoute("GET", "/ops", createPageHandler("./html/ops.page.tmpl")),
113- NewRoute("GET", "/privacy", createPageHandler("./html/privacy.page.tmpl")),
114- NewRoute("GET", "/help", createPageHandler("./html/help.page.tmpl")),
115+ NewRoute("GET", "/", createPageHandler("html/marketing.page.tmpl")),
116+ NewRoute("GET", "/spec", createPageHandler("html/spec.page.tmpl")),
117+ NewRoute("GET", "/ops", createPageHandler("html/ops.page.tmpl")),
118+ NewRoute("GET", "/privacy", createPageHandler("html/privacy.page.tmpl")),
119+ NewRoute("GET", "/help", createPageHandler("html/help.page.tmpl")),
120 NewRoute("GET", "/transparency", transparencyHandler),
121 NewRoute("GET", "/read", readHandler),
122 NewRoute("GET", "/check", checkHandler),
+5,
-0
1@@ -5,6 +5,7 @@ import (
2 "html/template"
3 "log"
4 "net/url"
5+ "path"
6
7 "git.sr.ht/~erock/pico/wish/cms/config"
8 "go.uber.org/zap"
9@@ -159,6 +160,10 @@ func (c *ConfigSite) CssURL(username string) string {
10 return fmt.Sprintf("/%s/styles.css", username)
11 }
12
13+func (c *ConfigSite) StaticPath(fname string) string {
14+ return path.Join(c.Space, fname)
15+}
16+
17 func CreateLogger() *zap.SugaredLogger {
18 logger, err := zap.NewProduction()
19 if err != nil {
1@@ -7,7 +7,7 @@
2 <a href="/ops">ops</a> |
3 <a href="/help">help</a> |
4 <a href="/rss">rss</a> |
5- <a href="https://git.sr.ht/~erock/prose.sh">source</a>
6+ <a href="https://git.sr.ht/~erock/pico/prose">source</a>
7 </div>
8 </footer>
9 {{end}}