Showcase xml feed

This commit is contained in:
Asaf Gartner 2021-06-22 15:02:47 +03:00
parent ae12ef0e8c
commit 2df9390993
3 changed files with 72 additions and 2 deletions

View File

@ -43,6 +43,28 @@
{{ end }} {{ end }}
{{ else if .Snippets }} {{ else if .Snippets }}
{{ range .Snippets }} {{ range .Snippets }}
<entry>
<title>New showcase item by {{ .OwnerName }}</title>
<link rel="alternative" type="text/html" href="{{ .Url }}" />
<id>{{ .UUID }}</id>
<published>{{ rfc3339 .Date }}</published>
<author>
<name>{{ .OwnerName }}</name>
<uri>{{ .OwnerUrl }}</uri>
</author>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
{{ .Description }}
{{ if snippetimage . }}
<img src="{{ .AssetUrl }}"/>
{{ else if snippetvideo . }}
<video src="{{ .AssetUrl }}" controls="true"/>
{{ else if snippetaudio . }}
<audio src="{{ .AssetUrl }}" controls="true"/>
{{ end }}
</div>
</content>
</entry>
{{ end }} {{ end }}
{{ end }} {{ end }}
</feed> </feed>

View File

@ -234,6 +234,7 @@ type TimelineItem struct {
Class string Class string
Date time.Time Date time.Time
Url string Url string
UUID string
OwnerAvatarUrl string OwnerAvatarUrl string
OwnerName string OwnerName string

View File

@ -140,7 +140,7 @@ type AtomFeedData struct {
FeedType FeedType FeedType FeedType
Posts []templates.PostListItem Posts []templates.PostListItem
Projects []templates.Project Projects []templates.Project
Snippets []int // TODO(asaf): Actually do this Snippets []templates.TimelineItem
} }
func AtomFeed(c *RequestContext) ResponseData { func AtomFeed(c *RequestContext) ResponseData {
@ -248,8 +248,55 @@ func AtomFeed(c *RequestContext) ResponseData {
templateProject.Owners = append(templateProject.Owners, templates.UserToTemplate(&owner.User, "")) templateProject.Owners = append(templateProject.Owners, templates.UserToTemplate(&owner.User, ""))
} }
c.Perf.EndBlock() c.Perf.EndBlock()
updated := time.Now()
if len(feedData.Projects) > 0 {
updated = feedData.Projects[0].DateApproved
}
feedData.Updated = updated
case "showcase": case "showcase":
// TODO(asaf): Implement this feedData.Title = "Showcase | Site-wide | Handmade.Network"
feedData.Subtitle = feedData.Title
feedData.FeedType = FeedTypeShowcase
feedData.FeedID = FeedIDShowcase
feedData.AtomFeedUrl = hmnurl.BuildAtomFeedForShowcase()
feedData.FeedUrl = hmnurl.BuildShowcase()
c.Perf.StartBlock("SQL", "Fetch showcase snippets")
type snippetQuery struct {
Owner models.User `db:"owner"`
Snippet models.Snippet `db:"snippet"`
Asset *models.Asset `db:"asset"`
DiscordMessage *models.DiscordMessage `db:"discord_message"`
}
snippetQueryResult, err := db.Query(c.Context(), c.Conn, snippetQuery{},
`
SELECT $columns
FROM
handmade_snippet AS snippet
INNER JOIN auth_user AS owner ON owner.id = snippet.owner_id
LEFT JOIN handmade_asset AS asset ON asset.id = snippet.asset_id
LEFT JOIN handmade_discordmessage AS discord_message ON discord_message.id = snippet.discord_message_id
ORDER BY snippet.when DESC
LIMIT $1
`,
itemsPerFeed,
)
if err != nil {
return ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to fetch snippets"))
}
snippetQuerySlice := snippetQueryResult.ToSlice()
for _, s := range snippetQuerySlice {
row := s.(*snippetQuery)
timelineItem := SnippetToTimelineItem(&row.Snippet, row.Asset, row.DiscordMessage, &row.Owner, c.Theme)
timelineItem.UUID = uuid.NewSHA1(uuid.NameSpaceURL, []byte(timelineItem.Url)).URN()
feedData.Snippets = append(feedData.Snippets, timelineItem)
}
c.Perf.EndBlock()
updated := time.Now()
if len(feedData.Snippets) > 0 {
updated = feedData.Snippets[0].Date
}
feedData.Updated = updated
default: default:
return FourOhFour(c) return FourOhFour(c)
} }