Quellcode durchsuchen

fix(widget): People widget - add `authors` to user account

- add `authors` to set username in user account and force generation
  of user profile page whether or not user has published content. This
  is particularly useful for linking users from the People widget.
- People widget: only link to users which have profile pages generated -
  prevents 404 error if user did not perform the point (1) above
- add i18n "user_profile_latest" to customize user profile text

Fix #274
George Cushen vor 6 Jahren
Ursprung
Commit
58dd61b0e7

+ 3 - 0
exampleSite/content/author/admin/_index.md

@@ -2,6 +2,9 @@
 # Display name
 name = "Nelson Bighetti"
 
+# Username (this should match the folder name)
+authors = ["admin"]
+
 # Is this the primary user of the site?
 superuser = true
 

+ 4 - 1
i18n/en.yaml

@@ -74,7 +74,10 @@
 
 - id: education
   translation: Education
-  
+
+- id: user_profile_latest
+  translation: Latest
+
 # Accomplishments widget
 
 - id: see_certificate

+ 8 - 3
layouts/author/list.html

@@ -16,18 +16,23 @@
     {{ with $.Site.GetPage (printf "/author/%s" (urlize .Title)) }}
       {{ partial $widget $params }}
     {{ end }}
+
+    {{ $query := where .Pages ".IsNode" false }}
+    {{ $count := len $query }}
+    {{ if $count }}
     <div class="article-widget">
       <div class="hr-light"></div>
-      <h3>{{ i18n "related" }}</h3>
+      <h3>{{ i18n "user_profile_latest" | default "Latest" }}</h3>
       <ul>
-        {{ range .Pages }}
+        {{ range $query }}
         <li>
-          <a href="{{ .Permalink }}">{{ .Title }}</a>
+          <a href="{{ .RelPermalink }}">{{ .Title }}</a>
         </li>
         {{ end }}
       </ul>
     </div>
   </div>
+  {{ end }}
 </section>
 
 <!-- Page Footer -->

+ 6 - 3
layouts/partials/widgets/people.html

@@ -25,7 +25,10 @@
 
   {{ $avatar := (.Resources.ByType "image").GetMatch "*avatar*" }}
   {{/* Get link to user's profile page. */}}
-  {{ $link := printf "/authors/%s" (path.Base (path.Split .Path).Dir) | relURL }}
+  {{ $link := "" }}
+  {{ with $.Site.GetPage (printf "/authors/%s" (path.Base (path.Split .Path).Dir)) }}
+    {{ $link = .RelPermalink }}
+  {{ end }}
   <div class="col-12 col-sm-auto people-person">
     {{ $src := "" }}
     {{ if $.Site.Params.gravatar }}
@@ -35,11 +38,11 @@
       {{ $src = $avatar_image.RelPermalink }}
     {{ end }}
     {{ if $src }}
-      <a href="{{ $link}}"><img class="portrait" src="{{ $src }}" alt="Avatar"></a>
+      {{with $link}}<a href="{{.}}">{{end}}<img class="portrait" src="{{ $src }}" alt="Avatar">{{if $link}}</a>{{end}}
     {{ end }}
 
     <div class="portrait-title">
-      <h2><a href="{{ $link }}">{{ .Params.name }}</a></h2>
+      <h2>{{with $link}}<a href="{{.}}">{{end}}{{ .Params.name }}{{if $link}}</a>{{end}}</h2>
       {{ with .Params.role }}<h3>{{ . | markdownify | emojify }}</h3>{{ end }}
       {{ with .Params.interests }}<p class="people-interests">{{ delimit . ", " | markdownify | emojify }}</p>{{ end }}
     </div>