Browse Source

feat: make taxonomy URLs singular

- make taxonomy URLs singular, consistent with other Academic pages (workaround Hugo attempting to publish taxonomy URLs with plural names). This requires the breaking change below.
- Fix extra space/lines appearing in the author cards underneath page content as reported at https://spectrum.chat/academic/help/publication-widget-adds-additional-lines-at-bottom-of-the-page~315f77d8-7cc8-44a9-a431-5b64b7556c53

BREAKING CHANGE:
Rename `name` to `title` in author profiles within `author/` folder.
George Cushen 5 years ago
parent
commit
601620c7a6

+ 7 - 0
exampleSite/config/_default/config.toml

@@ -37,6 +37,13 @@ enableEmoji = true
 footnotereturnlinkcontents = "<sup>^</sup>"
 ignoreFiles = ["\\.ipynb$", ".ipynb_checkpoints$", "\\.Rmd$", "\\.Rmarkdown$", "_files$", "_cache$"]
 
+# Workaround Hugo publishing taxonomy URLs as plurals - consistently use singular across Academic.
+[permalinks]
+  authors = "/author/:slug/"
+  tags = "/tag/:slug/"
+  categories = "/category/:slug/"
+  publication_types = "/publication-type/:slug/"
+
 [outputs]
   home = [ "HTML", "RSS", "JSON", "WebAppManifest" ]
   section = [ "HTML", "RSS" ]

+ 1 - 1
exampleSite/content/authors/admin/_index.md

@@ -1,6 +1,6 @@
 ---
 # Display name
-name: Nelson Bighetti
+title: Nelson Bighetti
 
 # Username (this should match the folder name)
 authors:

+ 1 - 1
layouts/authors/terms.html

@@ -12,7 +12,7 @@
   <ul>
     {{ $paginator := .Paginate .Data.Pages }}
     {{ range $k, $v := $paginator.Pages }}
-      {{ $name := $v.Params.name | default ($v.Title|plainify) }}
+      {{ $name := $v.Title }}
       <li><a href="{{$v.Permalink}}">{{$name}}</a></li>
     {{ end }}
   </ul>

+ 2 - 4
layouts/index.json

@@ -4,7 +4,7 @@
 {{- /* Add the index page of docs separately since it's not in RegularPages above. */ -}}
 {{- $pages := $pages | union (where (where site.Pages "Kind" "section") "Type" "docs") -}}
 {{- /* Add author pages to index so their bios can be searched. Hide empty `/authors/` node. */ -}}
-{{- $pages := $pages | union (where (where site.Pages "Section" "authors") "Params.name" "!=" nil) -}}
+{{- $pages := $pages | union (where (where site.Pages "Section" "authors") "Params.superuser" "!=" nil) -}}
 
 {{- range $pages -}}
   {{- /* Do not index drafts or private pages. */ -}}
@@ -27,7 +27,6 @@
 
     {{/* Correct the title and URL for author profile pages. */}}
     {{- if eq .Section "authors" -}}
-      {{- $title = .Params.name -}}
       {{- $username := path.Base (path.Split .Path).Dir -}}
       {{- with site.GetPage (printf "/authors/%s" $username) -}}
         {{- $permalink = .Permalink -}}
@@ -43,8 +42,7 @@
               {{- $person_page_path := (printf "/authors/%s" (urlize $v)) -}}
               {{- $person_page := site.GetPage $person_page_path -}}
               {{- if and $person_page $person_page.File -}}
-                {{- $person := $person_page.Params -}}
-                {{- $authors = $authors | append $person.name -}}
+                {{- $authors = $authors | append $person_page.Title -}}
               {{- else -}}
                 {{- $authors = $authors | append ($v | plainify) -}}
               {{- end -}}

+ 1 - 1
layouts/partials/functions/get_author_name.html

@@ -18,7 +18,7 @@
 {{ $taxonomy := "authors" }}
 {{ $profile_page := site.GetPage (printf "/%s/%s" $taxonomy $author_username) }}
 {{ with $profile_page }}
-  {{ $author = .Params.name | default .Title }}
+  {{ $author = .Title }}
 {{ else }}
   {{ $author = $author | default $publisher }}
 {{ end }}

+ 21 - 19
layouts/partials/page_author_card.html

