repos / pico

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

commit
2fe9e19
parent
0751d5d
author
Eric Bower
date
2022-08-27 01:55:35 +0000 UTC
feat: support for different blog page layouts

"default" and "aside" are currently supported by adding `layout` in the
_readme.md frontmatter
11 files changed,  +180, -37
M imgs/public/main.css
+8, -0
 1@@ -293,6 +293,14 @@ figure {
 2   margin-bottom: 0.5rem;
 3 }
 4 
 5+.mr {
 6+  margin-right: 0.5rem;
 7+}
 8+
 9+.ml {
10+  margin-left: 0.5rem;
11+}
12+
13 .my {
14   margin-top: 0.5rem;
15   margin-bottom: 0.5rem;
M lists/public/main.css
+8, -0
 1@@ -293,6 +293,14 @@ figure {
 2   margin-bottom: 0.5rem;
 3 }
 4 
 5+.mr {
 6+  margin-right: 0.5rem;
 7+}
 8+
 9+.ml {
10+  margin-left: 0.5rem;
11+}
12+
13 .my {
14   margin-top: 0.5rem;
15   margin-bottom: 0.5rem;
M pastes/public/main.css
+8, -0
 1@@ -293,6 +293,14 @@ figure {
 2   margin-bottom: 0.5rem;
 3 }
 4 
 5+.mr {
 6+  margin-right: 0.5rem;
 7+}
 8+
 9+.ml {
10+  margin-left: 0.5rem;
11+}
12+
13 .my {
14   margin-top: 0.5rem;
15   margin-bottom: 0.5rem;
M prose/api.go
+10, -2
 1@@ -89,6 +89,7 @@ type HeaderTxt struct {
 2 	Bio      string
 3 	Nav      []shared.Link
 4 	HasLinks bool
 5+	Layout   string
 6 }
 7 
 8 type ReadmeTxt struct {
 9@@ -171,6 +172,8 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
10 	}
11 
12 	ts, err := shared.RenderTemplate(cfg, []string{
13+		cfg.StaticPath("html/blog-default.partial.tmpl"),
14+		cfg.StaticPath("html/blog-aside.partial.tmpl"),
15 		cfg.StaticPath("html/blog.page.tmpl"),
16 	})
17 
18@@ -187,8 +190,9 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
19 	}
20 
21 	headerTxt := &HeaderTxt{
22-		Title: GetBlogName(username),
23-		Bio:   "",
24+		Title:  GetBlogName(username),
25+		Bio:    "",
26+		Layout: "default",
27 	}
28 	readmeTxt := &ReadmeTxt{}
29 
30@@ -202,6 +206,9 @@ func blogHandler(w http.ResponseWriter, r *http.Request) {
31 		if parsedText.Title != "" {
32 			headerTxt.Title = parsedText.Title
33 		}
34+		if parsedText.Layout != "" {
35+			headerTxt.Layout = parsedText.Layout
36+		}
37 
38 		headerTxt.Nav = []shared.Link{}
39 		for _, nav := range parsedText.Nav {
40@@ -434,6 +441,7 @@ func transparencyHandler(w http.ResponseWriter, r *http.Request) {
41 
42 	ts, err := template.ParseFiles(
43 		cfg.StaticPath("html/transparency.page.tmpl"),
44+		cfg.StaticPath("html/base.layout.tmpl"),
45 		cfg.StaticPath("html/footer.partial.tmpl"),
46 		cfg.StaticPath("html/marketing-footer.partial.tmpl"),
47 		cfg.StaticPath("html/base.layout.tmpl"),
A prose/html/blog-aside.partial.tmpl
+54, -0
 1@@ -0,0 +1,54 @@
 2+{{define "blog-aside"}}
 3+<main class="flex">
 4+    <section class="flex-1 mr">
 5+        <div>
 6+            <h1 class="text-2xl font-bold">{{.Header.Title}}</h1>
 7+            {{if .Header.Bio}}<span>{{.Header.Bio}}</span>{{end}}
 8+        </div>
 9+
10+        <div id="readme">
11+            {{if .Readme.HasText}}
12+            <section class="md">
13+                {{.Readme.Contents}}
14+            </section>
15+            {{end}}
16+            <div>
17+                {{range .Header.Nav}}
18+                <a href="{{.URL}}" class="text-lg">{{.Text}}</a> ·
19+                {{end}}
20+                <a href="{{.RSSURL}}" class="text-lg">rss</a>
21+            </div>
22+            <hr />
23+        </div>
24+
25+        {{if .HasFilter}}
26+            <a href={{.URL}}>clear filters</a>
27+        {{end}}
28+
29+        <div class="posts">
30+        {{range .Posts}}
31+            <article class="my">
32+                <div class="flex items-center">
33+                    <time datetime="{{.PublishAtISO}}" class="font-italic text-sm post-date">{{.PublishAt}}</time>
34+                    <div class="font-bold flex-1"><a href="{{.URL}}">{{.Title}}</a></div>
35+                </div>
36+            </article>
37+        {{end}}
38+        </div>
39+    </section>
40+
41+    <aside>
42+        {{if .Readme.HasText}}
43+        <section class="md">
44+            {{.Readme.Contents}}
45+        </section>
46+        {{end}}
47+        <nav>
48+            {{range .Header.Nav}}
49+            <a href="{{.URL}}" class="text-lg">{{.Text}}</a> ·
50+            {{end}}
51+            <a href="{{.RSSURL}}" class="text-lg">rss</a>
52+        </nav>
53+    </aside>
54+</main>
55+{{end}}
A prose/html/blog-default.partial.tmpl
+37, -0
 1@@ -0,0 +1,37 @@
 2+{{define "blog-default"}}
 3+<header class="text-center">
 4+    <h1 class="text-2xl font-bold">{{.Header.Title}}</h1>
 5+    {{if .Header.Bio}}<p class="text-lg">{{.Header.Bio}}</p>{{end}}
 6+    <nav>
 7+        {{range .Header.Nav}}
 8+        <a href="{{.URL}}" class="text-lg">{{.Text}}</a> |
 9+        {{end}}
10+        <a href="{{.RSSURL}}" class="text-lg">rss</a>
11+    </nav>
12+    <hr />
13+</header>
14+<main>
15+    {{if .Readme.HasText}}
16+    <section>
17+        <article class="md">
18+            {{.Readme.Contents}}
19+        </article>
20+        <hr />
21+    </section>
22+    {{end}}
23+
24+    <section class="posts">
25+        {{if .HasFilter}}
26+            <a href={{.URL}}>clear filters</a>
27+        {{end}}
28+        {{range .Posts}}
29+        <article class="my">
30+            <div class="flex items-center">
31+                <time datetime="{{.PublishAtISO}}" class="font-italic text-sm post-date">{{.PublishAt}}</time>
32+                <div class="font-bold flex-1"><a href="{{.URL}}">{{.Title}}</a></div>
33+            </div>
34+        </article>
35+        {{end}}
36+    </section>
37+</main>
38+{{end}}
M prose/html/blog.page.tmpl
+7, -35
 1@@ -26,43 +26,15 @@
 2 {{if .HasCSS}}<link rel="stylesheet" href="{{.CssURL}}" />{{end}}
 3 {{end}}
 4 
 5-{{define "attrs"}}id="blog"{{end}}
 6+{{define "attrs"}}id="blog" class="layout-{{.Header.Layout}}"{{end}}
 7 
 8 {{define "body"}}
 9-<header class="text-center">
10-    <h1 class="text-2xl font-bold">{{.Header.Title}}</h1>
11-    {{if .Header.Bio}}<p class="text-lg">{{.Header.Bio}}</p>{{end}}
12-    <nav>
13-        {{range .Header.Nav}}
14-        <a href="{{.URL}}" class="text-lg">{{.Text}}</a> |
15-        {{end}}
16-        <a href="{{.RSSURL}}" class="text-lg">rss</a>
17-    </nav>
18-    <hr />
19-</header>
20-<main>
21-    {{if .Readme.HasText}}
22-    <section>
23-        <article class="md">
24-            {{.Readme.Contents}}
25-        </article>
26-        <hr />
27-    </section>
28-    {{end}}
29 
30-    <section class="posts">
31-        {{if .HasFilter}}
32-            <a href={{.URL}}>clear filters</a>
33-        {{end}}
34-        {{range .Posts}}
35-        <article class="my">
36-            <div class="flex items-center">
37-                <time datetime="{{.PublishAtISO}}" class="font-italic text-sm post-date">{{.PublishAt}}</time>
38-                <div class="font-bold flex-1"><a href="{{.URL}}">{{.Title}}</a></div>
39-            </div>
40-        </article>
41-        {{end}}
42-    </section>
43-</main>
44+{{if eq .Header.Layout "aside"}}
45+    {{template "blog-aside" .}}
46+{{else}}
47+    {{template "blog-default" .}}
48+{{end}}
49+
50 {{template "footer" .}}
51 {{end}}
M prose/public/main.css
+8, -0
 1@@ -293,6 +293,14 @@ figure {
 2   margin-bottom: 0.5rem;
 3 }
 4 
 5+.mr {
 6+  margin-right: 0.5rem;
 7+}
 8+
 9+.ml {
10+  margin-left: 0.5rem;
11+}
12+
13 .my {
14   margin-top: 0.5rem;
15   margin-bottom: 0.5rem;
M prose/public/prose.css
+30, -0
 1@@ -33,3 +33,33 @@ table {
 2   font-weight: bold;
 3   padding: 0.6rem 0 0 0;
 4 }
 5+
 6+.layout-aside {
 7+  max-width: 50rem;
 8+}
 9+
10+.layout-aside aside {
11+  width: 200px;
12+}
13+
14+.layout-aside img {
15+  border-radius: 5px;
16+}
17+
18+#readme {
19+  display: none;
20+}
21+
22+@media only screen and (max-width: 600px) {
23+  .layout-aside main {
24+    flex-direction: column;
25+  }
26+
27+  #readme {
28+    display: block;
29+  }
30+
31+  aside {
32+    display: none;
33+  }
34+}
M shared/mdparser.go
+2, -0
 1@@ -31,6 +31,7 @@ type MetaData struct {
 2 	Description string
 3 	Nav         []Link
 4 	Tags        []string
 5+	Layout      string
 6 }
 7 
 8 type ParsedText struct {
 9@@ -208,6 +209,7 @@ func ParseText(text string, absURL string) (*ParsedText, error) {
10 	metaData := meta.Get(context)
11 	parsed.MetaData.Title = toString(metaData["title"])
12 	parsed.MetaData.Description = toString(metaData["description"])
13+	parsed.MetaData.Layout = toString(metaData["layout"])
14 
15 	var publishAt *time.Time = nil
16 	var err error
M smol.css
+8, -0
 1@@ -293,6 +293,14 @@ figure {
 2   margin-bottom: 0.5rem;
 3 }
 4 
 5+.mr {
 6+  margin-right: 0.5rem;
 7+}
 8+
 9+.ml {
10+  margin-left: 0.5rem;
11+}
12+
13 .my {
14   margin-top: 0.5rem;
15   margin-bottom: 0.5rem;