Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

templates: migrate Research Group template from v1 to v2 blocks #2914

Merged
merged 20 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/wowchemy/layouts/partials/blocks/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{{ end }}

<div class="col-12 {{if eq $columns "2"}}col-lg-8{{end}}">
{{ with $block.content.text }}{{ . | emojify | $page.RenderString }}{{ end }}
{{ with $block.content.text }}<p>{{ . | emojify | $page.RenderString }}</p>{{ end }}

{{ if $use_form }}

Expand Down
74 changes: 74 additions & 0 deletions modules/wowchemy/layouts/partials/blocks/people.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{{/* Wowchemy Blocks: People */}}
{{/* Documentation: https://wowchemy.com/blocks/ */}}
{{/* License: https://github.com/wowchemy/wowchemy-hugo-themes/blob/main/LICENSE.md */}}

{{/* Initialise */}}
{{ $page := .wcPage }}
{{ $block := .wcBlock }}
{{ $show_social := $block.design.show_social | default false }}
{{ $show_interests := $block.design.show_interests | default true }}
{{ $show_organizations := $block.design.show_organizations | default false }}
{{ $show_role := $block.design.show_role | default true }}

<div class="row justify-content-center people-widget">
{{ with $block.content.title }}
<div class="section-heading col-12 mb-3 text-center">
<h1 class="mb-0">{{ . | markdownify | emojify }}</h1>
{{ with $block.content.subtitle }}<p class="mt-1">{{ . | markdownify | emojify }}</p>{{ end }}
</div>
{{ end }}

{{ with $block.content.text }}
<div class="col-md-12">
{{ . | emojify | $page.RenderString }}
</div>
{{ end }}

{{ range $block.content.user_groups }}
{{ $query := where (where site.Pages "Section" "authors") ".Params.user_groups" "intersect" (slice .) }}

