Home

blog @main - refs - log -
-
https://git.jolheiser.com/blog.git
My nonexistent blog
tree log patch
add raw articles for convenience Signed-off-by: jolheiser <git@jolheiser.com>
Signature
-----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgBTEvCQk6VqUAdN2RuH6bj1dNkY oOpbPWj+jw4ua1B1cAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5 AAAAQMSgK1CerN0BDrpuRK/FhWDy7W8s3Zlolg2i2LcaH+W53pp//L21A/iqQw0kuSjLzC pgSkq683LY6bVTmLEsgwQ= -----END SSH SIGNATURE-----
jolheiser <git@jolheiser.com>
4 hours ago
3 changed files, 30 additions(+), 18 deletions(-)
main.gotemplates.templtemplates_templ.go
M main.go -> main.go
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
diff --git a/main.go b/main.go
index ce647c46a6f795ef63dc255dbe3066cea0f3f5ae..b01d6d92b4c819b2e675b42268a0c87206ba9e25 100644
--- a/main.go
+++ b/main.go
@@ -3,6 +3,7 @@ //go:generate go run .
 package main
 
 import (
+	"bytes"
 	"context"
 	"embed"
 	"flag"
@@ -66,6 +67,13 @@ 		article.path = path
 		categories[article.Category] = append(categories[article.Category], article)
 		articles = append(articles, article)
 		if err := writeArticle(*outFlag, article); err != nil {
+			return err
+		}
+		dstRaw, err := os.Create(filepath.Join(*outFlag, article.Slug()+".md"))
+		if err := copyFile(dstRaw, bytes.NewReader(content)); err != nil {
+			return err
+		}
+		if err := dstRaw.Close(); err != nil {
 			return err
 		}
 	}
@@ -200,23 +208,10 @@ 	}
 	return nil
 }
 
-func copyFile(dst, src string) error {
-	srcFi, err := os.Open(src)
-	if err != nil {
+func copyFile(dst io.Writer, src io.Reader) error {
+	if _, err := io.Copy(dst, src); err != nil {
 		return err
 	}
-	defer srcFi.Close()
-
-	dstFi, err := os.Create(dst)
-	if err != nil {
-		return err
-	}
-	defer dstFi.Close()
-
-	if _, err := io.Copy(dstFi, srcFi); err != nil {
-		return err
-	}
-
 	return nil
 }
 
M templates.templ -> templates.templ
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
diff --git a/templates.templ b/templates.templ
index 3a91de9045e39fa9e3801f2450714a0f97fde423..bbccc691c784ba56337e3dd2df920009ef5938ea 100644
--- a/templates.templ
+++ b/templates.templ
@@ -59,7 +59,11 @@ 		</header>
 		<main>
 			@templ.Raw(article.Content)
 		</main>
-		<footer><a href={ templ.SafeURL(fmt.Sprintf("https://git.jolheiser.com/blog/tree/%s/%s", ref, article.path)) }>source</a></footer>
+		<footer>
+			<a href={ templ.SafeURL(fmt.Sprintf("https://git.jolheiser.com/blog/tree/%s/%s", ref, article.path)) }>(source)</a>
+			&middot;
+			<a href={ templ.SafeURL(fmt.Sprintf("../%s.md", article.Slug())) }>(raw)</a>
+		</footer>
 	}
 }
 
M templates_templ.go -> templates_templ.go
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
diff --git a/templates_templ.go b/templates_templ.go
index ca1c7675eb01e3e71590d6427c765a1dbdebfdf9..a264aa9532c73c9b0541dd38be7f971b784a0ef7 100644
--- a/templates_templ.go
+++ b/templates_templ.go
@@ -296,13 +296,26 @@ 			}
 			var templ_7745c5c3_Var16 templ.SafeURL
 			templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(fmt.Sprintf("https://git.jolheiser.com/blog/tree/%s/%s", ref, article.path)))
 			if templ_7745c5c3_Err != nil {
-				return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates.templ`, Line: 62, Col: 110}
+				return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates.templ`, Line: 63, Col: 103}
 			}
 			_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
 			if templ_7745c5c3_Err != nil {
 				return templ_7745c5c3_Err
 			}
-			templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "\">source</a></footer>")
+			templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "\">(source)</a> &middot; <a href=\"")
+			if templ_7745c5c3_Err != nil {
+				return templ_7745c5c3_Err
+			}
+			var templ_7745c5c3_Var17 templ.SafeURL
+			templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(fmt.Sprintf("../%s.md", article.Slug())))
+			if templ_7745c5c3_Err != nil {
+				return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates.templ`, Line: 65, Col: 67}
+			}
+			_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
+			if templ_7745c5c3_Err != nil {
+				return templ_7745c5c3_Err
+			}
+			templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "\">(raw)</a></footer>")
 			if templ_7745c5c3_Err != nil {
 				return templ_7745c5c3_Err
 			}