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

Basic View Transition Support #1280

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noodp" />

{{/* View Transition */}}
{{/* https://developer.chrome.com/docs/web-platform/view-transitions/cross-document */}}
<style>
@view-transition {
navigation: auto;
}
</style>
{{- /* Paginate */ -}}
{{- /* Paginate in here, To solve the problem of the canonical URL being the same in the pagination */ -}}
{{- /* see more https://github.com/gohugoio/hugo/issues/4507 */ -}}
Expand Down
6 changes: 3 additions & 3 deletions layouts/_default/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
{{- with $image -}}
<div class="featured-image-preview">
<a href="{{ $.RelPermalink }}" aria-label={{ $.Title }}>
{{- dict "Src" . "Title" $.Description "Resources" $.Resources "Loading" "eager" "Optim" true | partial "plugin/image.html" -}}
{{- dict "Src" . "Title" $.Description "Resources" $.Resources "Loading" "eager" "Optim" true "ViewTransitionName" (printf "featured-image-%v" $.Title) | partial "plugin/image.html" -}}
</a>
</div>
{{- end -}}

{{- /* Title */ -}}
<h1 class="single-title">
<h1 class="single-title" style='view-transition-name: {{ (printf "single-title-%v" .Title) | partial "function/stringNormalise.html" | safeCSS }};'>
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
</h1>

{{- /* Meta */ -}}
<div class="post-meta">
<span class="post-author">
<span class="post-author" style='view-transition-name: {{ (printf "post-author-%v" .Title) | partial "function/stringNormalise.html" | safeCSS }};'>
{{- partial "meta/author" . }}
</span>

Expand Down
1 change: 1 addition & 0 deletions layouts/partials/function/stringNormalise.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- return replaceRE "[^A-Za-z0-9]" "-" . -}}
1 change: 1 addition & 0 deletions layouts/partials/plugin/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
{{- end -}}
<img
{{ with .Class }}class="{{ . }}"{{ end }}
{{- with .ViewTransitionName -}}style='view-transition-name: {{ . | partial "function/stringNormalise.html" | safeCSS }};'{{ end }}
loading="{{ $loading }}"
src="{{ $default.RelPermalink | safeURL }}"
srcset="
Expand Down
6 changes: 3 additions & 3 deletions layouts/posts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h2 class="toc-title">{{ T "contents" }}</h2>

<article class="page single print:!tw-w-full print:!tw-max-w-none print:!tw-m-0 print:!tw-p-0">
{{- /* Title */ -}}
<h1 class="single-title">{{ .Title }}</h1>
<h1 class="single-title" style='view-transition-name: {{ (printf "single-title-%v" .Title) | partial "function/stringNormalise.html" | safeCSS }};'>{{ .Title }}</h1>

{{- /* Subtitle */ -}}
{{- with $params.subtitle -}}
Expand All @@ -44,7 +44,7 @@ <h2 class="single-subtitle">{{ . }}</h2>
{{- /* Meta */ -}}
<div class="post-meta">
<div class="post-meta-line">
<span class="post-author">
<span class="post-author" style='view-transition-name: {{ (printf "post-author-%v" .Title) | partial "function/stringNormalise.html" | safeCSS }};'>
{{- partial "meta/author.html" . }}
</span>
{{- with .Params.categories | or .Params.series -}}
Expand Down Expand Up @@ -151,7 +151,7 @@ <h2 class="single-subtitle">{{ . }}</h2>
{{- $image := $params.featuredimage -}}
{{- with $image -}}
<div class="featured-image">
{{- dict "Src" . "Title" $.Description "Resources" $.Resources "Loading" "eager" "Optim" true | partial "plugin/image.html" -}}
{{- dict "Src" . "Title" $.Description "Resources" $.Resources "Loading" "eager" "Optim" true "ViewTransitionName" (printf "featured-image-%v" $.Title) | partial "plugin/image.html" -}}
</div>
{{- end -}}
{{- /* Series list */ -}}
Expand Down
Loading