From c29a7c1594ba1eaea80ab0a9bc440b0e9d07ff55 Mon Sep 17 00:00:00 2001 From: nbsp Date: Tue, 29 Apr 2025 05:57:26 +0300 Subject: [PATCH] add gopher publishing --- .nanpa/array-trunk-mule.kdl | 1 + ttbp/ttbp.go | 50 ++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 .nanpa/array-trunk-mule.kdl diff --git a/.nanpa/array-trunk-mule.kdl b/.nanpa/array-trunk-mule.kdl new file mode 100644 index 0000000..65d1493 --- /dev/null +++ b/.nanpa/array-trunk-mule.kdl @@ -0,0 +1 @@ +minor type="added" "add gopher support" diff --git a/ttbp/ttbp.go b/ttbp/ttbp.go index 798a0db..0b920bb 100644 --- a/ttbp/ttbp.go +++ b/ttbp/ttbp.go @@ -28,11 +28,13 @@ var ( PathUser = os.Getenv("HOME") PathUserFeels = path.Join(PathUser, ".ttbp") PathUserHTML = path.Join(PathUser, "public_html") + PathUserGopherhole = path.Join(PathUser, "public_gopher", "feels") PathUserConfig = path.Join(PathUserFeels, "config") PathUserEntries = path.Join(PathUserFeels, "entries") PathUserBuried = path.Join(PathUserFeels, "buried") PathUserBackups = path.Join(PathUserFeels, "backups") PathUserWWW = path.Join(PathUserFeels, "www") + PathUserGopher = path.Join(PathUserFeels, "gopher") PathUserRc = path.Join(PathUserConfig, "ttbprc") PathUserNopub = path.Join(PathUserConfig, "nopub") PathUserHTMLRender = path.Join(PathUserConfig, "html") @@ -436,7 +438,49 @@ func Publish() { writer.WriteString(string(footer)) writer.Flush() } - // TODO: gopher + if cfg.Gopher { + os.RemoveAll(PathUserGopher) // remove all posts and start over + if _, err := os.Stat(PathUserGopher); os.IsNotExist(err) { + os.MkdirAll(PathUserGopher, 0755) + os.Symlink(PathUserGopher, PathUserGopherhole) + } + file, err := os.Create(path.Join(PathUserGopher, "gophermap")) + defer file.Close() + + if err != nil { + return + } + + writer := bufio.NewWriter(file) + user, _ := user.Current() + writer.WriteString(fmt.Sprintf(` + welcome to %s's gopherfeels. + + .:: .:: + .: .:: + .:.: .: .:: .:: .:: .:::: + .:: .: .:: .: .:: .::.:: + .:: .::::: .::.::::: .:: .:: .::: + .:: .: .: .:: .:: + .:: .:::: .:::: .:::.:: .:: + + this file is automatically generated by ttbp. + +0(about ttbp)%s/~endorphant/ttbp.txt%stilde.town%s70 +1(back to user's home)%s/~%s + +entries: + +`, user.Username, "\t", "\t", "\t", "\t", user.Username)) + for _, post := range GetPostsForUser(user.Username) { + if !post.Nopub && post.Words > 0 { + dateString := post.Date.Format("20060102.txt") + os.Symlink(path.Join(PathUserEntries, dateString), path.Join(PathUserGopher, dateString)) + writer.WriteString(fmt.Sprintf("0%s\t%s\n", post.Date.Format("2006-01-02"), dateString)) + } + } + writer.Flush() + } } func Unpublish() { @@ -448,6 +492,10 @@ func Unpublish() { os.RemoveAll(PathUserWWW) os.RemoveAll(path.Join(PathUserHTML, cfg.PublishDir)) } + if cfg.Gopher { + os.RemoveAll(PathUserGopher) + os.RemoveAll(PathUserGopherhole) + } } func writePage(post Post, header, footer []byte) {