Kaynağa Gözat

Improve 404 error page (Close #332)

* Internationalize the page (string translation)
  * Add 3 new language variables: page_not_found, 404_recommendations,
    projects
* Show recent talks and projects
* For each content type, show most recent 5 items
* Only show content headings if content exists for each type of content
George Cushen 7 yıl önce
ebeveyn
işleme
d8577538ca
2 değiştirilmiş dosya ile 43 ekleme ve 6 silme
  1. 11 0
      i18n/en.yaml
  2. 32 6
      layouts/404.html

+ 11 - 0
i18n/en.yaml

@@ -127,3 +127,14 @@
 
 - id: talks
   translation: Talks
+
+- id: projects
+  translation: Projects
+
+# Error 404
+
+- id: page_not_found
+  translation: Page not found
+
+- id: 404_recommendations
+  translation: Perhaps you were looking for one of these?

+ 32 - 6
layouts/404.html

@@ -2,22 +2,48 @@
 {{ partial "navbar.html" . }}
 <div class="container">
 
-  <h1>Page not found</h1>
-  <p>Maybe you were looking for one of these?</p>
+  <h1>{{ i18n "page_not_found" }}</h1>
+  <p>{{ i18n "404_recommendations" }}</p>
 
-  <h2>Recent Posts</h2>
-  {{ range last 20 (where .Data.Pages "Section" "=" "post") }}
+  {{ $posts_len := len (where .Site.RegularPages "Section" "post") }}
+  {{ if gt $posts_len 0 }}
+  <h2>{{ i18n "posts" }}</h2>
+  {{ range last 5 (where .Site.RegularPages "Section" "post") }}
   <ul>
     <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
   </ul>
   {{ end }}
+  {{ end }}
+
+  {{ $pubs_len := len (where .Site.RegularPages "Section" "publication") }}
+  {{ if gt $pubs_len 0 }}
+  <h2>{{ i18n "publications" }}</h2>
+  {{ range last 5 (where .Site.RegularPages "Section" "publication") }}
+  <ul>
+    <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
+  </ul>
+  {{ end }}
+  {{ end }}
 
-  <h2>Recent Publications</h2>
-  {{ range last 20 (where .Data.Pages "Section" "=" "publication") }}
+  {{ $talks_len := len (where .Site.RegularPages "Section" "talk") }}
+  {{ if gt $talks_len 0 }}
+  <h2>{{ i18n "talks" }}</h2>
+  {{ range last 5 (where .Site.RegularPages "Section" "talk") }}
   <ul>
     <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
   </ul>
   {{ end }}
+  {{ end }}
+
+  {{ $projects_len := len (where .Site.RegularPages "Section" "project") }}
+  {{ if gt $projects_len 0 }}
+  <h2>{{ i18n "projects" }}</h2>
+  {{ range last 5 (where .Site.RegularPages "Section" "project") }}
+  <ul>
+    <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
+  </ul>
+  {{ end }}
+  {{ end }}
 
 </div>
 {{ partial "footer_container.html" . }}