Skip to content

Commit

Permalink
feat: make taxonomy URLs singular
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
gcushen committed Apr 15, 2020
1 parent f075bc2 commit 601620c
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 35 deletions.
7 changes: 7 additions & 0 deletions exampleSite/config/_default/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/content/authors/admin/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# Display name
name: Nelson Bighetti
title: Nelson Bighetti

# Username (this should match the folder name)
authors:
Expand Down
2 changes: 1 addition & 1 deletion layouts/authors/terms.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 2 additions & 4 deletions layouts/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. */ -}}
Expand All @@ -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 -}}
Expand All @@ -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 -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/functions/get_author_name.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
40 changes: 21 additions & 19 deletions layouts/partials/page_author_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 */}}
2 changes: 1 addition & 1 deletion layouts/partials/page_metadata_authors.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down
6 changes: 3 additions & 3 deletions layouts/partials/site_head.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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="{{.}}">
Expand All @@ -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>
6 changes: 3 additions & 3 deletions layouts/partials/widgets/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/widgets/people.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h2 class="mb-4">{{ . | markdownify }}</h2>
{{ 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 }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/shortcodes/mention.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down

0 comments on commit 601620c

Please sign in to comment.