From ba25ddc8556632eb7465fa8a7b297d3698b18821 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 17 Mar 2020 17:03:11 -0400 Subject: [PATCH] blog: use first OldURL to generate atom feed ID This way, renaming an article does not make it reappear in an RSS reader as a new article. Change-Id: I4e92707f9ea4983bf8506cde826d5e5f48a3b36f Reviewed-on: https://go-review.googlesource.com/c/tools/+/223751 Run-TryBot: Russ Cox TryBot-Result: Gobot Gobot Reviewed-by: Andrew Bonventre --- blog/blog.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/blog/blog.go b/blog/blog.go index 3e8f873ba..2310d62fe 100644 --- a/blog/blog.go +++ b/blog/blog.go @@ -312,9 +312,21 @@ func (s *Server) renderAtomFeed() error { if i >= s.cfg.FeedArticles { break } + + // Use original article path as ID in atom feed + // to avoid articles being treated as new when renamed. + idPath := doc.Path + if len(doc.OldURL) > 0 { + old := doc.OldURL[0] + if !strings.HasPrefix(old, "/") { + old = "/" + old + } + idPath = old + } + e := &atom.Entry{ Title: doc.Title, - ID: feed.ID + doc.Path, + ID: feed.ID + idPath, Link: []atom.Link{{ Rel: "alternate", Href: doc.Permalink,