From c9991c347d20ba9e96b3281f172a86f965934978 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Fri, 26 Jul 2024 20:47:59 +0200 Subject: Implement export script --- src/cmd/export/posts.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/cmd/export/posts.go') 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 } -- cgit v1.2.3