Compare commits

...

16 Commits

Author SHA1 Message Date
Wen Junhua e0f24bc593
Merge a15820cb37 into 7a9020b52f 2023-11-27 07:56:38 +11:00
James Panther 7a9020b52f
📝 Update changelog 2023-11-27 07:55:23 +11:00
James Panther a431f466dc
🔀 Merge pull request #693 from stereobooster/picture-new
feat: picture partial
2023-11-27 07:50:14 +11:00
Wen Junhua a15820cb37 fix: fix warning 2023-11-26 23:02:47 +08:00
stereobooster c8b33ae51e refactoring 2023-11-26 14:52:34 +01:00
stereobooster 0c6c30fec1 do not lazy load the feature image 2023-11-26 14:42:26 +01:00
stereobooster 6eb34e7124 use 2x instead of x2 in query params 2023-11-26 14:23:42 +01:00
stereobooster 11fd48f5d0 potential solution to screenshot 2023-11-26 14:14:49 +01:00
stereobooster 8cfe33965b use original image as backup for srcset 2023-11-26 14:14:49 +01:00
stereobooster 3ffe2b1002 do not upscale images in picture shortcode 2023-11-26 14:14:49 +01:00
stereobooster 978791808f integrate in single.html 2023-11-26 14:14:48 +01:00
stereobooster c237e04744 Example of integration of picture partial 2023-11-26 14:14:48 +01:00
Wen Junhua 8a8ae76bf2 docs: update author docs 2023-11-25 12:51:22 +08:00
Wen Junhua 4b3d31eff3 fix: move param under languages.xx.toml params.author 2023-11-25 12:29:10 +08:00
Wen Junhua 394a018e08 feat: add warning when config is incorrect 2023-11-12 19:09:16 +08:00
Wen Junhua 2dd90e3d20 feat: move author field to params.toml 2023-11-12 18:52:28 +08:00
24 changed files with 210 additions and 164 deletions

View File

