1
mirror of https://github.com/jlelse/GoBlog synced 2024-06-01 12:14:27 +00:00
GoBlog/postsDeleter.go
Jan-Lukas Else 37a9e1f29c Split status in status and visibility
Closes #38

This aligns the implementation more with the IndieWeb standards and allows setting and updating status and visibility individually.
2022-09-23 11:05:07 +02:00

35 lines
889 B
Go

package main
import (
"log"
"time"
"github.com/araddon/dateparse"
)
func (a *goBlog) initPostsDeleter() {
a.hourlyHooks = append(a.hourlyHooks, func() {
a.checkDeletedPosts()
})
}
func (a *goBlog) checkDeletedPosts() {
// Get all posts with `deleted` parameter and a deleted status
postsToDelete, err := a.getPosts(&postsRequestConfig{
status: []postStatus{statusPublishedDeleted, statusDraftDeleted, statusScheduledDeleted},
parameter: "deleted",
})
if err != nil {
log.Println("Error getting deleted posts:", err)
return
}
for _, post := range postsToDelete {
// Check if post is deleted for more than 7 days
if deleted, err := dateparse.ParseLocal(post.firstParameter("deleted")); err == nil && deleted.Add(time.Hour*24*7).Before(time.Now()) {
if err := a.deletePost(post.Path); err != nil {
log.Println("Error deleting post:", err)
}
}
}
}