repos / pico

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

commit
e445a79
parent
1395c99
author
Eric Bower
date
2023-03-07 14:38:04 +0000 UTC
feat(prose): support custom favicon

Now bloggers can supply their own favicon inside the `_readme.md`

```
---
favicon: https://zzz.png
favicon: /zzz.png
---
```

If relative paths are supplied we replace it with `imgs.sh`
6 files changed,  +34, -13
M prose/api.go
+6, -0
 1@@ -79,6 +79,7 @@ type PostPageData struct {
 2 	Image        template.URL
 3 	ImageCard    string
 4 	Footer       template.HTML
 5+	Favicon      template.URL
 6 }
 7 
 8 type TransparencyPageData struct {
 9@@ -94,6 +95,7 @@ type HeaderTxt struct {
10 	Layout    string
11 	Image     template.URL
12 	ImageCard string
13+	Favicon   template.URL
14 }
15 
16 type ReadmeTxt struct {
17@@ -208,6 +210,7 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
18 		headerTxt.Layout = parsedText.Layout
19 		headerTxt.Image = template.URL(parsedText.Image)
20 		headerTxt.ImageCard = parsedText.ImageCard
21+		headerTxt.Favicon = template.URL(parsedText.Favicon)
22 		if parsedText.Title != "" {
23 			headerTxt.Title = parsedText.Title
24 		}
25@@ -339,6 +342,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
26 	blogName := GetBlogName(username)
27 	curl := shared.CreateURLFromRequest(cfg, r)
28 
29+	favicon := ""
30 	ogImage := ""
31 	ogImageCard := ""
32 	hasCSS := false
33@@ -363,6 +367,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
34 			}
35 			ogImage = readmeParsed.Image
36 			ogImageCard = readmeParsed.ImageCard
37+			favicon = readmeParsed.Favicon
38 		}
39 
40 		if parsedText.Image != "" {
41@@ -416,6 +421,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
42 			Tags:         parsedText.Tags,
43 			Image:        template.URL(ogImage),
44 			ImageCard:    ogImageCard,
45+			Favicon:      template.URL(favicon),
46 			Footer:       footerHTML,
47 		}
48 	} else {
M prose/html/base.layout.tmpl
+0, -2
1@@ -6,8 +6,6 @@
2         <meta name="viewport" content="width=device-width, initial-scale=1" />
3         <title>{{template "title" .}}</title>
4 
5-        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
6-
7         <meta name="keywords" content="blog, blogging, write, writing" />
8 
9         <link rel="stylesheet" href="/main.css" />
M prose/html/blog.page.tmpl
+6, -0
 1@@ -3,6 +3,12 @@
 2 {{define "title"}}{{.PageTitle}}{{end}}
 3 
 4 {{define "meta"}}
 5+{{if .Header.Favicon}}
 6+<link rel="icon" href="{{.Header.Favicon}}">
 7+{{else}}
 8+<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
 9+{{end}}
10+
11 <meta name="description" content="{{if .Header.Bio}}{{.Header.Bio}}{{else}}{{.Header.Title}}{{end}}" />
12 
13 <meta property="og:type" content="website">
M prose/html/help.page.tmpl
+7, -11
 1@@ -203,6 +203,7 @@ This will show up on the blog landing page.
 2                 <li>nav (key=value pair that corresponds to text=href in html)</li>
 3                 <li>image (og image)</li>
 4                 <li>card (og image twitter card: summary, summary_large_image, etc.)</li>
 5+                <li>favicon</li>
 6             </ul>
 7         </p>
 8     </section>
 9@@ -267,14 +268,9 @@ This will show up on the blog landing page.
10             <a href="#file-types" rel="nofollow noopener">#</a>
11             What file types are supported?
12         </h2>
13-        <ul>
14-            <li>md</li>
15-            <li>jpg</li>
16-            <li>png</li>
17-            <li>gif</li>
18-            <li>webp</li>
19-            <li>svg</li>
20-        </ul>
21+        <p>
22+            <a href="https://imgs.sh/help">see imgs help page</a>
23+        </p>
24     </section>
25 
26     <section id="blog-url">
27@@ -488,13 +484,13 @@ This will show up on the blog landing page.
28                 <tr>
29                     <td>slug</td>
30                     <td>no</td>
31-                    <td>yes</td>
32+                    <td>no</td>
33                 </tr>
34 
35                 <tr>
36                     <td>summary</td>
37                     <td>no</td>
38-                    <td>yes</td>
39+                    <td>no</td>
40                 </tr>
41 
42                 <tr>
43@@ -512,7 +508,7 @@ This will show up on the blog landing page.
44                 <tr>
45                     <td>type</td>
46                     <td>no</td>
47-                    <td>maybe</td>
48+                    <td>no</td>
49                 </tr>
50 
51                 <tr>
M prose/html/post.page.tmpl
+6, -0
 1@@ -3,6 +3,12 @@
 2 {{define "title"}}{{.PageTitle}}{{end}}
 3 
 4 {{define "meta"}}
 5+{{if .Favicon}}
 6+<link rel="icon" href="{{.Favicon}}">
 7+{{else}}
 8+<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
 9+{{end}}
10+
11 <meta name="description" content="{{.Description}}" />
12 
13 <meta property="og:type" content="website">
M shared/mdparser.go
+9, -0
 1@@ -34,6 +34,7 @@ type MetaData struct {
 2 	Layout      string
 3 	Image       string
 4 	ImageCard   string
 5+	Favicon     string
 6 	Hidden      bool
 7 }
 8 
 9@@ -213,9 +214,17 @@ func ParseText(text string, linkify Linkify) (*ParsedText, error) {
10 	} else if strings.HasPrefix(parsed.Image, "./") {
11 		parsed.Image = linkify.Create(parsed.Image[1:])
12 	}
13+
14 	parsed.MetaData.ImageCard = toString(metaData["card"])
15 	parsed.MetaData.Hidden = toBool(metaData["draft"])
16 
17+	parsed.MetaData.Favicon = toString(metaData["favicon"])
18+	if strings.HasPrefix(parsed.Favicon, "/") {
19+		parsed.Favicon = linkify.Create(parsed.Favicon)
20+	} else if strings.HasPrefix(parsed.Favicon, "./") {
21+		parsed.Favicon = linkify.Create(parsed.Favicon[1:])
22+	}
23+
24 	var publishAt *time.Time = nil
25 	var err error
26 	date := toString(metaData["date"])