Skip to content

Commit

Permalink
ensure the feeds use correct URL for page
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarchie committed Oct 6, 2023
1 parent 638ac6b commit 61ffefa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
25 changes: 25 additions & 0 deletions builder_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,29 @@ title: required
Expect(notExist).NotTo(BeAnExistingFile())
})
})

When("generating feeds", func() {
It("creates RSS, Atom, and sitemap to HTML pages", func() {
createLayout()
createFile("dir/index.md", "# some text")
createFile("other.md", "# some text")
createFile("dir/test.html", "some other text")

cli.BaseURL = "https://example.com"
err := cli.Run()
Expect(err).NotTo(HaveOccurred())

contents := readFile("rss.xml")
Expect(contents).To(gbytes.Say(`https://example.com/other.html`))
Expect(contents).To(gbytes.Say(`https://example.com/dir/index.html`))

contents = readFile("atom.xml")
Expect(contents).To(gbytes.Say(`https://example.com/other.html`))
Expect(contents).To(gbytes.Say(`https://example.com/dir/index.html`))

contents = readFile("sitemap.xml")
Expect(contents).To(gbytes.Say(`https://example.com/other.html`))
Expect(contents).To(gbytes.Say(`https://example.com/dir/index.html`))
})
})
})
5 changes: 3 additions & 2 deletions render.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,17 @@ func (r *Render) generateFeeds(docs Docs, funcMap template.FuncMap) error {
createdTime = doc.Timespec.BirthTime().UTC()
}

docURL, _ := url.JoinPath(r.baseURL, doc.Path())

err := sitemap.Add(&smg.SitemapLoc{
Loc: doc.RelativePath(),
Loc: docURL,
LastMod: &modifiedTime,
ChangeFreq: smg.Always,
})
if err != nil {
return fmt.Errorf("could not add file %q to sitemap: %w", doc.Filename(), err)
}

docURL, _ := url.JoinPath(r.baseURL, doc.RelativePath())
contents, _ := r.renderMarkdownFromDoc(doc, funcMap)

feed.Items = append(feed.Items, &feeds.Item{
Expand Down

0 comments on commit 61ffefa

Please sign in to comment.