Automated Webmentions sending
parent
fa3bf31ea5
commit
1a07bbe047
5
go.mod
5
go.mod
|
@ -2,4 +2,7 @@ module codeberg.org/jlelse/hugo-micropub
|
|||
|
||||
go 1.13
|
||||
|
||||
require gopkg.in/yaml.v2 v2.2.5
|
||||
require (
|
||||
gopkg.in/yaml.v2 v2.2.7
|
||||
willnorris.com/go/webmention v0.0.0-20191104072158-c7fb13569b62 // indirect
|
||||
)
|
||||
|
|
14
go.sum
14
go.sum
|
@ -1,3 +1,13 @@
|
|||
github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRySc45o=
|
||||
github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/wsxiaoys/terminal v0.0.0-20160513160801-0940f3fc43a0/go.mod h1:IXCdmsXIht47RaVFLEdVnh1t+pgYtTAhQGj73kz+2DM=
|
||||
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3 h1:czFLhve3vsQetD6JOJ8NZZvGQIXlnN3/yXxbT6/awxI=
|
||||
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c=
|
||||
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
|
||||
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
willnorris.com/go/webmention v0.0.0-20191104072158-c7fb13569b62 h1:jqC8A1S2/9WjXSOK/Nl2rYwVgxU7DCnZ/zpOTL1BErI=
|
||||
willnorris.com/go/webmention v0.0.0-20191104072158-c7fb13569b62/go.mod h1:p+ZRAsZS2pzZ6kX3GKWYurf3WZI2ygj7VbR8NM8qwfM=
|
||||
|
|
5
main.go
5
main.go
|
@ -72,6 +72,11 @@ func handleMicroPub(w http.ResponseWriter, r *http.Request) {
|
|||
go func() {
|
||||
time.Sleep(10 * time.Second)
|
||||
Purge(location)
|
||||
// Send webmentions
|
||||
go func() {
|
||||
time.Sleep(3 * time.Second)
|
||||
SendWebmentions(location)
|
||||
}()
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
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
|
||||
}
|
||||
for _, link := range dl {
|
||||
blogUrl, err := GetBlogURL()
|
||||
if err != nil || strings.HasPrefix(link, blogUrl) {
|
||||
continue
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue