Skip to content

Commit

Permalink
fix: deprecate site.Author
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Aug 5, 2024
1 parent b3fde07 commit 82a54e6
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 47 deletions.
21 changes: 0 additions & 21 deletions exampleSite/config/_default/author.toml

This file was deleted.

23 changes: 23 additions & 0 deletions exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,26 @@ paypal="razonyang"
patreon="razonyang"
# tipeee="yourtipeeeaccount-fr"
# rss = "" # Disable RSS link

[author]
name = "HBS (Hugo Bootstrap Theme)"
# avatar = "images/profile.png" # Avatar image. Default to "images/profile.webp".
bio = "Fast, responsive, multipurpose, open source (MIT license) and feature-rich Hugo theme."
company = 'Company'
# company = '<a href="https://example.com" target="_blank" rel="noopener noreferrer">Company</a>'
location = "Earth"
# alternatives:
# location = "<a href='https://www.openstreetmap.org/search?query=Earth'>Earth</a>"
# location = "<a href='https://www.google.com/maps/search/Earth'>Earth</a>"
# about = "https://domain.tld" # The external about page. The internal about page will be used if not set.

[author.params]
#layout = "compact"

[author.social]
email = "razonyang@gmail.com"
github = "razonyang/hugo-theme-bootstrap"
twitter = "razonyang"
patreon = "razonyang"
paypal = "razonyang"
# rss = "" # Disable RSS link
16 changes: 13 additions & 3 deletions exampleSite/content/docs/widgets/author/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@ The author widget is located in the sidebar, in order to introduce yourself brie

<!--more-->

## Site Configuration
## Site Parameters

The configuration file is located in `config/_default/author.toml` by default.
You can turn it off by removing the `author` configuration.
{{% alert warning %}}
`config/_default/author.toml` is deprecated, please use `params.author` instead.
{{% /alert %}}

```toml
// params.toml
[author]
name = "Foobar"
[author.params]
[author.social]
```

| Name | Type | Default | Description
|---|:-:|:-:|---
Expand All @@ -41,3 +50,4 @@ You can turn it off by removing the `author` configuration.
| `author.params` | Object | - |
| `author.params.layout` | String | - | Optional values: `compact`.
| `author.social` | Object | - | [Social Links]({{< ref "/docs/widgets/social-links" >}}).

15 changes: 12 additions & 3 deletions exampleSite/content/docs/widgets/author/index.zh-hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@ authors = ["RazonYang"]

<!--more-->

## 站点配置
## 站点参数

默认地,配置文件位于 `config/_default/author.toml`
你可以通过移除 `author` 配置禁用小部件。
{{% alert warning %}}
`config/_default/author.toml` 已被弃用,请使用 `params.author` 代替。
{{% /alert %}}

```toml
// params.toml
[author]
name = "Foobar"
[author.params]
[author.social]
```

| 名称 | 类型 | 默认值 | 描述
|---|:-:|:-:|---
Expand Down
14 changes: 11 additions & 3 deletions exampleSite/content/docs/widgets/author/index.zh-hant.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ authors = ["RazonYang"]

<!--more-->

## 網站配置
## 網站參數

默認地,設定檔位於 `config/_ default/author.toml`
{{% alert warning %}}
`config/_default/author.toml` 已被棄用,請使用 `params.author` 代替。
{{% /alert %}}

你可以通過移除 `author` 配置禁用小部件。
```toml
// params.toml
[author]
name = "Foobar"
[author.params]
[author.social]
```

| 名稱 | 類型 | 預設值 | 描述
|---|:-:|:-:|---
Expand Down
4 changes: 2 additions & 2 deletions exampleSite/content/docs/widgets/social-links/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ There are three places you can put social links to: top app bar, [Author Widget]

### Author Widget

Set up social links by editing a file `config/_default/author.toml` with the following content:
Set up social links by editing a file `config/_default/params.toml` with the following content:

```toml
[social]
[author.social]
email = "user@domain.tld"
github = "githubusername"
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ authors = ["RazonYang"]

### 作者小部件

编辑 `config/_default/author.toml` 文件,并填写以下配置:
编辑 `config/_default/params.toml` 文件,并填写以下配置:

```toml
[social]
[author.social]
email = "user@domain.tld"
github = "githubusername"
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ authors = ["RazonYang"]

### 作者小部件

編輯 `config/_default/author.toml` 文件,並填寫以下配置:
編輯 `config/_default/params.toml` 文件,並填寫以下配置:

