45 lines
953 B
Go
45 lines
953 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"strings"
|
|
"willnorris.com/go/webmention"
|
|
)
|
|
|
|
func SendWebmentions(url string) {
|
|
client := webmention.New(nil)
|
|
dl, err := client.DiscoverLinks(url, ".h-entry")
|
|
if err != nil {
|
|
return
|
|
}
|
|
// Send Webmentions
|
|
for _, link := range filterLinks(dl) {
|
|
endpoint, err := client.DiscoverEndpoint(link)
|
|
if err != nil || len(endpoint) < 1 {
|
|
continue
|
|
}
|
|
_, err = client.SendWebmention(endpoint, url, link)
|
|
if err != nil {
|
|
log.Println("Sent webmention to " + link + " failed")
|
|
continue
|
|
}
|
|
log.Println("Sent webmention to " + link)
|
|
}
|
|
}
|
|
|
|
func filterLinks(links []string) []string {
|
|
var filteredLinks []string
|
|
LINKFILTER:
|
|
for _, link := range links {
|
|
if strings.HasPrefix(link, BlogUrl) {
|
|
continue
|
|
}
|
|
for _, ignoredURL := range IgnoredWebmentionUrls {
|
|
if strings.HasPrefix(link, ignoredURL) {
|
|
continue LINKFILTER
|
|
}
|
|
}
|
|
filteredLinks = append(filteredLinks, link)
|
|
}
|
|
return filteredLinks
|
|
} |