@@ -4,26 +4,28 @@
 {{ $taxonomy := "authors" }}
 {{ $profile_page := site.GetPage (printf "/%s/%s" $taxonomy $author_urlized) }}
 {{ with $profile_page }}
-  {{/* If it's a personal site and primary page author is superuser, link to the homepage rather than their profile page. */}}
-  {{ $profile_url := .RelPermalink }}
-  {{ if and (eq $site_type "Person") (eq .Params.superuser true) }}
-    {{ $profile_url = site.BaseURL }}
-  {{ end }}
-  {{ $avatar := (.Resources.ByType "image").GetMatch "*avatar*" }}
-  {{ $avatar_shape := site.Params.avatar.shape | default "circle" }}
-  <div class="media author-card content-widget-hr">
-    {{ if and site.Params.avatar.gravatar .Params.email }}
-      <img class="avatar mr-3 {{if eq $avatar_shape "square"}}avatar-square{{else}}avatar-circle{{end}}" src="https://s.gravatar.com/avatar/{{ md5 .Params.email }}?s=200')" alt="{{.Params.name}}">
-    {{ else if $avatar }}
-      {{ $avatar_image := $avatar.Fill "270x270 Center" }}
-      <img class="avatar mr-3 {{if eq $avatar_shape "square"}}avatar-square{{else}}avatar-circle{{end}}" src="{{ $avatar_image.RelPermalink }}" alt="{{.Params.name}}">
+  {{ if isset .Params "superuser" }}{{/* Check an author profile exists. */}}
+    {{/* If it's a personal site and primary page author is superuser, link to the homepage rather than their profile page. */}}
+    {{ $profile_url := .RelPermalink }}
+    {{ if and (eq $site_type "Person") (eq .Params.superuser true) }}
+      {{ $profile_url = site.BaseURL }}
     {{ end }}
+    {{ $avatar := (.Resources.ByType "image").GetMatch "*avatar*" }}
+    {{ $avatar_shape := site.Params.avatar.shape | default "circle" }}
+    <div class="media author-card content-widget-hr">
+      {{ if and site.Params.avatar.gravatar .Params.email }}
+        <img class="avatar mr-3 {{if eq $avatar_shape "square"}}avatar-square{{else}}avatar-circle{{end}}" src="https://s.gravatar.com/avatar/{{ md5 .Params.email }}?s=200')" alt="{{.Title}}">
+      {{ else if $avatar }}
+        {{ $avatar_image := $avatar.Fill "270x270 Center" }}
+        <img class="avatar mr-3 {{if eq $avatar_shape "square"}}avatar-square{{else}}avatar-circle{{end}}" src="{{ $avatar_image.RelPermalink }}" alt="{{.Title}}">
+      {{ end }}
 
-    <div class="media-body">
-      <h5 class="card-title"><a href="{{$profile_url}}">{{.Params.name}}</a></h5>
-      {{ with .Params.role }}<h6 class="card-subtitle">{{. | markdownify | emojify}}</h6>{{end}}
-      {{ with .Params.bio }}<p class="card-text">{{. | markdownify | emojify}}</p>{{end}}
-      {{ partial "social_links" . }}
+      <div class="media-body">
+        <h5 class="card-title"><a href="{{$profile_url}}">{{.Title}}</a></h5>
+        {{ with .Params.role }}<h6 class="card-subtitle">{{. | markdownify | emojify}}</h6>{{end}}
+        {{ with .Params.bio }}<p class="card-text">{{. | markdownify | emojify}}</p>{{end}}
+        {{ partial "social_links" . }}
+      </div>
     </div>
-  </div>
+  {{end}}
 {{end}}{{/* Profile page block */}}

+ 1 - 1
layouts/partials/page_metadata_authors.html

@@ -5,7 +5,7 @@
   {{ $link_authors := site.Params.link_authors | default true }}
   {{ range $index, $value := . }}
     {{- $profile_page := site.GetPage (printf "/%s/%s" $taxonomy (. | urlize)) -}}
-    {{- $name := $profile_page.Params.name | default ($value|markdownify) -}}
+    {{- $name := $profile_page.Title | default ($value|markdownify) -}}
     {{- if gt $index 0 }}, {{ end -}}
     <span>
       {{- if and $profile_page $link_authors -}}

+ 3 - 3
layouts/partials/site_head.html

