diff --git a/main.go b/main.go index 94126da92d0d6f9a5c90bcab275bb36fd2bd8338..949c504fba8b0c24c5373bd6cc00c7d9731268cb 100644 --- a/main.go +++ b/main.go @@ -26,11 +26,13 @@ var ( flagSensitive *bool = flag.BoolP("sensitive", "S", false, "Mark the post as sensitive (optional)") flagAuthenticate *bool = flag.BoolP("authenticate", "a", false, "Authenticate with the server") flagInstance *string = flag.StringP("instance", "i", "", "Instance to post to (required)") + flagTagsSkip *string = flag.StringP("tagsskip", "T", "", "Particular tags to skip (optional)") ) type post struct { Title string Description string `json:"status"` + Tags string Image string `json:"media_attachments"` Link string Visibility string `json:"visibility"` @@ -44,24 +46,49 @@ func main() { fp := gofeed.NewParser() feed, _ := fp.ParseURL(*flagFeed) - description, _ := htmlToPlaintext(feed.Items[0].Description) - description = strings.ReplaceAll(description, "\n\n", " ") - description = strings.ReplaceAll(description, "\n", " ") - splitDesc := strings.Split(description, " ") - if len(splitDesc) > 50 { - description = strings.Join(splitDesc[:50], " ") + + skippedTags := strings.Split(*flagTagsSkip, ",") + skippedTagsMaps := make(map[string]int) + for i := range skippedTags { + skippedTagsMaps[skippedTags[i]] = 0 + } + var i int + tags := strings.Split(feed.Items[i].Categories[0], "/") + for i, tag := range tags { + if _, ok := skippedTagsMaps[tag]; ok { + i++ + continue + } + break } post := post{ - Title: feed.Items[0].Title, - Description: description + "...", - Link: feed.Items[0].Link, + Title: feed.Items[i].Title, + Link: feed.Items[i].Link, + } + + if feed.Items[i].Image != nil { + post.Image = feed.Items[i].Image.URL } - if feed.Items[0].Image != nil { - post.Image = feed.Items[0].Image.URL + for i, tag := range tags { + tag = "#" + strings.ReplaceAll(tag, " ", "") + if i == 0 { + post.Tags = tag + continue + } + post.Tags += " " + tag } + description, _ := htmlToPlaintext(feed.Items[i].Description) + description = strings.ReplaceAll(description, "\n\n", " ") + description = strings.ReplaceAll(description, "\n", " ") + splitDesc := strings.Split(description, " ") + if len(splitDesc) > 50 { + description = strings.Join(splitDesc[:50], " ") + } + post.Description = description + "..." + tFile, err := os.ReadFile(*flagTemplate) if err != nil { fmt.Println(err) @@ -80,7 +107,6 @@ func main() { post.Sensitive = *flagSensitive post.Spoiler = *flagSpoiler post.Visibility = *flagVisibility - postBytes, err := json.Marshal(post) if err != nil { fmt.Println(err) diff --git a/template.txt b/template.txt index 65588553812d2e601efb5812c27340d2638fdcf8..f8704698c3c5f74e868a7460f2567accc140de44 100644 --- a/template.txt +++ b/template.txt @@ -2,3 +2,5 @@ {{ .Link }} {{ .Description }} + +{{ .Tags }}