actually use consts

trunk
nbsp 2025-01-08 02:08:50 +02:00
parent 9db7c4b44d
commit 8588cbd16d
No known key found for this signature in database
GPG Key ID: 7184AC1C9835CE48
3 changed files with 32 additions and 21 deletions

View File

@ -133,7 +133,7 @@ func newFeels(state *ui.State) {
vt.Attach(state.PostEvent())
vt.Focus()
now := time.Now()
err := vt.Start(exec.Command(os.ExpandEnv(os.Getenv("EDITOR")), path.Join(os.Getenv("HOME"), ".ttbp/entries", now.Format("20060102")+".txt")))
err := vt.Start(exec.Command(os.ExpandEnv(os.Getenv("EDITOR")), path.Join(ttbp.PathUserEntries, now.Format("20060102")+".txt")))
if err != nil {
panic(err)
}

View File

@ -3,9 +3,11 @@ package app
import (
"os"
"path"
"strings"
"time"
"git.sr.ht/~rockorager/vaxis"
"git.tilde.town/nbsp/neofeels/ttbp"
"git.tilde.town/nbsp/neofeels/ui"
)
@ -17,8 +19,8 @@ type Posted struct {
func NewPosted() *Posted {
var content string
info, err := os.Stat(path.Join(os.Getenv("HOME"), ".ttbp/entries", time.Now().Format("20060102")+".txt"))
if os.IsNotExist(err) || info.IsDir() || info.Size() == 0 {
info, err := os.ReadFile(path.Join(ttbp.PathUserEntries, time.Now().Format("20060102")+".txt"))
if os.IsNotExist(err) || strings.Trim(string(info), " \r\n\t") == "" {
content = `your post is empty and was not published.
see you next time!`
} else {

View File

@ -17,13 +17,22 @@ import (
)
var (
PathVar = "/var/global/ttbp"
PathVarWWW = path.Join(PathVar, "www")
PathLive = "https://tilde.town/~"
PathUserFile = path.Join(PathVar, "users.txt")
PathGraff = path.Join(PathVar, "graffiti")
PathWall = path.Join(PathGraff, "wall.txt")
PathWallLock = path.Join(PathGraff, ".lock")
PathVar = "/var/global/ttbp"
PathVarWWW = path.Join(PathVar, "www")
PathLive = "https://tilde.town/~"
PathUserFile = path.Join(PathVar, "users.txt")
PathGraff = path.Join(PathVar, "graffiti")
PathWall = path.Join(PathGraff, "wall.txt")
PathWallLock = path.Join(PathGraff, ".lock")
PathUser = os.Getenv("HOME")
PathUserFeels = path.Join(PathUser, ".ttbp")
PathUserHTML = path.Join(PathUser, "public_html")
PathUserConfig = path.Join(PathUserFeels, "config")
PathUserEntries = path.Join(PathUserFeels, "entries")
PathUserWWW = path.Join(PathUserFeels, "www")
PathUserRc = path.Join(PathUserConfig, "ttbprc")
PathUserNopub = path.Join(PathUserConfig, "nopub")
PathUserSubs = path.Join(PathUserConfig, "subs")
)
type User struct {
@ -99,7 +108,7 @@ func GetPostsForUser(user string) (posts []Post) {
if err != nil {
return
}
nopubFile, err := os.OpenFile(path.Join(os.Getenv("HOME"), ".ttbp/config/nopub"), os.O_RDONLY|os.O_CREATE, 0644)
nopubFile, err := os.OpenFile(PathUserNopub, os.O_RDONLY|os.O_CREATE, 0644)
if err != nil {
return
}
@ -169,7 +178,7 @@ type Subscriptions struct {
}
func GetSubscriptions() *Subscriptions {
file, err := os.OpenFile(path.Join(os.Getenv("HOME"), ".ttbp/config/subs"), os.O_RDONLY|os.O_CREATE, 0600)
file, err := os.OpenFile(PathUserSubs, os.O_RDONLY|os.O_CREATE, 0600)
if err != nil {
return &Subscriptions{}
}
@ -209,7 +218,7 @@ func (subscriptions *Subscriptions) Unsubscribe(user User) {
}
func (subscriptions *Subscriptions) Write() {
file, err := os.Create(path.Join(os.Getenv("HOME"), ".ttbp/config/subs"))
file, err := os.Create(PathUserSubs)
if err != nil {
return
}
@ -232,7 +241,7 @@ func NewNopub(t time.Time) {
return
}
dateString := t.Format("20060102.txt")
file, err := os.OpenFile(path.Join(os.Getenv("HOME"), ".ttbp/config/nopub"), os.O_RDWR|os.O_CREATE, 0600)
file, err := os.OpenFile(PathUserNopub, os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return
}
@ -256,12 +265,12 @@ func Publish(t time.Time) {
return // TODO: expose this error to the user
}
if cfg.Publishing {
file, err := os.Create(path.Join(os.Getenv("HOME"), ".ttbp/www/index.html"))
file, err := os.Create(path.Join(PathUserWWW, "index.html"))
defer file.Close()
// load header and footer
header, err := os.ReadFile(path.Join(os.Getenv("HOME"), ".ttbp/config/header.txt"))
footer, err := os.ReadFile(path.Join(os.Getenv("HOME"), ".ttbp/config/footer.txt"))
header, err := os.ReadFile(path.Join(PathUserConfig, "header.txt"))
footer, err := os.ReadFile(path.Join(PathUserConfig, "footer.txt"))
if err != nil {
return
@ -272,7 +281,7 @@ func Publish(t time.Time) {
writer.WriteString(string(header) + "\n")
user, _ := user.Current()
for _, post := range GetPostsForUser(user.Username) {
if !post.Nopub {
if !post.Nopub && post.Words > 0 {
writePage(post, header, footer)
writer.WriteString(writeEntry(post) + "\n")
}
@ -284,8 +293,8 @@ func Publish(t time.Time) {
}
func writePage(post Post, header, footer []byte) {
dateString := post.Date.Format("20060102")
file, err := os.Create(path.Join(os.Getenv("HOME"), ".ttbp/www/"+dateString+".html"))
dateString := post.Date.Format("20060102.html")
file, err := os.Create(path.Join(PathUserWWW, dateString))
if err != nil {
return
}
@ -299,7 +308,7 @@ func writePage(post Post, header, footer []byte) {
func writeEntry(post Post) string {
dateString := post.Date.Format("20060102")
file, err := os.ReadFile(path.Join(os.Getenv("HOME"), ".ttbp/entries/"+dateString+".txt"))
file, err := os.ReadFile(path.Join(PathUserEntries, dateString+".txt"))
if err != nil {
return ""
}