Skip to content

Commit

Permalink
✨ Feat: add param.capitalizeTitles, default is true
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Oct 1, 2024
1 parent 53f221b commit 9c440df
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 33 deletions.
4 changes: 3 additions & 1 deletion hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ enableEmoji = true
enablePWA = false
# FixIt 0.2.14 | NEW whether to add external Icon for external links automatically
externalIcon = false
# FixIt 0.3.13 | NEW whether to capitalize titles
capitalizeTitles = true
# FixIt 0.3.0 | NEW whether to add site title to the title of every page
# remember to set up your site title in `hugo.toml` (e.g. title = "title")
withSiteTitle = true
Expand Down Expand Up @@ -441,7 +443,7 @@ enableEmoji = true
showHome = false
# FixIt 0.3.13 | NEW
separator = "/"
capitalize = false
capitalize = true

# FixIt 0.3.10 | NEW Post navigation config
[params.navigation]
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/home.archives.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h2 class="group-title">
{{- dict "Class" "fa-solid fa-share fa-fw text-success me-1" | partial "plugin/icon.html" -}}
{{- end -}}
{{- /* Use the original title after archiving the articles */ -}}
{{- title .Title -}}
{{- cond (.Param "capitalizeTitles") (title .Title) (.Title) -}}
</a>
<span class="archive-item-date" title='{{ "2006-01-02 15:04:05" | .Date.Format }}'>
{{- .Date | dateFormat ($.Site.Params.archives.dateFormat | default "01-02") -}}
Expand Down
4 changes: 2 additions & 2 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- define "title" -}}
{{- title .Title -}}
{{- cond (.Param "capitalizeTitles") (title .Title) .Title -}}
{{- if .Site.Params.withSiteTitle }} {{ .Site.Params.titleDelimiter }} {{ .Site.Title }}{{- end -}}
{{- end -}}

Expand All @@ -8,7 +8,7 @@
<article class="page single special">
<div class="header">
{{- /* Title */ -}}
<h1 class="single-title animate__animated animate__pulse animate__faster">{{- title .Title -}}</h1>
<h1 class="single-title animate__animated animate__pulse animate__faster">{{- cond (.Param "capitalizeTitles") (title .Title) .Title -}}</h1>

{{- /* Subtitle */ -}}
{{- with $params.subtitle -}}<p class="single-subtitle animate__animated animate__fadeIn">{{ . }}</p>{{- end -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/single.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- $params := partial "function/params.html" -}}
{{- $author := .Store.Get "author" -}}
# {{ title .Title }}
# {{ cond (.Param "capitalizeTitles") (title .Title) .Title }}

{{ if $params.password -}}
_**{{ T "single.encryptedAbstract" }}**_
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h2 class="single-title" itemprop="name headline">
<span title="{{ $title }}" class="icon-repost">{{- $icon | partial "plugin/icon.html" -}}</span>
{{- end -}}
{{- end -}}
<a href="{{ .RelPermalink }}">{{ title .Title }}</a>
<a href="{{ .RelPermalink }}">{{ cond (.Param "capitalizeTitles") (title .Title) .Title }}</a>
</h2>

{{- /* Meta */ -}}
Expand Down
4 changes: 2 additions & 2 deletions layouts/page/friends.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- define "title" -}}
{{- title .Title -}}
{{- cond (.Param "capitalizeTitles") (title .Title) .Title -}}
{{- if .Site.Params.withSiteTitle }} {{ .Site.Params.titleDelimiter }} {{ .Site.Title }}{{- end -}}
{{- end -}}

Expand All @@ -8,7 +8,7 @@
<article class="page single special friends">
<div class="header">
{{- /* Title */ -}}
<h1 class="single-title animate__animated animate__pulse animate__faster">{{- title .Title -}}</h1>
<h1 class="single-title animate__animated animate__pulse animate__faster">{{- cond (.Param "capitalizeTitles") (title .Title) .Title -}}</h1>
{{- /* Subtitle */ -}}
{{- with $params.subtitle -}}<p class="single-subtitle animate__animated animate__fadeIn">{{ . }}</p>{{- end -}}
</div>
Expand Down
7 changes: 4 additions & 3 deletions layouts/partials/breadcrumb.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
{{- end -}}

{{- $title := "" -}}
{{- $capitalizeTitles := .Param "capitalizeTitles" -}}
{{- with .Description -}}
{{- $title = . -}}
{{- else -}}
{{- $title = title .LinkTitle -}}
{{- $title = cond $capitalizeTitles (title .LinkTitle) .LinkTitle -}}
{{- if .IsPage | and .Summary -}}
{{- $title = .Summary -}}
{{- end -}}
Expand All @@ -22,14 +23,14 @@
{{- $innerText = T "single.home" -}}
{{- else -}}
{{- $innerText = (T (add .TranslationKey ".breadcrumbTitle")) | default (lower .LinkTitle | T) | default .LinkTitle -}}
{{- $innerText = cond (.Param "breadcrumb.capitalize") (title $innerText) $innerText -}}
{{- $innerText = cond ((.Param "breadcrumb.capitalize") | and $capitalizeTitles) (title $innerText) $innerText -}}
{{- end -}}

<li class="breadcrumb-item" data-separator="{{ $separator }}"><a href="{{ .RelPermalink }}" title="{{ $title }}">{{ $innerText }}</a></li>
{{- end -}}

{{- $currentText := (T (add .TranslationKey ".breadcrumbTitle")) | default (lower .LinkTitle | T) | default .LinkTitle -}}
{{- $currentText = cond (.Param "breadcrumb.capitalize") (title $currentText) $currentText -}}
{{- $currentText = cond ((.Param "breadcrumb.capitalize") | and (.Param "capitalizeTitles")) (title $currentText) $currentText -}}
<li class="breadcrumb-item active" data-separator="{{ $separator }}" aria-current="page">{{ $currentText }}</li>
</ol>
</nav>
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/init/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- .Scratch.Set "version" "v0.3.13-729c2c39" -}}
{{- .Scratch.Set "version" "v0.3.13-53f221b7" -}}
{{- .Scratch.Set "this" dict -}}

{{- partial "init/detection-env.html" . -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/plugin/share.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- $share := (partial "function/params.html").share | default dict -}}

{{- if $share.enable -}}
{{- $title := title .Title -}}
{{- $title := cond (.Param "capitalizeTitles") (title .Title) .Title -}}
{{- /* 001: Twitter */ -}}
{{- if $share.Twitter -}}
<a href="javascript:void(0);" title="{{ T `shareOn` }} X" data-sharer="twitter" data-url="{{ .Permalink }}" data-title="{{ $title }}"{{ with .Site.Params.Social.Twitter }} data-via="{{ . }}"{{ end }}{{ with .Params.tags }} data-hashtags="{{ delimit . `,` }}"{{ end }}>
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/recently-updated.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h2 class="group-title">
{{- if eq $repost.enable true -}}
{{- dict "Class" "fa-solid fa-share fa-fw text-success me-1" | partial "plugin/icon.html" -}}
{{- end -}}
{{- title .LinkTitle -}}
{{- cond (.Param "capitalizeTitles") (title .LinkTitle) .LinkTitle -}}
</a>
<span class="archive-item-date" title='{{ "2006-01-02 15:04:05" | .Lastmod.Format }}'>
{{- with .Lastmod | dateFormat (.Site.Params.section.dateformat | default "01-02") -}}
Expand Down
10 changes: 6 additions & 4 deletions layouts/partials/single/collection-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<nav>
<ul class="collection-list">
{{- range $key, $page := $pages -}}
{{- /* whether to capitalize the title, consistent with breadcrumb */ -}}
{{- $title := cond ($page.Param "breadcrumb.capitalize") (title $page.LinkTitle) $page.LinkTitle -}}
{{- $capitalizeTitles := $page.Param "capitalizeTitles" -}}
{{- $title := cond $capitalizeTitles (title $page.LinkTitle) $page.LinkTitle -}}
{{- if $page.LinkTitle | eq $.LinkTitle -}}
{{- $currentKey = $key -}}
<li class="collection-item"><span class="active" title="{{ $title }}">{{ $title }}</span></li>
Expand All @@ -31,15 +31,17 @@
</ul>
<div class="collection-nav-simple">
{{- with $pages.Next $ -}}
<a href="{{ .RelPermalink }}" class="collection-nav-item" rel="prev" title="{{ title .LinkTitle }}">
{{- $capitalizeTitles := .Param "capitalizeTitles" -}}
<a href="{{ .RelPermalink }}" class="collection-nav-item" rel="prev" title="{{ cond $capitalizeTitles (title .LinkTitle) .LinkTitle }}">
{{- dict "Class" "fa-solid fa-angle-left fa-fw" | partial "plugin/icon.html" -}}
</a>
{{- else -}}
{{- dict "Class" "fa-solid fa-angle-left fa-fw collection-nav-item text-secondary" | partial "plugin/icon.html" -}}
{{- end -}}
<span class="text-secondary">{{ add $currentKey 1 }}/{{ $pages.Len }}</span>
{{- with $pages.Prev $ -}}
<a href="{{ .RelPermalink }}" class="collection-nav-item" rel="next" title="{{ title .LinkTitle }}">
{{- $capitalizeTitles := .Param "capitalizeTitles" -}}
<a href="{{ .RelPermalink }}" class="collection-nav-item" rel="next" title="{{ cond $capitalizeTitles (title .LinkTitle) .LinkTitle }}">
{{- dict "Class" "fa-solid fa-angle-right fa-fw" | partial "plugin/icon.html" -}}
</a>
{{- else -}}
Expand Down
10 changes: 6 additions & 4 deletions layouts/partials/single/collection-nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
{{/* TODO JS 实现 reverse 翻转顺序 */}}
{{- $pages := (where .Pages "Params.Weight" "!=" nil) | append (where .Pages "Params.Weight" "eq" nil).ByDate -}}
{{- with $pages.Next $ -}}
<a href="{{ .RelPermalink }}" class="collection-nav-item" rel="prev" title="{{ title .LinkTitle }}">
{{- $capitalizeTitles := .Param "capitalizeTitles" -}}
<a href="{{ .RelPermalink }}" class="collection-nav-item" rel="prev" title="{{ cond $capitalizeTitles (title .LinkTitle) .LinkTitle }}">
{{- dict "Class" "fa-solid fa-angle-left fa-fw" | partial "plugin/icon.html" -}}
<span>{{- title .LinkTitle -}}</span>
<span>{{- cond $capitalizeTitles (title .LinkTitle) .LinkTitle -}}</span>
</a>
{{- end -}}
{{- with $pages.Prev $ -}}
<a href="{{ .RelPermalink }}" class="collection-nav-item" rel="next" title="{{ title .LinkTitle }}">
<span>{{- title .LinkTitle -}}</span>
{{- $capitalizeTitles := .Param "capitalizeTitles" -}}
<a href="{{ .RelPermalink }}" class="collection-nav-item" rel="next" title="{{ cond $capitalizeTitles (title .LinkTitle) .LinkTitle }}">
<span>{{- cond $capitalizeTitles (title .LinkTitle) .LinkTitle -}}</span>
{{- dict "Class" "fa-solid fa-angle-right fa-fw" | partial "plugin/icon.html" -}}
</a>
{{- end -}}
Expand Down
10 changes: 6 additions & 4 deletions layouts/partials/single/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,16 @@
{{- $next = $pages.Prev . -}}
{{- end -}}
{{- with $prev -}}
<a href="{{ .RelPermalink }}" class="post-nav-item" rel="prev" title="{{ title .LinkTitle }}">
{{- $capitalizeTitles := .Param "capitalizeTitles" -}}
<a href="{{ .RelPermalink }}" class="post-nav-item" rel="prev" title="{{ cond $capitalizeTitles (title .LinkTitle) .LinkTitle }}">
{{- dict "Class" "fa-solid fa-angle-left fa-fw" | partial "plugin/icon.html" -}}
{{- title .LinkTitle -}}
{{- cond $capitalizeTitles (title .LinkTitle) .LinkTitle -}}
</a>
{{- end -}}
{{ with $next }}
<a href="{{ .RelPermalink }}" class="post-nav-item" rel="next" title="{{ title .LinkTitle }}">
{{- title .LinkTitle -}}
{{- $capitalizeTitles := .Param "capitalizeTitles" -}}
<a href="{{ .RelPermalink }}" class="post-nav-item" rel="next" title="{{ cond $capitalizeTitles (title .LinkTitle) .LinkTitle }}">
{{- cond $capitalizeTitles (title .LinkTitle) .LinkTitle -}}
{{- dict "Class" "fa-solid fa-angle-right fa-fw" | partial "plugin/icon.html" -}}
</a>
{{- end -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/single/related.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<h2 id="see-also">{{ T "single.relatedContent" }}</h2>
<ul>
{{- range $i, $p := . -}}
{{- $title := title .LinkTitle -}}
{{- $title := cond (.Param "capitalizeTitles") (title .LinkTitle) .LinkTitle -}}
<li>
<a href="{{ .RelPermalink }}" title="{{ $title }}">{{ $title }}</a>
{{- with .HeadingsFiltered -}}
Expand Down
4 changes: 2 additions & 2 deletions layouts/posts/single.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{{- define "title" -}}
{{- title .Title -}}
{{- cond (.Param "capitalizeTitles") (title .Title) .Title -}}
{{- if .Site.Params.withSiteTitle }} {{ .Site.Params.titleDelimiter }} {{ .Site.Title }}{{- end -}}
{{- end -}}

{{- define "content" -}}
{{- $title := title .Title -}}
{{- $title := cond (.Param "capitalizeTitles") (title .Title) .Title -}}
{{- $params := partial "function/params.html" -}}
{{- $toc := .Scratch.Get "toc" -}}
{{- $tableOfContents := .Fragments.ToHTML ($toc.startLevel | int) ($toc.endLevel | int) ($toc.ordered | default false) -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/section/section.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2 class="group-title">
{{- if eq $repost.enable true -}}
{{- dict "Class" "fa-solid fa-share fa-fw text-success me-1" | partial "plugin/icon.html" -}}
{{- end -}}
{{- title .LinkTitle -}}
{{- cond (.Param "capitalizeTitles") (title .LinkTitle) .LinkTitle -}}
</a>
<span class="archive-item-date" title='{{ "2006-01-02 15:04:05" | .Date.Format }}'>
{{- .Date | dateFormat ($.Site.Params.section.dateFormat | default "01-02") -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/taxonomy/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h2 class="group-title">
{{- if eq $repost.enable true -}}
{{- dict "Class" "fa-solid fa-share fa-fw text-success me-1" | partial "plugin/icon.html" -}}
{{- end -}}
{{- title .LinkTitle -}}
{{- cond (.Param "capitalizeTitles") (title .LinkTitle) .LinkTitle -}}
</a>
<span class="archive-item-date" title='{{ "2006-01-02 15:04:05" | .Date.Format }}'>
{{- .Date | dateFormat ($.Site.Params.list.dateFormat | default "01-02") -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/taxonomy/terms/categories.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h2 class="card-item-title">
{{- if eq $repost.enable true -}}
{{- dict "Class" "fa-solid fa-share fa-fw text-success me-1" | partial "plugin/icon.html" -}}
{{- end -}}
{{- title .LinkTitle -}}
{{- cond (.Param "capitalizeTitles") (title .LinkTitle) .LinkTitle -}}
</a>
</article>
{{- end -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/taxonomy/terms/collections.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h2 class="card-item-title">
{{- if eq $repost.enable true -}}
{{- dict "Class" "fa-solid fa-share fa-fw text-success me-1" | partial "plugin/icon.html" -}}
{{- end -}}
{{- title .LinkTitle -}}
{{- cond (.Param "capitalizeTitles") (title .LinkTitle) .LinkTitle -}}
</a>
</article>
{{- end -}}
Expand Down

0 comments on commit 9c440df

Please sign in to comment.