Skip to content

Commit

Permalink
feat(sitemap): add last updated for packages (#1070)
Browse files Browse the repository at this point in the history
  • Loading branch information
Elsie19 authored Nov 8, 2024
1 parent b9a54ac commit 1c02974
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion server/server/sitemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package server
import (
"fmt"
"net/http"
"time"

"pacstall.dev/webserver/types/pac/pacstore"
)

type SitemapEntry struct {
Location string
ChangeFrequency string
LastUpdated *string
}

func registerSiteMap() {
Expand Down Expand Up @@ -42,9 +44,11 @@ func generateDynamicSiteMap() []SitemapEntry {
entries := make([]SitemapEntry, len(packages))

for idx, pkg := range packages {
lastUpdated := pkg.LastUpdatedAt.Format(time.RFC3339)
entries[idx] = SitemapEntry{
Location: fmt.Sprintf("https://pacstall.dev/packages/%s/", pkg.PackageName),
ChangeFrequency: "monthly",
LastUpdated: &lastUpdated,
}
}

Expand All @@ -55,7 +59,13 @@ func (entry SitemapEntry) generateSiteMapUrls() string {
return fmt.Sprintf(`<url>
<loc>%s</loc>
<changefreq>%s</changefreq>
</url>`, entry.Location, entry.ChangeFrequency)
%s
</url>`, entry.Location, entry.ChangeFrequency, func() string {
if entry.LastUpdated != nil {
return fmt.Sprintf("<lastmod>%s</lastmod>", *entry.LastUpdated)
}
return ""
}())
}

func generateSiteMapXML() string {
Expand Down

0 comments on commit 1c02974

Please sign in to comment.