{{/* Sort */}}
{{ $sort_by := $block.content.sort_by | default "last_name" }}
{{ if not ( in "last_name first_name title" $sort_by ) }} {{ $sort_by = "last_name" }} {{ end }}
{{ $sort_by = printf ".Params.%s" $sort_by }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we prefix .Params. to the sort_by automatically, we should probably do the same for any other uses of the sort_by option in Wowchemy, such as in the Collections (and Portfolio?) blocks, otherwise different behaviours will be very confusing to users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I also remove the automatic .Params. prefix to align this block to the others.
Although, I think maybe it could be nice to have an autoprefix just if last_name, first_name or title are passed as parameters, since these are the most common options to sort the people.

It could be something like:

{{ if in "last_name first_name title" $sort_by }} {{ $sort_by = printf ".Params.%s" $sort_by }}  {{ end }}

What do you think? Otherwise, I'll just remove it, no problem!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the first letter of the sort_by param is capitalised then it's a built-in Hugo param right, otherwise it's a parameter which requires prefixing with Params.?

I have also observed that users find this Hugo behaviour very confusing and prone to error.

So I suggest we check if first letter of sort_by is capitalised, if it is then pass it as it is, otherwise prefix it. If this works successfully, then let's apply this logic to all instances where sort_by is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to think about this. In principle, I think nothing stops me to create a custom parameter (eg. LastName instead of last_name), so I don't know if this logic can actually be applied.

If you agree, we can close this PR (which I'll immediately follow with a new one to fix the Wowchemy version in go.mod) as it is, so that users need to input .Params.last_name to sort authors by their last name.

Then, I'll open another issue to discuss and investigate about your proposed solution to discover built-in or custom parameters.

Copy link
Collaborator

@gcushen gcushen Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Agos95 the Wowchemy parameters are all standardised to lowercase-underscore convention, so that is fine, we can go ahead and make things easier for the user based on my above comment at #2914 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I added the function in the wowchemy-core module, since it is independent on bootstrap, and I tested it locally.
I also add it in people, collection and portfolio blocks as comments. This is due to the fact that the version of wowchemy-core must be updated (in modules/wowchemy/go.mod) in order to detect the new function, and I don't have any idea on what I should do.

Maybe the best thing is to merge this PR, create a new tag/version for wowchemy-core, and then I can follow with another PR to fix the versions. But I wait for your instructions, since I don't have any experience on this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #2914 (comment)

In order to merge this PR without splitting it into separate PRs for each module change, we will go ahead with the latter suggestion you made.

{{ $sort_ascending := $block.content.sort_ascending | default true }}
{{ $sort_order := cond $sort_ascending "asc" "desc" }}
{{ $query = sort $query $sort_by $sort_order }}

{{if $query | and (gt (len $block.content.user_groups) 1) }}
<div class="col-md-12">
<h2 class="mb-4">{{ . | markdownify }}</h2>
</div>
{{end}}

{{ range $query }}
{{ $avatar := (.Resources.ByType "image").GetMatch "*avatar*" }}
{{/* Get link to user's profile page. */}}
{{ $link := "" }}
{{ with site.GetPage (printf "/authors/%s" (path.Base .File.Dir)) }}
{{ $link = .RelPermalink }}
{{ end }}
<div class="col-12 col-sm-auto people-person">
{{ $src := "" }}
{{ if site.Params.features.avatar.gravatar }}
{{ $src = printf "https://s.gravatar.com/avatar/%s?s=150" (md5 .Params.email) }}
{{ else if $avatar }}
{{ $avatar_image := $avatar.Fill "270x270 Center" }}
{{ $src = $avatar_image.RelPermalink }}
{{ end }}
{{ if $src }}
{{ $avatar_shape := site.Params.features.avatar.shape | default "circle" }}
{{with $link}}<a href="{{.}}">{{end}}<img width="270" height="270" loading="lazy" class="avatar {{if eq $avatar_shape "square"}}avatar-square{{else}}avatar-circle{{end}}" src="{{ $src }}" alt="Avatar">{{if $link}}</a>{{end}}
{{ end }}

<div class="portrait-title">
<h2>{{with $link}}<a href="{{.}}">{{end}}{{ .Title }}{{if $link}}</a>{{end}}</h2>
{{ if and $show_organizations .Params.organizations }}{{ range .Params.organizations }}<h3>{{ .name }}</h3>{{ end }}{{ end }}
{{ if and $show_role .Params.role }}<h3>{{ .Params.role | 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 }}
</div>
</div>
{{ end }}
{{ end }}
</div>
91 changes: 91 additions & 0 deletions modules/wowchemy/layouts/partials/blocks/slider.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{{/* Wowchemy Blocks: Slider */}}
{{/* Documentation: https://wowchemy.com/blocks/ */}}
{{/* License: https://github.com/wowchemy/wowchemy-hugo-themes/blob/main/LICENSE.md */}}

{{/* Initialise */}}
{{ $page := .wcPage }}
{{ $block := .wcBlock }}
{{ $hash_id := .wcIdentifier }}

<!-- Indicators -->
<ol class="carousel-indicators">
{{ range $index, $item := $block.content.slides }}
<li data-target="#{{$hash_id}}" data-slide-to="{{$index}}" {{if eq $index 0}}class="active"{{end}}></li>
{{ end }}
</ol>

<!-- Carousel slides wrapper -->
<div class="carousel-inner">
{{ range $index, $item := $block.content.slides }}

{{ $style_bg := "" }}
{{ $style_filter := "" }}

{{with $block.design.slide_height}}
{{ $style_bg = printf "%s height: %s;" $style_bg . }}
{{end}}

{{ $bg := $item.background}}
{{ with $bg.color }}
{{ $style_bg = printf "%s background-color: %s;" $style_bg (. | default "transparent") }}
{{ end }}

{{ if and $bg.gradient_start $bg.gradient_end }}
{{ $angle := string $bg.gradient_angle | default "90" }}
{{ $style_bg = printf "%sbackground-image: linear-gradient(%sdeg, %s, %s);" $style_bg $angle $bg.gradient_start $bg.gradient_end }}
{{ end }}

{{ if $bg.image.filename }}
{{ $bg_img := resources.Get (printf "media/%s" $bg.image.filename) }}
{{ if $bg_img }}
{{ $style_bg = printf "%sbackground-image: url('%s'); background-repeat: no-repeat; background-position: %s; background-size: %s; " $style_bg $bg_img.Permalink ($bg.image.position | default "center") ($bg.image.size | default "cover") }}
{{ else }}
{{ errorf "Couldn't find `%s` in the `assets/media/` folder - please add it." $bg.image.filename }}
{{ end }}
{{ with $bg.image.filters.brightness }}
{{ $style_filter = printf "%s-webkit-backdrop-filter: brightness(%s); backdrop-filter: brightness(%s);" $style_filter (string .) (string .) }}
{{ end }}
{{ end }}

<div class="carousel-item{{if eq $index 0}} active{{end}} {{with $block.design.is_fullscreen}}fullscreen{{end}}" style="{{$style_bg | safeCSS}}">
<div class="position-absolute d-flex w-100 h-100 justify-content-center align-items-center" style="{{$style_filter | safeCSS}}">
{{/* To prevent control overlap, margins are based on $carousel-control-* in bootstrap-variables.scss */}}
<div class="wg-hero dark container" style="margin-left: 6rem; margin-right: 6rem; text-align: {{$item.align | default "left"}};">
<h1 class="hero-title ">
{{ with $item.title }}{{ . | markdownify | emojify }}{{ end }}
</h1>

{{ with $item.content }}
<p class="hero-lead" style="{{if eq $item.align "center"}}margin: 0 auto 0 auto;{{else if eq $item.align "right"}}margin-left: auto; margin-right: 0{{end}}">
{{ . | emojify | $page.RenderString }}
</p>
{{ end }}

{{ if $item.link.url }}
{{ $pack := $item.link.icon_pack | default "fas" }}
{{ $pack_prefix := $pack }}
{{ if in (slice "fab" "fas" "far" "fal") $pack }}
{{ $pack_prefix = "fa" }}
{{ end }}
<p>
<a href="{{ $item.link.url }}" class="btn btn-light btn-lg mt-3">
{{- with $item.link.icon -}}<i class="{{ $pack }} {{ $pack_prefix }}-{{ . }}" style="padding-right: 10px;"></i>{{- end -}}
{{- $item.link.text | emojify | markdownify | safeHTML -}}
</a>
</p>
{{ end }}
</div>
</div>
</div>
{{ end }}
</div>

<!-- Left and right controls -->
<a class="carousel-control-prev" href="#{{$hash_id}}" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#{{$hash_id}}" data-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="sr-only">Next</span>
</a>
67 changes: 67 additions & 0 deletions starters/research-group/content/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
# Leave the homepage title empty to use the site title
title:
date: 2022-10-24
type: landing

sections:
- block: hero
content:
title: |
Wowchemy
Research Group
image:
filename: welcome.jpg
text: |
<br>

The **Wowchemy Research Group** has been a center of excellence for Artificial Intelligence research, teaching, and practice since its founding in 2016.

- block: collection
content:
title: Latest News
subtitle:
text:
count: 5
filters:
author: ''
category: ''
exclude_featured: false
publication_type: ''
tag: ''
offset: 0
order: desc
page_type: post
design:
view: card
columns: '1'

- block: markdown
content:
title:
subtitle: ''
text:
design:
columns: '1'
background:
image:
filename: coders.jpg
filters:
brightness: 1
parallax: false
position: center
size: cover
text_color_light: true
spacing:
padding: ['20px', '0', '20px', '0']
css_class: fullscreen

- block: markdown
content:
title:
subtitle:
text: |
{{% cta cta_link="./people/" cta_text="Meet the team →" %}}
design:
columns: '1'
---
4 changes: 4 additions & 0 deletions starters/research-group/content/authors/admin/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# Display name
title: Nelson Bighetti

# Full Name (for SEO)
first_name: Nelson
last_name: Bighetti

# Is this the primary user of the site?
superuser: true

Expand Down
6 changes: 5 additions & 1 deletion starters/research-group/content/authors/吳恩達/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
# Display name
title: 吳恩達
title: Alice Wu 吳恩達

# Full name (for SEO)
first_name: Alice
last_name: Wu

# Username (this should match the folder name)
authors:
Expand Down
57 changes: 0 additions & 57 deletions starters/research-group/content/contact/contact.md

This file was deleted.

28 changes: 0 additions & 28 deletions starters/research-group/content/contact/image.md

This file was deleted.

Loading