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

View File

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

37
main.go
View File

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