add gopher publishing

This commit is contained in:
nbsp 2025-04-29 05:57:26 +03:00
parent 350727cd58
commit c29a7c1594
No known key found for this signature in database
GPG Key ID: 7184AC1C9835CE48
2 changed files with 50 additions and 1 deletions

View File

@ -0,0 +1 @@
minor type="added" "add gopher support"

View File

@ -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) {