summaryrefslogtreecommitdiff
path: root/src/cmd/export/posts.go
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2024-07-26 20:47:59 +0200
committerBrian Picciano <mediocregopher@gmail.com>2024-07-26 23:08:24 +0200
commitc9991c347d20ba9e96b3281f172a86f965934978 (patch)
tree012f1c0c15e6bc36aec4a142248d418efe626464 /src/cmd/export/posts.go
parent45c20d03663878f3508eaa9b961cb0cb12cc5574 (diff)
Implement export scriptHEADmain
Diffstat (limited to 'src/cmd/export/posts.go')
-rw-r--r--src/cmd/export/posts.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/cmd/export/posts.go b/src/cmd/export/posts.go
index f54fc2c..569ff6b 100644
--- a/src/cmd/export/posts.go
+++ b/src/cmd/export/posts.go
@@ -31,7 +31,7 @@ func postTargetFormat(p post.StoredPost) post.Format {
return post.FormatGemtext
}
-func writePostBody(post post.StoredPost, path, body string) error {
+func writePostBody(p post.StoredPost, path, body string) error {
f, err := os.Create(path)
if err != nil {
return fmt.Errorf("opening file: %w", err)
@@ -45,11 +45,18 @@ func writePostBody(post post.StoredPost, path, body string) error {
_, err = f.WriteString(str)
}
- writeString(fmt.Sprintf("# %s\n\n", post.Title))
- if post.Description != "" {
- writeString(fmt.Sprintf("> %s\n\n", post.Description))
+ if f := postTargetFormat(p); f == post.FormatGemtext {
+ writeString("=> ../posts/ Back to All Posts\n\n")
+ } else if f == post.FormatMarkdown {
+ writeString(fmt.Sprintf("---\nTitle: %q\n---\n", p.Title))
+ writeString("[Back to All Posts](../posts/)\n\n")
+ }
+ writeString(fmt.Sprintf("# %s\n\n", p.Title))
+ if p.Description != "" {
+ writeString(fmt.Sprintf("> %s\n\n", p.Description))
}
writeString(body)
+ writeString(fmt.Sprintf("\n-----\n\nPublished %s\n", p.PublishedAt.Format("2006-01-02")))
return err
}