feat: first and last buttons

This commit is contained in:
Henrique Dias 2023-06-02 08:18:30 +02:00
parent ad118d8984
commit f5f7f58806
No known key found for this signature in database
3 changed files with 28 additions and 25 deletions

View File

@ -13,19 +13,19 @@
<main>
<h1>{{ .Num }} - {{ .Title }}</h1>
<nav>
{{- with .Prev }}
<a href="{{ . }}" aria-label="Previous" role="button"><span aria-hidden="true">← Prev</span></a>
<a href="../1/" aria-label="First" role="button"><span aria-hidden="true">|&lt;</span></a>
{{- if gt .Num 1 }}
<a href="../{{ minus .Num 1 }}/" aria-label="Previous" role="button"><span aria-hidden="true">← Prev</span></a>
{{- else }}
<a aria-disabled="true" aria-label="Previous" role="button" tabindex="-1"><span aria-hidden="true">← Prev</span></a>
{{- end }}
<a role="button" href="../">Home</a>
{{- with .Next }}
<a href="{{ . }}" aria-label="Next" role="button"><span aria-hidden="true">Next →</span></a>
{{- if lt .Num .Latest }}
<a href="../{{ plus .Num 1 }}/" aria-label="Next" role="button"><span aria-hidden="true">Next →</span></a>
{{- else }}
<a aria-disabled="true" aria-label="Next" role="button" tabindex="-1"><span aria-hidden="true">Next →</span></a>
{{- end }}
<a href="../{{ .Latest }}/" aria-label="Last" role="button"><span aria-hidden="true">&gt;|</span></a>
</nav>
{{ if .Image }}
<figure>

View File

@ -57,6 +57,10 @@ nav a:hover {
box-shadow: none;
}
nav a[aria-disabled="true"] {
cursor: not-allowed;
}
ul {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));

37
main.go
View File

@ -103,18 +103,11 @@ var cmd = &cobra.Command{
}
data := &comicData{
Num: id,
Title: metadata.String("title"),
Alt: metadata.String("alt"),
Image: metadata.String("img"),
}
if id > 1 {
data.Prev = fmt.Sprintf("../%d/", id-1)
}
if id < uint(latest) {
data.Next = fmt.Sprintf("../%d/", id+1)
Num: id,
Title: metadata.String("title"),
Alt: metadata.String("alt"),
Image: metadata.String("img"),
Latest: latest,
}
var b bytes.Buffer
@ -162,12 +155,11 @@ var cmd = &cobra.Command{
}
type comicData struct {
Num uint
Title string
Alt string
Prev string
Next string
Image string
Latest uint
Num uint
Title string
Alt string
Image string
}
type homeData struct {
@ -179,7 +171,14 @@ func getTemplate(name string) (*template.Template, error) {
if err != nil {
return nil, err
}
return template.New("").Parse(string(comicBytes))
return template.New("").Funcs(template.FuncMap{
"minus": func(a, b uint) uint {
return a - b
},
"plus": func(a, b uint) uint {
return a + b
},
}).Parse(string(comicBytes))
}
func copyAsset(out, filename string) error {