@@ -12,7 +12,7 @@
   {{ $superuser_username := "" }}
   {{ $superuser_role := "" }}
   {{ range first 1 (where (where site.Pages "Section" "authors") "Params.superuser" true) }}
-    {{ $superuser_name = .Params.name }}
+    {{ $superuser_name = .Title }}
     {{ $superuser_username = path.Base (path.Split .Path).Dir }}
     {{ $superuser_role = .Params.role }}
   {{ end }}
@@ -182,7 +182,7 @@
   {{ end }}
   <meta property="og:site_name" content="{{ site.Title }}">
   <meta property="og:url" content="{{ .Permalink }}">
-  <meta property="og:title" content="{{ if not .IsHome }}{{ .Params.name | default .Title }} | {{ end }}{{ site.Title }}">
+  <meta property="og:title" content="{{ if not .IsHome }}{{ .Title }} | {{ end }}{{ site.Title }}">
   <meta property="og:description" content="{{ $desc }}">
   {{- with $og_image -}}
   <meta property="og:image" content="{{.}}">
@@ -206,6 +206,6 @@
 
   {{ partial "custom_head" . }}
 
-  <title>{{ if not .IsHome }}{{ .Params.name | default .Title }} | {{ end }}{{ site.Title }}</title>
+  <title>{{ if not .IsHome }}{{ .Title }} | {{ end }}{{ site.Title }}</title>
 
 </head>

+ 3 - 3
layouts/partials/widgets/about.html

@@ -23,14 +23,14 @@
     <div id="profile">
 
       {{ if site.Params.avatar.gravatar }}
-      <img class="avatar {{if eq $avatar_shape "square"}}avatar-square{{else}}avatar-circle{{end}}" src="https://s.gravatar.com/avatar/{{ md5 $person.email }}?s=270')" alt="{{$person.name}}">
+      <img class="avatar {{if eq $avatar_shape "square"}}avatar-square{{else}}avatar-circle{{end}}" src="https://s.gravatar.com/avatar/{{ md5 $person.email }}?s=270')" alt="{{$person_page.Title}}">
       {{ else if $avatar }}
       {{ $avatar_image := $avatar.Fill "270x270 Center" }}
-      <img class="avatar {{if eq $avatar_shape "square"}}avatar-square{{else}}avatar-circle{{end}}" src="{{ $avatar_image.RelPermalink }}" alt="{{$person.name}}">
+      <img class="avatar {{if eq $avatar_shape "square"}}avatar-square{{else}}avatar-circle{{end}}" src="{{ $avatar_image.RelPermalink }}" alt="{{$person_page.Title}}">
       {{ end }}
 
       <div class="portrait-title">
-        <h2>{{ $person.name }}</h2>
+        <h2>{{ $person_page.Title }}</h2>
         {{ with $person.role }}<h3>{{ . | markdownify | emojify }}</h3>{{ end }}
 
         {{ range $person.organizations }}

+ 1 - 1
layouts/partials/widgets/people.html

@@ -50,7 +50,7 @@
     {{ end }}
 
     <div class="portrait-title">
-      <h2>{{with $link}}<a href="{{.}}">{{end}}{{ .Params.name }}{{if $link}}</a>{{end}}</h2>
+      <h2>{{with $link}}<a href="{{.}}">{{end}}{{ .Title }}{{if $link}}</a>{{end}}</h2>
       {{ with .Params.role }}<h3>{{ . | markdownify | emojify }}</h3>{{ end }}
       {{ if $show_social }}{{ partial "social_links" . }}{{ end }}
       {{ if and $show_interests .Params.interests }}<p class="people-interests">{{ delimit .Params.interests ", " | markdownify | emojify }}</p>{{ end }}

+ 1 - 1
layouts/shortcodes/mention.html

@@ -2,7 +2,7 @@
 {{- $username_url := $username | urlize -}}
 {{- $taxonomy := "authors" -}}
 {{- $profile_page := site.GetPage (printf "/%s/%s" $taxonomy $username_url) -}}
-{{- $name := $profile_page.Params.name | default ($username|markdownify) -}}
+{{- $name := $profile_page.Title | default ($username|markdownify) -}}
 {{- with $profile_page -}}
   <a href="{{$profile_page.RelPermalink}}">{{$name}}</a>
 {{- else -}}