Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resend webmention to a link if the link is removed #17

Merged
merged 1 commit into from
Oct 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ func findWork(cfg config) ([]mention, error) {
var mentions []mention

for _, file := range files {
path := filepath.Join(cfg.newDir, file)
path := filepath.Join(cfg.oldDir, file)
oldtargets, _ := getSources(path, cfg.baseURL, cfg.excludeDestinations, cfg.oldDir)
path = filepath.Join(cfg.newDir, file)
targets, err := getSources(path, cfg.baseURL, cfg.excludeDestinations, cfg.newDir)
if err != nil {
if err == errPageDeleted {
Expand All @@ -197,6 +199,7 @@ func findWork(cfg config) ([]mention, error) {
return nil, err
}
}
targets = appendDedupe(targets, oldtargets...)
for _, target := range targets {
m := mention{base + strings.TrimSuffix(file, "index.html"), target}
mentions = append(mentions, m)
Expand Down Expand Up @@ -488,3 +491,17 @@ func eqUnescaped(source, ex string) bool {
func postSlash(s string) string {
return strings.TrimSuffix(s, "/") + "/"
}

func appendDedupe(a []string, b ...string) (out []string) {
a = append(a, b...)
lp:
for _, s := range a {
for _, str := range out {
if eqUnescaped(s, str) {
continue lp
}
}
out = append(out, s)
}
return
}
2 changes: 2 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestFindWork(t *testing.T) {
"https://my-awesome.site/testdata/page/",
"http://some.site/post/title",
"https://my-awesome.site/other/",
"http://example.site/post",
}

if !stringSlicesEqual(got, want) {
Expand Down Expand Up @@ -103,6 +104,7 @@ func TestCompareDirs(t *testing.T) {
"posts/1/index.html",
"posts/2/index.html",
"posts/3/index.html",
"posts/4/index.html",
}

if !stringSlicesEqual(got, want) {
Expand Down
1 change: 1 addition & 0 deletions testdata/prod/posts/4/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><span class=h-entry>Some text, and there's a <a href="http://example.site/post">link</a>, too!</span></html>
1 change: 1 addition & 0 deletions testdata/prod/posts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><span class=h-entry>Some text, and there's a <a href="http://example.site/somepost">link</a>, too!</span></html>
1 change: 1 addition & 0 deletions testdata/staging/posts/4/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><span class=h-entry>something</span></html>