repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
80b3c18
parent
9197ebd
author
Eric Bower
date
2022-08-31 01:01:55 +0000 UTC
feat(prose): special _footer.md appends all posts

This allows users to be able to upload a special "hidden" file that will
be appended to every post.  The intention is to use this as a regular
call-to-action like an email address for feedback.
4 files changed,  +43, -3
M prose/api.go
+24, -2
 1@@ -79,6 +79,7 @@ type PostPageData struct {
 2 	Tags         []string
 3 	Image        template.URL
 4 	ImageCard    string
 5+	Footer       template.HTML
 6 }
 7 
 8 type TransparencyPageData struct {
 9@@ -382,7 +383,6 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
10 			ogImageCard = parsedText.ImageCard
11 		}
12 
13-		// we need the blog name from the readme unfortunately
14 		css, err := dbpool.FindPostWithFilename("_styles.css", user.ID, cfg.Space)
15 		if err == nil {
16 			if len(css.Text) > 0 {
17@@ -390,6 +390,16 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
18 			}
19 		}
20 
21+		footer, err := dbpool.FindPostWithFilename("_footer.md", user.ID, cfg.Space)
22+		var footerHTML template.HTML
23+		if err == nil {
24+			footerParsed, err := shared.ParseText(footer.Text, linkify)
25+			if err != nil {
26+				logger.Error(err)
27+			}
28+			footerHTML = template.HTML(footerParsed.Html)
29+		}
30+
31 		// validate and fire off analytic event
32 		if isRequestTrackable(r) {
33 			_, err := dbpool.AddViewCount(post.ID)
34@@ -416,6 +426,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
35 			Tags:         parsedText.Tags,
36 			Image:        template.URL(ogImage),
37 			ImageCard:    ogImageCard,
38+			Footer:       footerHTML,
39 		}
40 	} else {
41 		data = PostPageData{
42@@ -644,9 +655,20 @@ func rssBlogHandler(w http.ResponseWriter, r *http.Request) {
43 		if err != nil {
44 			logger.Error(err)
45 		}
46+
47+		footer, err := dbpool.FindPostWithFilename("_footer.md", user.ID, cfg.Space)
48+		var footerHTML string
49+		if err == nil {
50+			footerParsed, err := shared.ParseText(footer.Text, linkify)
51+			if err != nil {
52+				logger.Error(err)
53+			}
54+			footerHTML = footerParsed.Html
55+		}
56+
57 		var tpl bytes.Buffer
58 		data := &PostPageData{
59-			Contents: template.HTML(parsed.Html),
60+			Contents: template.HTML(parsed.Html + footerHTML),
61 		}
62 		if err := ts.Execute(&tpl, data); err != nil {
63 			continue
M prose/config.go
+1, -1
1@@ -53,7 +53,7 @@ func NewConfigSite() *shared.ConfigSite {
2 			IntroText:     intro,
3 			Space:         "prose",
4 			AllowedExt:    []string{".md"},
5-			HiddenPosts:   []string{"_readme.md", "_styles.css"},
6+			HiddenPosts:   []string{"_readme.md", "_styles.css", "_footer.md"},
7 			Logger:        shared.CreateLogger(),
8 			AllowRegister: allowRegister == "1",
9 		},
M prose/html/help.page.tmpl
+17, -0
 1@@ -108,6 +108,23 @@ date: 2022-06-28
 2         </p>
 3     </section>
 4 
 5+    <section id="post-footer">
 6+        <h2 class="text-xl">
 7+            <a href="#post-footer" rel="nofollow noopener">#</a>
 8+            How can I add a footer to all of my posts?
 9+        </h2>
10+        <p>
11+            We have a special file <code>_footer.md</code> that will be appended to every
12+            single blog post.
13+
14+        </p>
15+        <p>
16+            There is nothing that differentiates itself from the rest of the
17+            post so it's up to you to style it.  For convenience we added an <code>id</code> to the
18+            containing element <code>post-footer</code>.
19+        </p>
20+    </section>
21+
22     <section id="post-update">
23         <h2 class="text-xl">
24             <a href="#post-update" rel="nofollow noopener">#</a>
M prose/html/post.page.tmpl
+1, -0
1@@ -57,6 +57,7 @@
2 <main>
3     <article class="md">
4         {{.Contents}}
5+        <div id="post-footer">{{.Footer}}</div>
6     </article>
7 </main>
8 {{template "footer" .}}