Skip to content

Commit

Permalink
Fix glossary template rendering and redirect.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jun 4, 2023
1 parent 3ccdd19 commit 45faf31
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
1 change: 0 additions & 1 deletion cmd/dictpress/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ func initHTTPServer(app *App, ko *koanf.Koanf) *echo.Echo {
p.GET("/dictionary/:fromLang/:toLang/:q", handleSearchPage)
p.GET("/dictionary/:fromLang/:toLang", handleGlossaryPage)
p.GET("/glossary/:fromLang/:toLang/:initial", handleGlossaryPage)
p.GET("/glossary/:fromLang/:toLang", handleGlossaryPage)
p.GET("/pages/:page", handleStaticPage)

// Static files.
Expand Down
9 changes: 7 additions & 2 deletions cmd/dictpress/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@ func handleGlossaryPage(c echo.Context) error {
}

// If there's no initial, pick the first one.
if initial == "" {
return c.Redirect(http.StatusFound, fmt.Sprintf("/glossary/%s/%s/%s", fromLang, toLang, initials[0]))
if initial == "" || initial == "*" {
for _, i := range initials {
if i == "*" || i == "." {
continue
}
return c.Redirect(http.StatusFound, fmt.Sprintf("/glossary/%s/%s/%s", fromLang, toLang, i))
}
}

// Get words.
Expand Down
11 changes: 6 additions & 5 deletions site/glossary-words.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{{ define "glossary-words" }}
{{ if not .Words }}
<h2>{{ .L.T "public.noResultsTitle" }}</h2>
<p>{{ .L.T "public.noGlossary" }}</p>
{{ $g := .Data.Glossary }}
{{ if not $g.Words }}
<h2>{{ $.L.T "public.noResultsTitle" }}</h2>
<p>{{ $.L.T "public.noResults" }}</p>
{{ else }}
<ul class="noul words">
{{ range $i, $w := .Words }}
<li><a href="/dictionary/{{ UnicodeURL $.FromLang }}/{{ UnicodeURL $.ToLang }}/{{ UnicodeURL $w.Content }}">{{ $w.Content }}</a></li>
{{ range $i, $w := $g.Words }}
<li><a href="/dictionary/{{ UnicodeURL $g.FromLang }}/{{ UnicodeURL $g.ToLang }}/{{ UnicodeURL $w.Content }}">{{ $w.Content }}</a></li>
{{ end }}
</ul>
{{ end }}
Expand Down
4 changes: 2 additions & 2 deletions site/glossary.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<section class="content glossary">
{{ if not .Data.Initials }}
<h2>{{ .L.T "public.glossaryTitle" }}</h2>
<p>{{ .L.T "public.noGlossary" }}</p>
<p>{{ .L.T "public.noResults" }}</p>
{{ else }}
<nav class="index">
{{ range $k, $a := .Data.Initials }}
Expand All @@ -13,7 +13,7 @@ <h2>{{ .L.T "public.glossaryTitle" }}</h2>
</nav>

<nav class="pagination top">{{ .Data.PgBar }}</nav>
{{ template "glossary-words" .Data.Glossary }}
{{ template "glossary-words" . }}
<nav class="pagination bottom">{{ .Data.PgBar }}</nav>
{{ end}}
</section>
Expand Down
1 change: 0 additions & 1 deletion site/lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"public.glossary": "{name} glossary",
"public.glossaryTitle": "Glossary of words",
"public.mainTitle": "Dictionary website",
"public.noGlossary": "No glossary results were found for that language",
"public.noResults": "No results where found for the query.",
"public.noResultsTitle": "No results",
"public.searchTitle": "\"{query}\" meaning",
Expand Down

0 comments on commit 45faf31

Please sign in to comment.