```toml
[social]
[author.social]
email = "user@domain.tld"
github = "githubusername"
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
```text
├── _default
│ ├── author.toml
│ ├── config.toml
│ ├── config.zh-hans.toml
│ ├── config.zh-hant.toml
Expand Down
42 changes: 37 additions & 5 deletions layouts/partials/rss.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
{{/* Source: https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/rss.xml */}}
{{- /* Deprecate site.Author.email in favor of site.Params.author.email */}}
{{- $authorEmail := "" }}
{{- with site.Params.author }}
{{- if reflect.IsMap . }}
{{- with .email }}
{{- $authorEmail = . }}
{{- end }}
{{- end }}
{{- else }}
{{- with site.Author.email }}
{{- $authorEmail = . }}
{{- warnf "The author key in site configuration is deprecated. Use params.author.email instead." }}
{{- end }}
{{- end }}

{{- /* Deprecate site.Author.name in favor of site.Params.author.name */}}
{{- $authorName := "" }}
{{- with site.Params.author }}
{{- if reflect.IsMap . }}
{{- with .name }}
{{- $authorName = . }}
{{- end }}
{{- else }}
{{- $authorName = . }}
{{- end }}
{{- else }}
{{- with site.Author.name }}
{{- $authorName = . }}
{{- warnf "The author key in site configuration is deprecated. Use params.author.name instead." }}
{{- end }}
{{- end }}

{{- $pctx := . -}}
{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}}
{{- $pages := slice -}}
Expand All @@ -18,10 +50,10 @@
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
<link>{{ .Permalink }}</link>
<description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }}</description>
<generator>Hugo -- gohugo.io</generator>{{ with .Site.LanguageCode }}
<language>{{.}}</language>{{end}}{{ with .Site.Author.email }}
<managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }}
<webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}
<generator>Hugo</generator>
<language>{{ site.Language.LanguageCode }}</language>{{ with $authorEmail }}
<managingEditor>{{.}}{{ with $authorName }} ({{ . }}){{ end }}</managingEditor>{{ end }}{{ with $authorEmail }}
<webMaster>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</webMaster>{{ end }}
<copyright>{{- partial "helpers/copyright" . }}</copyright>{{ if not .Date.IsZero }}
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
{{- with .OutputFormats.Get "RSS" -}}
Expand All @@ -32,7 +64,7 @@
<title>{{ .Title }}</title>
<link>{{ .Permalink }}</link>
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
{{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
{{- with $authorEmail }}<author>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</author>{{ end }}
<guid>{{ .Permalink }}</guid>
<description>{{- printf "<![CDATA[%s]]>" .Summary | safeHTML }}</description>
{{- if default false $.Site.Params.feeds.content }}
Expand Down
9 changes: 7 additions & 2 deletions layouts/partials/sidebar/profile.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{{- if .Site.Author }}
{{- $layout := default "" .Site.Author.params.layout }}
{{- $author := site.Params.author }}
{{- with site.Author }}
{{- $author = . }}
{{- warnf "The author key in site configuration is deprecated. Use params.author instead." }}
{{- end }}
{{- if $author }}
{{- $layout := default "" $author.params.layout }}
{{- if eq $layout "compact" }}
{{- partial "sidebar/profile/compact" . }}
{{- else }}
Expand Down
7 changes: 6 additions & 1 deletion layouts/partials/sidebar/profile/avatar.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{{- with .Site.Author -}}
{{- $author := site.Params.author }}
{{- with site.Author }}
{{- $author = . }}
{{- warnf "The author key in site configuration is deprecated. Use params.author instead." }}
{{- end }}
{{- with $author -}}
{{- $attributes := printf "data-viewer-invisible" | safeHTMLAttr -}}
{{- partial "helpers/image" (dict "filename" (default "images/profile.webp" .avatar) "class" "profile-avatar rounded-circle" "alt" .name "resources" $.Resources "attributes" $attributes) -}}
{{- end -}}
7 changes: 6 additions & 1 deletion layouts/partials/sidebar/profile/meta.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{{- with .Site.Author -}}
{{- $author := site.Params.author }}
{{- with site.Author }}
{{- $author = . }}
{{- warnf "The author key in site configuration is deprecated. Use params.author instead." }}
{{- end }}
{{- with $author -}}
<div class="profile-name fw-fold fs-lg">{{ .name }}</div>
{{- with .bio -}}
<div class="profile-bio">{{ . }}</div>
Expand Down
7 changes: 6 additions & 1 deletion layouts/partials/sidebar/profile/social-links.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{{- with .Site.Author.social -}}
{{- $author := site.Params.author }}
{{- with site.Author }}
{{- $author = . }}
{{- warnf "The author key in site configuration is deprecated. Use params.author instead." }}
{{- end }}
{{- with $author.social -}}
{{- partial "helpers/social-links" (dict "class" "mt-1 justify-content-around" "links" . "size" "fa-2x" "OutputFormats" $.OutputFormats "home" ($.GetPage "/") "params" $.Site.Params) -}}
{{- end -}}

0 comments on commit 82a54e6

Please sign in to comment.