Remove sending of webmentions
parent
8a72be6fc2
commit
e716188dff
|
@ -12,7 +12,6 @@ import (
|
||||||
var (
|
var (
|
||||||
BlogUrl string
|
BlogUrl string
|
||||||
MediaEndpointUrl string
|
MediaEndpointUrl string
|
||||||
IgnoredWebmentionUrls []string
|
|
||||||
SyndicationTargets []SyndicationTarget
|
SyndicationTargets []SyndicationTarget
|
||||||
SelectedStorage Storage
|
SelectedStorage Storage
|
||||||
SelectedMediaStorage MediaStorage
|
SelectedMediaStorage MediaStorage
|
||||||
|
@ -38,7 +37,6 @@ type YamlConfig struct {
|
||||||
BunnyCdn BunnyCdnConfig `yaml:"bunnyCdn"`
|
BunnyCdn BunnyCdnConfig `yaml:"bunnyCdn"`
|
||||||
Telegram TelegramConfig `yaml:"telegram"`
|
Telegram TelegramConfig `yaml:"telegram"`
|
||||||
Tinify TinifyConfig `yaml:"tinify"`
|
Tinify TinifyConfig `yaml:"tinify"`
|
||||||
IgnoredWebmentionUrls []string `yaml:"ignoreWebmention"`
|
|
||||||
SyndicationTargets []string `yaml:"syndication"`
|
SyndicationTargets []string `yaml:"syndication"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,8 +129,6 @@ func initConfig() (err error) {
|
||||||
} else {
|
} else {
|
||||||
return errors.New("no languages configured")
|
return errors.New("no languages configured")
|
||||||
}
|
}
|
||||||
// Ignored Webmention URLs (optional)
|
|
||||||
IgnoredWebmentionUrls = cfg.IgnoredWebmentionUrls
|
|
||||||
// Syndication Targets (optional)
|
// Syndication Targets (optional)
|
||||||
targets := make([]SyndicationTarget, 0)
|
targets := make([]SyndicationTarget, 0)
|
||||||
for _, url := range cfg.SyndicationTargets {
|
for _, url := range cfg.SyndicationTargets {
|
||||||
|
|
6
go.mod
6
go.mod
|
@ -1,4 +1,4 @@
|
||||||
module codeberg.org/jlelse/hugo-micropub
|
module git.jlel.se/jlelse/hugo-micropub
|
||||||
|
|
||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
|
@ -10,8 +10,8 @@ require (
|
||||||
github.com/google/go-cmp v0.4.0 // indirect
|
github.com/google/go-cmp v0.4.0 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/stretchr/testify v1.5.1 // indirect
|
github.com/stretchr/testify v1.5.1 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20200420104511-884d27f42877 // indirect
|
golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 // indirect
|
||||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
|
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd // indirect
|
||||||
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f // indirect
|
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f // indirect
|
||||||
gopkg.in/yaml.v2 v2.2.8
|
gopkg.in/yaml.v2 v2.2.8
|
||||||
willnorris.com/go/webmention v0.0.0-20200126231626-5a55fff6bf71
|
willnorris.com/go/webmention v0.0.0-20200126231626-5a55fff6bf71
|
||||||
|
|
10
go.sum
10
go.sum
|
@ -68,17 +68,15 @@ golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnf
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
|
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
|
||||||
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM=
|
golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 h1:Q7tZBpemrlsc2I7IyODzhtallWRSm4Q0d09pL6XbQtU=
|
||||||
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.0.0-20200420104511-884d27f42877 h1:IhZPbxNd1UjBCaD5AfpSSbJTRlp+ZSuyuH5uoksNS04=
|
|
||||||
golang.org/x/crypto v0.0.0-20200420104511-884d27f42877/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
|
||||||
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
|
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
|
||||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
|
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd h1:QPwSajcTUrFriMF1nJ3XzgoqakqQEsnZf9LdXdi2nkI=
|
||||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
|
2
main.go
2
main.go
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,7 +14,6 @@ func main() {
|
||||||
log.Println("Starting micropub server...")
|
log.Println("Starting micropub server...")
|
||||||
log.Println("Current time: " + time.Now().Format(time.RFC3339))
|
log.Println("Current time: " + time.Now().Format(time.RFC3339))
|
||||||
log.Println("Blog URL: " + BlogUrl)
|
log.Println("Blog URL: " + BlogUrl)
|
||||||
log.Println("Ignored URLs for Webmention: " + strings.Join(IgnoredWebmentionUrls, ", "))
|
|
||||||
http.HandleFunc("/micropub", HandleMicroPub)
|
http.HandleFunc("/micropub", HandleMicroPub)
|
||||||
http.HandleFunc("/media", HandleMedia)
|
http.HandleFunc("/media", HandleMedia)
|
||||||
http.HandleFunc("/webmention", HandleWebmention)
|
http.HandleFunc("/webmention", HandleWebmention)
|
||||||
|
|
|
@ -72,8 +72,6 @@ func HandleMicroPub(w http.ResponseWriter, r *http.Request) {
|
||||||
SelectedCdn.Purge(location)
|
SelectedCdn.Purge(location)
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
}
|
}
|
||||||
// Send webmentions
|
|
||||||
go SendWebmentions(location)
|
|
||||||
}()
|
}()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -19,48 +18,6 @@ type Mention struct {
|
||||||
Date string `json:"date"`
|
Date string `json:"date"`
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
checkPrefix := func(link string, prefix string) bool {
|
|
||||||
return strings.HasPrefix(link, strings.TrimSuffix(prefix, "/"))
|
|
||||||
}
|
|
||||||
checkAny := func(link string) bool {
|
|
||||||
for _, ignoredUrl := range IgnoredWebmentionUrls {
|
|
||||||
if checkPrefix(link, ignoredUrl) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for _, link := range links {
|
|
||||||
if !(checkPrefix(link, BlogUrl) || checkAny(link)) {
|
|
||||||
filteredLinks = append(filteredLinks, link)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filteredLinks
|
|
||||||
}
|
|
||||||
|
|
||||||
func HandleWebmention(w http.ResponseWriter, r *http.Request) {
|
func HandleWebmention(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != "POST" {
|
if r.Method != "POST" {
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
|
Loading…
Reference in New Issue