option to resend specific post webmention

This commit is contained in:
Niko Abeler 2022-09-08 21:11:34 +02:00
parent db9dee6232
commit ecfcd84b82
1 changed files with 39 additions and 18 deletions

View File

@ -6,8 +6,14 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var postId string
func init() { func init() {
rootCmd.AddCommand(webmentionCmd) rootCmd.AddCommand(webmentionCmd)
webmentionCmd.Flags().StringVar(
&postId, "post", "",
"specify the post to send webmentions for. Otherwise, all posts will be checked.",
)
} }
var webmentionCmd = &cobra.Command{ var webmentionCmd = &cobra.Command{
@ -39,19 +45,13 @@ var webmentionCmd = &cobra.Command{
} }
} }
for _, user := range users { processPost := func(user owl.User, post *owl.Post) error {
posts, err := user.Posts()
if err != nil {
println("Error getting posts: ", err.Error())
}
for _, post := range posts {
println("Webmentions for post: ", post.Title()) println("Webmentions for post: ", post.Title())
err := post.ScanForLinks() err := post.ScanForLinks()
if err != nil { if err != nil {
println("Error scanning post for links: ", err.Error()) println("Error scanning post for links: ", err.Error())
continue return err
} }
webmentions := post.OutgoingWebmentions() webmentions := post.OutgoingWebmentions()
@ -64,6 +64,27 @@ var webmentionCmd = &cobra.Command{
println("Webmention sent to ", webmention.Target) println("Webmention sent to ", webmention.Target)
} }
} }
return nil
}
for _, user := range users {
if postId != "" {
// send webmentions for a specific post
post, err := user.GetPost(postId)
if err != nil {
println("Error getting post: ", err.Error())
return
}
processPost(user, &post)
}
posts, err := user.Posts()
if err != nil {
println("Error getting posts: ", err.Error())
}
for _, post := range posts {
processPost(user, post)
} }
} }
}, },