fast and minimal static site generator
ssg

Fix atom feed link construction

This pull request introduces a helper function `newAtomLink` to correctly construct Atom feed links using subdomains and slugs. Previously, the feed link was generated using `filepath.Join`, which is intended for file paths and caused malformed URLs like:

```
https://example.comfoo/bar
```

Now, the link is properly constructed in the format:

```
https://<subdomain>.<host>/<slug>
```

Example:

```go
newAtomLink("https://example.com", "blog", "some-post")
// → <link href="https://blog.example.com/some-post"></link>
```

This change improves the correctness and clarity of Atom feed generation by replacing inappropriate path logic with URL-aware composition via url.Parse.

authored by fogtype.com and committed by anirudh.fi 39b17ddd 060a4516

Changed files
+20 -2
atom
+20 -2
atom/feed.go
··· 3 3 import ( 4 4 "encoding/xml" 5 5 "fmt" 6 + "net/url" 6 7 "path/filepath" 7 8 "time" 8 9 ··· 80 81 dateStr, 81 82 filepath.Join(srcDir, p.Meta["slug"].(string)), 82 83 ), 83 - // filepath.Join strips the second / in http:// 84 - Link: &AtomLink{Href: config.Config.URL + filepath.Join(srcDir, p.Meta["slug"].(string))}, 84 + Link: newAtomLink(config.Config.URL, srcDir, p.Meta["slug"].(string)), 85 85 Summary: &AtomSummary{ 86 86 Content: summaryContent, 87 87 Type: "html", ··· 113 113 // Add the <?xml...> header. 114 114 return []byte(xml.Header + string(feedXML)), nil 115 115 } 116 + 117 + // Creates a new Atom link. 118 + // 119 + // Example: 120 + // 121 + // newAtomLink("https://example.com", "blog", "some-post") 122 + // // → <link href="https://blog.example.com/some-post"></link> 123 + func newAtomLink(base string, subdomain string, slug string) *AtomLink { 124 + baseURL, err := url.Parse(base) 125 + if err != nil { 126 + return nil 127 + } 128 + 129 + baseURL.Host = subdomain + "." + baseURL.Host 130 + baseURL.Path = slug 131 + 132 + return &AtomLink{Href: baseURL.String()} 133 + }