Add Atom feed (not yet linked)
This commit is contained in:
parent
8be575875d
commit
c8808e21bf
|
@ -422,9 +422,15 @@ func TestTimeMachine(t *testing.T) {
|
||||||
|
|
||||||
func TestTimeMachineSubmissions(t *testing.T) {
|
func TestTimeMachineSubmissions(t *testing.T) {
|
||||||
AssertRegexMatch(t, BuildTimeMachineSubmissions(), RegexTimeMachineSubmissions, nil)
|
AssertRegexMatch(t, BuildTimeMachineSubmissions(), RegexTimeMachineSubmissions, nil)
|
||||||
|
AssertRegexMatch(t, BuildTimeMachineSubmission(123), RegexTimeMachineSubmissions, nil)
|
||||||
AssertSubdomain(t, BuildTimeMachineSubmissions(), "")
|
AssertSubdomain(t, BuildTimeMachineSubmissions(), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTimeMachineAtomFeed(t *testing.T) {
|
||||||
|
AssertRegexMatch(t, BuildTimeMachineAtomFeed(), RegexTimeMachineAtomFeed, nil)
|
||||||
|
AssertSubdomain(t, BuildTimeMachineAtomFeed(), "")
|
||||||
|
}
|
||||||
|
|
||||||
func TestTimeMachineForm(t *testing.T) {
|
func TestTimeMachineForm(t *testing.T) {
|
||||||
AssertRegexMatch(t, BuildTimeMachineForm(), RegexTimeMachineForm, nil)
|
AssertRegexMatch(t, BuildTimeMachineForm(), RegexTimeMachineForm, nil)
|
||||||
AssertSubdomain(t, BuildTimeMachineForm(), "")
|
AssertSubdomain(t, BuildTimeMachineForm(), "")
|
||||||
|
|
|
@ -126,6 +126,18 @@ func BuildTimeMachineSubmissions() string {
|
||||||
return Url("/timemachine/submissions", nil)
|
return Url("/timemachine/submissions", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BuildTimeMachineSubmission(id int) string {
|
||||||
|
defer CatchPanic()
|
||||||
|
return UrlWithFragment("/timemachine/submissions", nil, strconv.Itoa(id))
|
||||||
|
}
|
||||||
|
|
||||||
|
var RegexTimeMachineAtomFeed = regexp.MustCompile("^/timemachine/submissions/atom$")
|
||||||
|
|
||||||
|
func BuildTimeMachineAtomFeed() string {
|
||||||
|
defer CatchPanic()
|
||||||
|
return Url("/timemachine/submissions/atom", nil)
|
||||||
|
}
|
||||||
|
|
||||||
var RegexTimeMachineForm = regexp.MustCompile("^/timemachine/submit$")
|
var RegexTimeMachineForm = regexp.MustCompile("^/timemachine/submit$")
|
||||||
|
|
||||||
func BuildTimeMachineForm() string {
|
func BuildTimeMachineForm() string {
|
||||||
|
|
|
@ -177,6 +177,8 @@
|
||||||
margin: 0.2rem 0;
|
margin: 0.2rem 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
{{ block "extrahead" . }}{{ end }}
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
{{ noescape "<?xml version=\"1.0\" encoding=\"utf-8\"?>" }}
|
||||||
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||||
|
<id>https://handmade.network/timemachine/submissions</id>
|
||||||
|
<title type="text">Time Machine | Handmade Network</title>
|
||||||
|
<subtitle>This summer, dig out your old devices and see what they were actually like to use.</subtitle>
|
||||||
|
<updated>{{ rfc3339 .Updated }}</updated>
|
||||||
|
<link href="{{ .TimeMachineUrl }}"/>
|
||||||
|
<link rel="self" type="application/atom+xml" href="{{ .AtomFeedUrl }}"/>
|
||||||
|
<link rel="alternate" type="text/html" hreflang="en" href="{{ .SubmissionsUrl }}"/>
|
||||||
|
<author>
|
||||||
|
<name>Handmade Network</name>
|
||||||
|
<email>team@handmade.network</email>
|
||||||
|
<uri>https://handmade.network/</uri>
|
||||||
|
</author>
|
||||||
|
<logo>{{ .LogoUrl }}</logo>
|
||||||
|
<rights>© 2023 Handmade Network</rights>
|
||||||
|
{{ range .Submissions }}
|
||||||
|
<entry>
|
||||||
|
<id>{{ .Permalink }}</id>
|
||||||
|
<title>{{ .Title }}</title>
|
||||||
|
<link rel="alternate" type="text/html" href="{{ .Permalink }}" />
|
||||||
|
<published>{{ rfc3339 .Date }}</published>
|
||||||
|
<updated>{{ rfc3339 .Date }}</updated>
|
||||||
|
<content type="html">
|
||||||
|
{{ with .Details }}
|
||||||
|
<ul>
|
||||||
|
{{ range . }}
|
||||||
|
<li><b>{{ .Name }}:</b> {{ yesescape .Content }}</li>
|
||||||
|
{{ end }}
|
||||||
|
</ul>
|
||||||
|
{{ end }}
|
||||||
|
{{ yesescape .Description }}
|
||||||
|
</content>
|
||||||
|
</entry>
|
||||||
|
{{ end }}
|
||||||
|
</feed>
|
|
@ -1,5 +1,9 @@
|
||||||
{{ template "timemachine_base.html" . }}
|
{{ template "timemachine_base.html" . }}
|
||||||
|
|
||||||
|
{{ define "extrahead" }}
|
||||||
|
<link rel="alternate" type="application/atom+xml" title="Submission Feed" href="{{ .AtomFeedUrl }}">
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
{{ define "content" }}
|
{{ define "content" }}
|
||||||
<div class="center-layout content mw7 ph3 flex flex-column g3">
|
<div class="center-layout content mw7 ph3 flex flex-column g3">
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -255,6 +255,9 @@ var HMNTemplateFuncs = template.FuncMap{
|
||||||
"noescape": func(str string) template.HTML {
|
"noescape": func(str string) template.HTML {
|
||||||
return template.HTML(str)
|
return template.HTML(str)
|
||||||
},
|
},
|
||||||
|
"yesescape": func(html template.HTML) string {
|
||||||
|
return string(html)
|
||||||
|
},
|
||||||
"filesize": func(numBytes int) string {
|
"filesize": func(numBytes int) string {
|
||||||
scales := []string{
|
scales := []string{
|
||||||
" bytes",
|
" bytes",
|
||||||
|
|
|
@ -72,6 +72,7 @@ func NewWebsiteRoutes(conn *pgxpool.Pool) http.Handler {
|
||||||
|
|
||||||
hmnOnly.GET(hmnurl.RegexTimeMachine, TimeMachine)
|
hmnOnly.GET(hmnurl.RegexTimeMachine, TimeMachine)
|
||||||
hmnOnly.GET(hmnurl.RegexTimeMachineSubmissions, TimeMachineSubmissions)
|
hmnOnly.GET(hmnurl.RegexTimeMachineSubmissions, TimeMachineSubmissions)
|
||||||
|
hmnOnly.GET(hmnurl.RegexTimeMachineAtomFeed, TimeMachineAtomFeed)
|
||||||
hmnOnly.GET(hmnurl.RegexTimeMachineForm, needsAuth(TimeMachineForm))
|
hmnOnly.GET(hmnurl.RegexTimeMachineForm, needsAuth(TimeMachineForm))
|
||||||
hmnOnly.GET(hmnurl.RegexTimeMachineFormDone, needsAuth(TimeMachineFormDone))
|
hmnOnly.GET(hmnurl.RegexTimeMachineFormDone, needsAuth(TimeMachineFormDone))
|
||||||
hmnOnly.POST(hmnurl.RegexTimeMachineForm, needsAuth(csrfMiddleware(TimeMachineFormSubmit)))
|
hmnOnly.POST(hmnurl.RegexTimeMachineForm, needsAuth(csrfMiddleware(TimeMachineFormSubmit)))
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.handmade.network/hmn/hmn/src/email"
|
"git.handmade.network/hmn/hmn/src/email"
|
||||||
"git.handmade.network/hmn/hmn/src/hmnurl"
|
"git.handmade.network/hmn/hmn/src/hmnurl"
|
||||||
|
@ -67,12 +68,14 @@ func TimeMachineSubmissions(c *RequestContext) ResponseData {
|
||||||
templates.BaseData
|
templates.BaseData
|
||||||
MainUrl string
|
MainUrl string
|
||||||
SubmitUrl string
|
SubmitUrl string
|
||||||
|
AtomFeedUrl string
|
||||||
Submissions []TimeMachineSubmission
|
Submissions []TimeMachineSubmission
|
||||||
}
|
}
|
||||||
tmpl := TemplateData{
|
tmpl := TemplateData{
|
||||||
BaseData: baseData,
|
BaseData: baseData,
|
||||||
MainUrl: hmnurl.BuildTimeMachine(),
|
MainUrl: hmnurl.BuildTimeMachine(),
|
||||||
SubmitUrl: hmnurl.BuildTimeMachineForm(),
|
SubmitUrl: hmnurl.BuildTimeMachineForm(),
|
||||||
|
AtomFeedUrl: hmnurl.BuildTimeMachineAtomFeed(),
|
||||||
Submissions: tmSubmissions,
|
Submissions: tmSubmissions,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,10 +142,39 @@ func TimeMachineFormDone(c *RequestContext) ResponseData {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TimeMachineAtomFeed(c *RequestContext) ResponseData {
|
||||||
|
type TemplateData struct {
|
||||||
|
Updated time.Time
|
||||||
|
TimeMachineUrl string
|
||||||
|
SubmissionsUrl string
|
||||||
|
AtomFeedUrl string
|
||||||
|
LogoUrl string
|
||||||
|
Submissions []TimeMachineSubmission
|
||||||
|
}
|
||||||
|
tmpl := TemplateData{
|
||||||
|
Updated: tmSubmissions[0].Date,
|
||||||
|
TimeMachineUrl: hmnurl.BuildTimeMachine(),
|
||||||
|
SubmissionsUrl: hmnurl.BuildTimeMachineSubmissions(),
|
||||||
|
AtomFeedUrl: hmnurl.BuildTimeMachineAtomFeed(),
|
||||||
|
LogoUrl: hmnurl.BuildPublic("timemachine/twittercard.png", true),
|
||||||
|
Submissions: tmSubmissions,
|
||||||
|
}
|
||||||
|
|
||||||
|
var res ResponseData
|
||||||
|
res.MustWriteTemplate(
|
||||||
|
"timemachine_atom.xml",
|
||||||
|
tmpl,
|
||||||
|
c.Perf,
|
||||||
|
)
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
type TimeMachineSubmission struct {
|
type TimeMachineSubmission struct {
|
||||||
|
Date time.Time
|
||||||
Title string
|
Title string
|
||||||
Url string
|
Url string
|
||||||
Thumbnail string
|
Thumbnail string
|
||||||
|
Permalink string // generated for feed
|
||||||
Details []TimeMachineSubmissionDetail
|
Details []TimeMachineSubmissionDetail
|
||||||
Description template.HTML
|
Description template.HTML
|
||||||
}
|
}
|
||||||
|
@ -154,6 +186,7 @@ type TimeMachineSubmissionDetail struct {
|
||||||
|
|
||||||
var tmSubmissions = []TimeMachineSubmission{
|
var tmSubmissions = []TimeMachineSubmission{
|
||||||
{
|
{
|
||||||
|
Date: time.Date(2023, 6, 6, 0, 0, 0, 0, time.UTC),
|
||||||
Title: "2009 iPod Touch",
|
Title: "2009 iPod Touch",
|
||||||
Url: "https://youtu.be/2eBFk1yV6mE",
|
Url: "https://youtu.be/2eBFk1yV6mE",
|
||||||
Thumbnail: "timemachine/ipodtouch-dither.gif",
|
Thumbnail: "timemachine/ipodtouch-dither.gif",
|
||||||
|
@ -188,3 +221,9 @@ var tmSubmissions = []TimeMachineSubmission{
|
||||||
</p>`,
|
</p>`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
for i := range tmSubmissions {
|
||||||
|
tmSubmissions[i].Permalink = hmnurl.BuildTimeMachineSubmission(len(tmSubmissions) - i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue