mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-09 01:35:56 +01:00
Little hack to prevent webmentions overwriting
This commit is contained in:
parent
716e206938
commit
baa43bdb40
2 changed files with 25 additions and 3 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -13,7 +13,8 @@
|
|||
"shortener",
|
||||
"shorteners",
|
||||
"shortlink",
|
||||
"shortlinks"
|
||||
"shortlinks",
|
||||
"Webmention"
|
||||
],
|
||||
"cSpell.language": "en-GB"
|
||||
}
|
|
@ -8,6 +8,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -20,6 +21,10 @@ import (
|
|||
const webmentions = "https://webmention.io/api/mentions.jf2?domain=%s&token=%s"
|
||||
const siteTarget = "https://www.byjp.me/"
|
||||
|
||||
var myURLs = []string{
|
||||
"https://bsky.app/profile/byjp.me",
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Domain string
|
||||
Token string
|
||||
|
@ -39,7 +44,7 @@ func main() {
|
|||
switch err {
|
||||
case nil:
|
||||
// Proceed
|
||||
case ErrNoEntry, ErrIsPrivate, ErrIncorrectTarget:
|
||||
case ErrNoEntry, ErrIsPrivate, ErrIncorrectTarget, ErrIsMine:
|
||||
// Skip
|
||||
continue
|
||||
default:
|
||||
|
@ -89,6 +94,14 @@ func addInteraction(jsonPath string, newIn synd.Interaction) error {
|
|||
added := false
|
||||
for idx, in := range inf.Interactions {
|
||||
if in.GUID == newIn.GUID {
|
||||
// A hack because webmentions.io can't process emoji properly currently
|
||||
if strings.Contains(newIn.Author.Name, "????") {
|
||||
newIn.Author.Name = in.Author.Name
|
||||
}
|
||||
if strings.Contains(newIn.Comment, "????") {
|
||||
newIn.Comment = in.Comment
|
||||
}
|
||||
|
||||
inf.Interactions[idx] = newIn
|
||||
added = true
|
||||
}
|
||||
|
@ -115,6 +128,7 @@ func addInteraction(jsonPath string, newIn synd.Interaction) error {
|
|||
var ErrNoEntry = errors.New("JF2 item isn't an entry")
|
||||
var ErrIsPrivate = errors.New("JF2 item is set to private")
|
||||
var ErrIncorrectTarget = errors.New("JF2 item describes a different target site")
|
||||
var ErrIsMine = errors.New("JF2 item was created by the author")
|
||||
|
||||
func parseJF2(m Mention, isValidPath func(string) bool) (string, synd.Interaction, error) {
|
||||
if m.Type != "entry" {
|
||||
|
@ -135,6 +149,14 @@ func parseJF2(m Mention, isValidPath func(string) bool) (string, synd.Interactio
|
|||
return "", synd.Interaction{}, ErrIncorrectTarget
|
||||
}
|
||||
|
||||
if len(sitePath) == 0 {
|
||||
return "", synd.Interaction{}, ErrIncorrectTarget
|
||||
}
|
||||
|
||||
if slices.Contains(myURLs, m.Author.URL) {
|
||||
return "", synd.Interaction{}, ErrIsMine
|
||||
}
|
||||
|
||||
i := synd.Interaction{
|
||||
GUID: fmt.Sprintf("webmentions.io#%d", m.WebmentionID),
|
||||
URL: m.URL,
|
||||
|
@ -169,7 +191,6 @@ func parseJF2(m Mention, isValidPath func(string) bool) (string, synd.Interactio
|
|||
case "in-reply-to":
|
||||
i.Emoji = "💬"
|
||||
case "mention-of":
|
||||
i.Comment = "_A wibble_"
|
||||
i.Emoji = "🗣️"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue