Remove sending of webmentions

master
Jan-Lukas Else 2020-04-25 12:19:57 +02:00
parent 8a72be6fc2
commit e716188dff
6 changed files with 17 additions and 70 deletions

View File

@ -12,7 +12,6 @@ import (
var (
BlogUrl string
MediaEndpointUrl string
IgnoredWebmentionUrls []string
SyndicationTargets []SyndicationTarget
SelectedStorage Storage
SelectedMediaStorage MediaStorage
@ -29,17 +28,16 @@ type SyndicationTarget struct {
}
type YamlConfig struct {
BlogUrl string `yaml:"blogUrl"`
BaseUrl string `yaml:"baseUrl"`
MediaUrl string `yaml:"mediaUrl"`
DefaultLanguage string `yaml:"defaultLang"`
Languages map[string]Language `yaml:"languages"`
Git GitConfig `yaml:"git"`
BunnyCdn BunnyCdnConfig `yaml:"bunnyCdn"`
Telegram TelegramConfig `yaml:"telegram"`
Tinify TinifyConfig `yaml:"tinify"`
IgnoredWebmentionUrls []string `yaml:"ignoreWebmention"`
SyndicationTargets []string `yaml:"syndication"`
BlogUrl string `yaml:"blogUrl"`
BaseUrl string `yaml:"baseUrl"`
MediaUrl string `yaml:"mediaUrl"`
DefaultLanguage string `yaml:"defaultLang"`
Languages map[string]Language `yaml:"languages"`
Git GitConfig `yaml:"git"`
BunnyCdn BunnyCdnConfig `yaml:"bunnyCdn"`
Telegram TelegramConfig `yaml:"telegram"`
Tinify TinifyConfig `yaml:"tinify"`
SyndicationTargets []string `yaml:"syndication"`
}
type BunnyCdnConfig struct {
@ -131,8 +129,6 @@ func initConfig() (err error) {
} else {
return errors.New("no languages configured")
}
// Ignored Webmention URLs (optional)
IgnoredWebmentionUrls = cfg.IgnoredWebmentionUrls
// Syndication Targets (optional)
targets := make([]SyndicationTarget, 0)
for _, url := range cfg.SyndicationTargets {

6
go.mod
View File

@ -1,4 +1,4 @@
module codeberg.org/jlelse/hugo-micropub
module git.jlel.se/jlelse/hugo-micropub
go 1.14
@ -10,8 +10,8 @@ require (
github.com/google/go-cmp v0.4.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.5.1 // indirect
golang.org/x/crypto v0.0.0-20200420104511-884d27f42877 // indirect
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 // indirect
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd // indirect
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f // indirect
gopkg.in/yaml.v2 v2.2.8
willnorris.com/go/webmention v0.0.0-20200126231626-5a55fff6bf71

10
go.sum
View File

@ -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-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-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/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/crypto v0.0.0-20200423211502-4bdfaf469ed5 h1:Q7tZBpemrlsc2I7IyODzhtallWRSm4Q0d09pL6XbQtU=
golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5/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-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-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-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd h1:QPwSajcTUrFriMF1nJ3XzgoqakqQEsnZf9LdXdi2nkI=
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-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -3,7 +3,6 @@ package main
import (
"log"
"net/http"
"strings"
"time"
)
@ -15,7 +14,6 @@ func main() {
log.Println("Starting micropub server...")
log.Println("Current time: " + time.Now().Format(time.RFC3339))
log.Println("Blog URL: " + BlogUrl)
log.Println("Ignored URLs for Webmention: " + strings.Join(IgnoredWebmentionUrls, ", "))
http.HandleFunc("/micropub", HandleMicroPub)
http.HandleFunc("/media", HandleMedia)
http.HandleFunc("/webmention", HandleWebmention)

View File

@ -72,8 +72,6 @@ func HandleMicroPub(w http.ResponseWriter, r *http.Request) {
SelectedCdn.Purge(location)
time.Sleep(10 * time.Second)
}
// Send webmentions
go SendWebmentions(location)
}()
return
}

View File

@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"net/url"
"strings"
@ -19,48 +18,6 @@ type Mention struct {
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) {
if r.Method != "POST" {
w.WriteHeader(http.StatusMethodNotAllowed)