@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Warning when building if links to markdown files cannot be resolved ([#691](https://github.com/jpanther/congo/pull/691)) - Warning when building if links to markdown files cannot be resolved ([#691](https://github.com/jpanther/congo/pull/691))
### Changed
- Refactored image logic into a new `picture.html` partial ([#693](https://github.com/jpanther/congo/pull/693))
### Removed ### Removed
- Fathom Analytics custom domain parameter as this is no longer supported by Fathom - Fathom Analytics custom domain parameter as this is no longer supported by Fathom

View File

@ -12,7 +12,7 @@ title = "Congo"
# mainSections = ["section1", "section2"] # mainSections = ["section1", "section2"]
# description = "My awesome website" # description = "My awesome website"
[author] [params.author]
# name = "Your name here" # name = "Your name here"
# image = "img/author.jpg" # image = "img/author.jpg"
# headline = "I'm only human" # headline = "I'm only human"

View File

@ -12,6 +12,7 @@ autoSwitchAppearance = true
enableSearch = false enableSearch = false
enableCodeCopy = false enableCodeCopy = false
enableImageLazyLoading = true enableImageLazyLoading = true
enableImageWebp = true
# robots = "" # robots = ""
fingerprintAlgorithm = "sha256" fingerprintAlgorithm = "sha256"

View File

@ -12,7 +12,7 @@ copyright = "© 2023 Congo contributors"
mainSections = ["samples"] mainSections = ["samples"]
description = "Ein leistungsstarkes, leichtgewichtiges Theme für Hugo, das mit Tailwind CSS erstellt wurde." description = "Ein leistungsstarkes, leichtgewichtiges Theme für Hugo, das mit Tailwind CSS erstellt wurde."
[author] [params.author]
name = "Congo" name = "Congo"
image = "img/author.jpg" image = "img/author.jpg"
headline = "Nicht dein Durschnitts-Theme!" headline = "Nicht dein Durschnitts-Theme!"

View File

@ -12,7 +12,7 @@ copyright = "© 2023 Congo contributors"
mainSections = ["samples"] mainSections = ["samples"]
description = "A powerful, lightweight theme for Hugo built with Tailwind CSS." description = "A powerful, lightweight theme for Hugo built with Tailwind CSS."
[author] [params.author]
name = "Congo" name = "Congo"
image = "img/author.jpg" image = "img/author.jpg"
headline = "Not your ordinary theme!" headline = "Not your ordinary theme!"

View File

@ -12,7 +12,7 @@ copyright = "© 2023 Congo contributors"
mainSections = ["samples"] mainSections = ["samples"]
description = "Un tema poderoso y liviano para Hugo creado con Tailwind CSS." description = "Un tema poderoso y liviano para Hugo creado con Tailwind CSS."
[author] [params.author]
name = "Congo" name = "Congo"
image = "img/author.jpg" image = "img/author.jpg"
headline = "¡No es tu tema ordinario!" headline = "¡No es tu tema ordinario!"

View File

@ -12,7 +12,7 @@ copyright = "© 2023 Congo contributors"
mainSections = ["samples"] mainSections = ["samples"]
description = "Tailwind CSSをベースに開発された強力で軽量なHugo向けテーマ" description = "Tailwind CSSをベースに開発された強力で軽量なHugo向けテーマ"
[author] [params.author]
name = "Congo" name = "Congo"
image = "img/author.jpg" image = "img/author.jpg"
headline = "ただならぬテーマ!" headline = "ただならぬテーマ!"

View File

@ -12,6 +12,7 @@ autoSwitchAppearance = true
enableSearch = true enableSearch = true
enableCodeCopy = true enableCodeCopy = true
enableImageLazyLoading = true enableImageLazyLoading = true
enableImageWebp = true
# robots = "" # robots = ""
fingerprintAlgorithm = "sha256" fingerprintAlgorithm = "sha256"

View File

@ -100,11 +100,11 @@ Congoは現在、以下の言語に対応しています:
|`params.dateFormat`|`"2 January 2006"`|日付の書式。許容される書式については、[Hugo docs](https://gohugo.io/functions/format/#gos-layout-string)を参照してください。| |`params.dateFormat`|`"2 January 2006"`|日付の書式。許容される書式については、[Hugo docs](https://gohugo.io/functions/format/#gos-layout-string)を参照してください。|
|`params.mainSections`|_Not set_|最近の記事リストに表示するセクション。指定されていない場合は、記事の数が最も多いセクションが使われます。| |`params.mainSections`|_Not set_|最近の記事リストに表示するセクション。指定されていない場合は、記事の数が最も多いセクションが使われます。|
|`params.description`|_Not set_|ウェブサイトの説明。これはサイトのメタデータに使用されます。| |`params.description`|_Not set_|ウェブサイトの説明。これはサイトのメタデータに使用されます。|
|`author.name`|_Not set_|著者の名前。これは記事のフッターと、プロフィールレイアウトが使用されている場合にホームページに表示されます。| |`params.author.name`|_Not set_|著者の名前。これは記事のフッターと、プロフィールレイアウトが使用されている場合にホームページに表示されます。|
|`author.image`|_Not set_|著者の画像ファイルへのパス。画像は縦横比1:1で、 `assets/` に置くこと。| |`params.author.image`|_Not set_|著者の画像ファイルへのパス。画像は縦横比1:1で、 `assets/` に置くこと。|
|`author.headline`|_Not set_|著者の見出しを含むMarkdown文字列。プロフィールのトップページで著者の名前の下に表示されます。| |`params.author.headline`|_Not set_|著者の見出しを含むMarkdown文字列。プロフィールのトップページで著者の名前の下に表示されます。|
|`author.bio`|_Not set_|著者の経歴を含むMarkdown文字列。記事のフッターに表示されます。| |`params.author.bio`|_Not set_|著者の経歴を含むMarkdown文字列。記事のフッターに表示されます。|
|`author.links`|_Not set_|著者の詳細とともに表示するリンク。設定ファイルにはリンクの例が含まれており、コメントを外すだけで有効にすることができます。リンクが表示される順番は、配列に表示される順番によって決まります。 `assets/icons/` に対応するSVGアイコンを用意することで、カスタムリンクを追加することもできます。| |`params.author.links`|_Not set_|著者の詳細とともに表示するリンク。設定ファイルにはリンクの例が含まれており、コメントを外すだけで有効にすることができます。リンクが表示される順番は、配列に表示される順番によって決まります。 `assets/icons/` に対応するSVGアイコンを用意することで、カスタムリンクを追加することもできます。|
<!-- prettier-ignore-end --> <!-- prettier-ignore-end -->
### メニュー ### メニュー

View File

@ -100,11 +100,11 @@ The default file can be used as a template to create additional languages, or re
|`params.dateFormat`|`"2 January 2006"`|How dates are formatted in this language. Refer to the [Hugo docs](https://gohugo.io/functions/format/#gos-layout-string) for acceptable formats.| |`params.dateFormat`|`"2 January 2006"`|How dates are formatted in this language. Refer to the [Hugo docs](https://gohugo.io/functions/format/#gos-layout-string) for acceptable formats.|
|`params.mainSections`|_Not set_|The sections that should be displayed in the recent articles list. If not provided the section with the greatest number of articles is used.| |`params.mainSections`|_Not set_|The sections that should be displayed in the recent articles list. If not provided the section with the greatest number of articles is used.|
|`params.description`|_Not set_|The website description. This will be used in the site metadata.| |`params.description`|_Not set_|The website description. This will be used in the site metadata.|
|`author.name`|_Not set_|The author's name. This will be displayed in article footers, and on the homepage when the profile layout is used.| |`params.author.name`|_Not set_|The author's name. This will be displayed in article footers, and on the homepage when the profile layout is used.|
|`author.image`|_Not set_|Path to the image file of the author. The image should be a 1:1 aspect ratio and placed in the site's `assets/` folder.| |`params.author.image`|_Not set_|Path to the image file of the author. The image should be a 1:1 aspect ratio and placed in the site's `assets/` folder.|
|`author.headline`|_Not set_|A Markdown string containing the author's headline. It will be displayed on the profile homepage under the author's name.| |`params.author.headline`|_Not set_|A Markdown string containing the author's headline. It will be displayed on the profile homepage under the author's name.|
|`author.bio`|_Not set_|A Markdown string containing the author's bio. It will be displayed in article footers.| |`params.author.bio`|_Not set_|A Markdown string containing the author's bio. It will be displayed in article footers.|
|`author.links`|_Not set_|The links to display alongside the author's details. The config file contains example links which can simply be uncommented to enable. The order that the links are displayed is determined by the order they appear in the array. Custom links can be added by providing corresponding SVG icon assets in `assets/icons/`.| |`params.author.links`|_Not set_|The links to display alongside the author's details. The config file contains example links which can simply be uncommented to enable. The order that the links are displayed is determined by the order they appear in the array. Custom links can be added by providing corresponding SVG icon assets in `assets/icons/`.|
<!-- prettier-ignore-end --> <!-- prettier-ignore-end -->
### Menus ### Menus

View File

@ -38,7 +38,7 @@ languageCode = "en"
title = "My awesome website" title = "My awesome website"
[author] [params.author]
name = "My name" name = "My name"
image = "img/author.jpg" image = "img/author.jpg"
headline = "A generally awesome human" headline = "A generally awesome human"
@ -48,7 +48,7 @@ links = [
] ]
``` ```
`[author]` はウェブサイト上でどのように著者情報を表示するかを決定します。画像はサイトの `assets/` に置きましょう。リンクはリストの記述順に沿って表示されます。 `[params.author]` はウェブサイト上でどのように著者情報を表示するかを決定します。画像はサイトの `assets/` に置きましょう。リンクはリストの記述順に沿って表示されます。
各設定に関する詳細情報は、[設定]({{< ref "configuration" >}})セクションで説明されています。 各設定に関する詳細情報は、[設定]({{< ref "configuration" >}})セクションで説明されています。

View File

@ -38,7 +38,7 @@ The language code in the language config filename should match the `languageCode
title = "My awesome website" title = "My awesome website"
[author] [params.author]
name = "My name" name = "My name"
image = "img/author.jpg" image = "img/author.jpg"
headline = "A generally awesome human" headline = "A generally awesome human"
@ -48,7 +48,7 @@ links = [
] ]
``` ```
The `[author]` configuration determines how the author information is displayed on the website. The image should be placed in the site's `assets/` folder. Links will be displayed in the order they are listed. The `[params.author]` configuration determines how the author information is displayed on the website. The image should be placed in the site's `assets/` folder. Links will be displayed in the order they are listed.
If you need extra detail, further information about each of these configuration options, is covered in the [Configuration]({{< ref "configuration" >}}) section. If you need extra detail, further information about each of these configuration options, is covered in the [Configuration]({{< ref "configuration" >}}) section.

View File

@ -1,64 +1,28 @@
{{ $url := urls.Parse .Destination }} {{ $url := urls.Parse .Destination }}
{{ $altText := .Text }} {{ $altText := .Text }}
{{ $caption := .Title }} {{ $caption := .Title }}
{{ $lazyLoad := $.Page.Site.Params.enableImageLazyLoading | default true }} {{ $class := "mx-auto my-0 rounded-md" }}
{{ if findRE "^https?" $url.Scheme }}
<figure> {{ $file := $url.Path }}
<img {{ $img := .Page.Resources.GetMatch $file }}
class="mx-auto my-0 rounded-md" {{- if and (not $img) .Page.File }}
src="{{ $url.String }}" {{ $path := path.Join .Page.File.Dir $file }}
alt="{{ $altText }}" {{ $img = resources.Get $path }}
{{ if $lazyLoad }} {{ end -}}
loading="lazy"
{{ end }} {{/* https://github.com/gohugoio/hugo/pull/10666 */}}
/> {{- $params := $url.Query -}}
{{- $x2Param := $params.Get "2x" -}}
{{- $x2 := false -}}
{{- if eq $x2Param "true" -}}
{{- $x2 = true -}}
{{- end -}}
<figure>
{{- with $img -}}
{{ partial "picture.html" (dict "img" . "alt" $altText "class" $class "x2" $x2) }}
{{- else -}}
<img src="{{ .Destination | safeURL }}" alt="{{ $altText }}" class="{{ $class }}"/>
{{- end -}}
{{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }} {{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }}
</figure> </figure>
{{ else }}
{{ $resource := "" }}
{{ if $.Page.Resources.GetMatch ($url.String) }}
{{ $resource = $.Page.Resources.GetMatch ($url.String) }}
{{ else if resources.GetMatch ($url.String) }}
{{ $resource = resources.Get ($url.String) }}
{{ end }}
{{ with $resource }}
<figure>
<img
class="mx-auto my-0 rounded-md"
{{ if eq .MediaType.SubType "svg" }}
src="{{ .RelPermalink }}"
{{ else }}
width="{{ .Width }}"
height="{{ .Height }}"
{{ if lt .Width 660 }}
src="{{ .RelPermalink }}"
{{ else }}
srcset="
{{- (.Resize "330x").RelPermalink }} 330w,
{{- (.Resize "660x").RelPermalink }} 660w,
{{- (.Resize "1024x").RelPermalink }} 1024w,
{{- (.Resize "1320x").RelPermalink }} 2x"
src="{{ (.Resize "660x").RelPermalink }}"
{{ end }}
{{ end }}
alt="{{ $altText }}"
{{ if $lazyLoad }}
loading="lazy"
{{ end }}
/>
{{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }}
</figure>
{{ else }}
<figure>
<img
class="mx-auto my-0 rounded-md"
src="{{ $url.String }}"
alt="{{ $altText }}"
{{ if $lazyLoad }}
loading="lazy"
{{ end }}
/>
{{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }}
</figure>
{{ end }}
{{ end }}

View File

@ -15,25 +15,9 @@
</div> </div>
{{ with $feature }} {{ with $feature }}
<div class="prose"> <div class="prose">
<img {{ $altText := $.Params.featureAlt | default $.Params.coverAlt | default "" }}
class="mb-6 -mt-4 rounded-md" {{ $class := "mb-6 -mt-4 rounded-md" }}
{{ if eq .MediaType.SubType "svg" }} {{ partial "picture.html" (dict "img" . "alt" $altText "class" $class "lazy" false) }}
src="{{ .RelPermalink }}"
{{ else }}
width="{{ .Width }}"
height="{{ .Height }}"
{{ if lt .Width 660 }}
src="{{ .RelPermalink }}"
{{ else }}
srcset="
{{- (.Resize "330x").RelPermalink }} 330w,
{{- (.Resize "660x").RelPermalink }} 660w,
{{- (.Resize "1024x").RelPermalink }} 1024w,
{{- (.Resize "1320x").RelPermalink }} 2x"
{{ end }}
{{ end }}
alt="{{ $.Params.featureAlt | default $.Params.coverAlt | default "" }}"
/>
{{ with $.Params.coverCaption }} {{ with $.Params.coverCaption }}
<figcaption class="mb-6 -mt-3 text-center">{{ . | markdownify }}</figcaption> <figcaption class="mb-6 -mt-3 text-center">{{ . | markdownify }}</figcaption>
{{ end }} {{ end }}

View File

@ -1,4 +1,4 @@
{{ with .Site.Author.links }} {{ with .Site.Language.Params.Author.links }}
<div class="flex flex-wrap text-neutral-400 dark:text-neutral-500"> <div class="flex flex-wrap text-neutral-400 dark:text-neutral-500">
{{ range $links := . }} {{ range $links := . }}
{{ range $name, $url := $links }} {{ range $name, $url := $links }}

View File

@ -1,6 +1,6 @@
{{ if .Params.showAuthor | default (.Site.Params.article.showAuthor | default true) }} {{ if .Params.showAuthor | default (.Site.Params.article.showAuthor | default true) }}
<div class="flex"> <div class="flex">
{{ with .Site.Author.image }} {{ with .Site.Language.Params.Author.image }}
{{ $authorImage := resources.Get . }} {{ $authorImage := resources.Get . }}
{{ if $authorImage }} {{ if $authorImage }}
{{ $authorImage := $authorImage.Fill "192x192 Center" }} {{ $authorImage := $authorImage.Fill "192x192 Center" }}
@ -8,7 +8,7 @@
class="!mb-0 !mt-0 me-4 h-24 w-24 rounded-full" class="!mb-0 !mt-0 me-4 h-24 w-24 rounded-full"
width="96" width="96"
height="96" height="96"
alt="{{ $.Site.Author.name | default "Author" }}" alt="{{ $.Site.Language.Params.Author.name | default "Author" }}"
src="{{ $authorImage.RelPermalink }}" src="{{ $authorImage.RelPermalink }}"
{{ if $.Site.Params.enableImageLazyLoading | default true }} {{ if $.Site.Params.enableImageLazyLoading | default true }}
loading="lazy" loading="lazy"
@ -17,7 +17,7 @@
{{ end }} {{ end }}
{{ end }} {{ end }}
<div class="place-self-center"> <div class="place-self-center">
{{ with .Site.Author.name | markdownify | emojify }} {{ with .Site.Language.Params.Author.name | markdownify | emojify }}
<div class="text-[0.6rem] uppercase leading-3 text-neutral-500 dark:text-neutral-400"> <div class="text-[0.6rem] uppercase leading-3 text-neutral-500 dark:text-neutral-400">
{{ i18n "author.byline_title" | markdownify | emojify }} {{ i18n "author.byline_title" | markdownify | emojify }}
</div> </div>
@ -25,7 +25,7 @@
{{ . }} {{ . }}
</div> </div>
{{ end }} {{ end }}
{{ with .Site.Author.bio | markdownify | emojify }} {{ with .Site.Language.Params.Author.bio | markdownify | emojify }}
<div class="text-sm text-neutral-700 dark:text-neutral-400">{{ . }}</div> <div class="text-sm text-neutral-700 dark:text-neutral-400">{{ . }}</div>
{{ end }} {{ end }}
<div class="text-2xl sm:text-lg">{{ partialCached "author-links.html" . }}</div> <div class="text-2xl sm:text-lg">{{ partialCached "author-links.html" . }}</div>

View File

@ -86,7 +86,7 @@
{{- else }} {{- else }}
&copy; &copy;
{{ now.Format "2006" }} {{ now.Format "2006" }}
{{ .Site.Author.name | markdownify | emojify }} {{ .Site.Language.Params.Author.name | markdownify | emojify }}
{{- end }} {{- end }}
</p> </p>
{{ end }} {{ end }}

View File

@ -7,3 +7,6 @@
{{ if ne .Params.logo nil }} {{ if ne .Params.logo nil }}
{{ warnf "[CONGO] Theme parameter `logo` has been renamed to `header.logo`. Please update your site configuration." }} {{ warnf "[CONGO] Theme parameter `logo` has been renamed to `header.logo`. Please update your site configuration." }}
{{ end }} {{ end }}
{{ if .Author }}
{{ warnf "[CONGO] Theme parameter `author` block in `languages.xx.toml` has been renamed to `.params.author`. Please update your site configuration." }}
{{ end }}

View File

@ -117,8 +117,8 @@
{{/* Schema */}} {{/* Schema */}}
{{ partial "schema.html" . }} {{ partial "schema.html" . }}
{{/* Me */}} {{/* Me */}}
{{ with .Site.Author.name }}<meta name="author" content="{{ . }}" />{{ end }} {{ with .Site.Language.Params.Author.name }}<meta name="author" content="{{ . }}" />{{ end }}
{{ with .Site.Author.links }} {{ with .Site.Language.Params.Author.links }}
{{ range $links := . }} {{ range $links := . }}
{{ range $name, $url := $links }}<link href="{{ $url }}" rel="me" />{{ end }} {{ range $name, $url := $links }}<link href="{{ $url }}" rel="me" />{{ end }}
{{ end }} {{ end }}

View File

@ -4,7 +4,7 @@
{{ end }} flex flex-col items-center justify-center text-center" {{ end }} flex flex-col items-center justify-center text-center"
> >
<header class="mb-3 flex flex-col items-center"> <header class="mb-3 flex flex-col items-center">
{{ with .Site.Author.image }} {{ with .Site.Language.Params.Author.image }}
{{ $authorImage := resources.Get . }} {{ $authorImage := resources.Get . }}
{{ if $authorImage }} {{ if $authorImage }}
{{ $authorImage := $authorImage.Fill "288x288 Center" }} {{ $authorImage := $authorImage.Fill "288x288 Center" }}
@ -12,15 +12,15 @@
class="mb-2 h-36 w-36 rounded-full" class="mb-2 h-36 w-36 rounded-full"
width="144" width="144"
height="144" height="144"
alt="{{ $.Site.Author.name | default "Author" }}" alt="{{ $.Site.Language.Params.Author.name | default "Author" }}"
src="{{ $authorImage.RelPermalink }}" src="{{ $authorImage.RelPermalink }}"
/> />
{{ end }} {{ end }}
{{ end }} {{ end }}
<h1 class="text-4xl font-extrabold"> <h1 class="text-4xl font-extrabold">
{{ .Site.Author.name | default .Site.Title }} {{ .Site.Language.Params.Author.name | default .Site.Title }}
</h1> </h1>
{{ with .Site.Author.headline }} {{ with .Site.Language.Params.Author.headline }}
<h2 class="text-xl text-neutral-500 dark:text-neutral-400"> <h2 class="text-xl text-neutral-500 dark:text-neutral-400">
{{ . | markdownify | emojify }} {{ . | markdownify | emojify }}
</h2> </h2>

View File

@ -0,0 +1,112 @@
{{ $img := .img }}
{{ $alt := .alt }}
{{ $class := .class }}
{{ $lazy := .lazy | default $.Page.Site.Params.enableImageLazyLoading | default true }}
{{ $webp := .webp | default $.Page.Site.Params.enableImageWebp | default true }}
{{ $lqip := .lqip | default false }}
{{ $x2 := .x2 | default false }}
{{ with $img }}
{{ if (eq .MediaType.SubType "svg") }}
{{ $width := ""}}
{{ $height := ""}}
{{ $svgContent := .Content }}
{{ range (findRESubmatch `<svg[^>]*width=["']([.0-9]*)["'a-zA-Z]` $svgContent 1) }}
{{ $width = index . 1 }}
{{ end }}
{{ range (findRESubmatch `<svg[^>]*height=["']([.0-9]*)["'a-zA-Z]` $svgContent 1) }}
{{ $height = index . 1 }}
{{ end }}
{{ if (eq "" $width $height) }}
{{ range (findRESubmatch `<svg[^>]*viewBox=["']?([.0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*)` $svgContent 1) }}
{{ $width = index . 3 }}
{{ $height = index . 4 }}
{{ end }}
{{ end }}
{{ if (eq "" $width $height) }}
{{ warnf "Can't detect width and height for SVG %s" .RelPermalink }}
{{/* do not use lazy without dimensions */}}
{{ $lazy = false }}
{{ end }}
<picture {{ with $class }} class="{{ . }}" {{ end }}>
<img
src="{{ .RelPermalink }}"
{{ with $width }} width="{{ . }}" {{ end }}
{{ with $height }} height="{{ . }}" {{ end }}
{{ with $class }} class="{{ . }}" {{ end }}
{{ with $alt }} alt="{{ . }}" {{ end }}
{{ with $lazy }} loading="lazy" decoding="async" {{ end }}
>
</picture>
{{ else }}
<picture
{{ with $class }} class="{{ . }}" {{ end }}
{{ if $lqip }}
{{ $bg := (.Resize "20x webp q20").Content | base64Encode }}
style="background-image:url(data:image/webp;base64,{{ $bg }});background-size:cover"
{{ end }}
>
{{ $width := .Width }}
{{ $height := .Height }}
{{ if $x2 }}
{{ $width = div .Width 2 }}
{{ $height = div .Height 2 }}
{{ end }}
{{ if $webp }}
<source
{{ if lt .Width 660 }}
{{ with .Resize (printf "%dx%d webp" .Width .Height) }}
src="{{ .RelPermalink }}"
{{ end }}
{{ else }}
srcset="
{{- (.Resize "330x webp").RelPermalink }} 330w,
{{- (.Resize "660x webp").RelPermalink }} 660w
{{ if gt .Width 1024 }}
,{{ (.Resize "1024x webp").RelPermalink }} 1024w
{{ else }}
{{ with .Resize (printf "%dx%d webp" .Width .Height) }}
,{{ .RelPermalink }} {{ .Width }}w
{{ end }}
{{ end }}
{{ if gt .Width 1320 }}
,{{ (.Resize "1320x webp").RelPermalink }} 2x
{{ else }}
{{ with .Resize (printf "%dx%d webp" .Width .Height) }}
,{{ .RelPermalink }} {{ .Width }}w
{{ end }}
{{ end }}"
src="{{ (.Resize "660x webp").RelPermalink }}"
{{ end }}
type="image/webp"
/>
{{ end }}
<img
src="{{ .RelPermalink }}"
width="{{ $width }}"
height="{{ $height }}"
{{ with $class }} class="{{ . }}" {{ end }}
{{ with $alt }} alt="{{ . }}" {{ end }}
{{ with $lazy }} loading="lazy" decoding="async" {{ end }}
{{ if lt .Width 660 }}
src="{{ .RelPermalink }}"
{{ else }}
srcset="
{{- (.Resize "330x").RelPermalink }} 330w,
{{- (.Resize "660x").RelPermalink }} 660w
{{ if gt .Width 1024 }}
,{{ (.Resize "1024x").RelPermalink }} 1024w
{{ else }}
,{{ .RelPermalink }} {{ .Width }}w
{{ end }}
{{ if gt .Width 1320 }}
,{{ (.Resize "1320x").RelPermalink }} 2x
{{ else }}
,{{ .RelPermalink }} {{ .Width }}w
{{ end }}"
src="{{ (.Resize "660x").RelPermalink }}"
{{ end }}
>
</picture>
{{ end }}
{{ end }}

View File

@ -11,7 +11,7 @@
{{ with .Site.Params.keywords }}"keywords": {{ . }},{{ end }} {{ with .Site.Params.keywords }}"keywords": {{ . }},{{ end }}
"publisher" : { "publisher" : {
"@type": "Person", "@type": "Person",
"name": "{{ .Site.Author.name | safeJS }}" "name": "{{ .Site.Language.Params.Author.name | safeJS }}"
} }
} }
</script> </script>
@ -30,7 +30,7 @@
"url" : "{{ .Permalink }}", "url" : "{{ .Permalink }}",
"author" : { "author" : {
"@type": "Person", "@type": "Person",
"name": "{{ .Site.Author.name | safeJS }}" "name": "{{ .Site.Language.Params.Author.name | safeJS }}"
}, },
{{ with .PublishDate }}"copyrightYear": "{{ .Format "2006" }}",{{ end }} {{ with .PublishDate }}"copyrightYear": "{{ .Format "2006" }}",{{ end }}
{{ with .Date }}"dateCreated": "{{ .Format $iso8601 }}",{{ end }} {{ with .Date }}"dateCreated": "{{ .Format $iso8601 }}",{{ end }}

View File

@ -6,45 +6,23 @@
{{ $caption := .Get "caption" }} {{ $caption := .Get "caption" }}
{{ $href := .Get "href" }} {{ $href := .Get "href" }}
{{ $class := .Get "class" }} {{ $class := .Get "class" }}
{{ $file := $url.Path }}
{{ $img := .Page.Resources.GetMatch $file }}
{{- if and (not $img) .Page.File }}
{{ $path := path.Join .Page.File.Dir $file }}
{{ $img = resources.Get $path }}
{{ end -}}
<figure{{ with $class }} class="{{ . }}"{{ end }}> <figure{{ with $class }} class="{{ . }}"{{ end }}>
{{ with $href }}<a href="{{ . }}">{{ end }} {{ with $href }}<a href="{{ . }}">{{ end }}
<img
class="mx-auto my-0 rounded-md" {{- with $img -}}
alt="{{ $altText }}" {{ partial "picture.html" (dict "img" . "alt" $altText "class" $class) }}
{{ if .Site.Params.enableImageLazyLoading | default true }} {{- else -}}
loading="lazy" <img src="{{ $url.String }}" alt="{{ $altText }}" class="{{ $class }}"/>
{{ end }} {{- end -}}
{{ if findRE "^https?" $url.Scheme }}
src="{{ $url.String }}"
{{ else }}
{{ $resource := "" }}
{{ if $.Page.Resources.GetMatch ($url.String) }}
{{ $resource = $.Page.Resources.GetMatch ($url.String) }}
{{ else if resources.GetMatch ($url.String) }}
{{ $resource = resources.Get ($url.String) }}
{{ end }}
{{ with $resource }}
{{ if eq .MediaType.SubType "svg" }}
src="{{ .RelPermalink }}"
{{ else }}
width="{{ .Width }}"
height="{{ .Height }}"
{{ if lt .Width 660 }}
src="{{ .RelPermalink }}"
{{ else }}
srcset="
{{- (.Resize "330x").RelPermalink }} 330w,
{{- (.Resize "660x").RelPermalink }} 660w,
{{- (.Resize "1024x").RelPermalink }} 1024w,
{{- (.Resize "1320x").RelPermalink }} 2x"
src="{{ (.Resize "660x").RelPermalink }}"
{{ end }}
{{ end }}
{{ else }}
src="{{ $url.String }}"
{{ end }}
{{ end }}
/>
{{ with $href }}</a>{{ end }} {{ with $href }}</a>{{ end }}
{{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }} {{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }}
</figure> </figure>

View File

@ -4,17 +4,16 @@
{{- if .Get "href" -}} {{- if .Get "href" -}}
<a href="{{ .Get "href" }}"> <a href="{{ .Get "href" }}">
{{- end -}} {{- end -}}
<img src="{{ $image.RelPermalink }}"
{{- if or (.Get "alt") (.Get "caption") }} {{ $altText := "" }}
alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify | plainify }}{{ end }}" {{ with .Get "alt" }}
{{- end -}} {{ $altText = . }}
{{ if .Site.Params.enableImageLazyLoading | default true }} {{ else }}
loading="lazy" {{ $altText = (.Get "caption") | markdownify | plainify }}
{{ end }} {{ end }}
width="100%"
height="auto" {{ partial "picture.html" (dict "img" $image "alt" $altText "x2" true) }}
style="max-width:{{ div $image.Width 2 }}px; max-height:{{ div $image.Height 2 }}px;"
/>
{{- if .Get "href" }}</a>{{ end -}} {{- if .Get "href" }}</a>{{ end -}}
{{- if .Get "caption" -}} {{- if .Get "caption" -}}
<figcaption> <figcaption>