diff options
author | FFRaycoder <nn_201312@163.com> | 2020-05-24 09:42:47 +0300 |
---|---|---|
committer | FFRaycoder <nn_201312@163.com> | 2020-05-24 09:42:47 +0300 |
commit | 88be03e974b9197b558610c9735a110806c15647 (patch) | |
tree | 2c67f5894c7df6f10c287ef525238d9f985ac689 | |
parent | 817259edb690fddf8d6c6911278cc135ac5f36f4 (diff) |
custom copyright
-rw-r--r-- | exampleSite/config.toml | 9 | ||||
-rw-r--r-- | exampleSite/config.zh.toml | 9 | ||||
-rw-r--r-- | layouts/partials/footer.html | 19 | ||||
-rw-r--r-- | layouts/partials/utils/markdownify.html | 46 |
4 files changed, 74 insertions, 9 deletions
diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 1a9c668..35d12fc 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -151,6 +151,15 @@ paginate = 10 mainSections = [] ##################################### + # Copyright Protection + + # Whether to open + enableCopyright = true + + copyrightName = "CC BY-NC 4.0" + copyrightLink = "https://creativecommons.org/licenses/by-nc/4.0/" + + ##################################### # table of Contents # Whether to open (global settings) diff --git a/exampleSite/config.zh.toml b/exampleSite/config.zh.toml index 67ff7d2..705d017 100644 --- a/exampleSite/config.zh.toml +++ b/exampleSite/config.zh.toml @@ -151,6 +151,15 @@ paginate = 10 mainSections = [] ###################################### + # 版权保护 + + # 是否开启 + enableCopyright = true + + copyrightName = "CC BY-NC 4.0" + copyrightLink = "https://creativecommons.org/licenses/by-nc/4.0/" + + ###################################### # 目录 # 是否开启(全局设置) diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 29149a1..ef8b99a 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -5,17 +5,18 @@ </div>
</a>
<div class="footer reveal">
+ {{ if .Site.Params.enableCopyright }}
+ <p>
+ Copyright <i class="ri-copyright-line"></i> · {{ now.Format "2006" }} · {{ .Site.Author.name }} ·
+ <a href="{{ .Site.Params.copyrightLink }}" target="_blank" style="text-decoration: none;color: inherit;font-size: 14px;font-weight: 500;">
+ {{ .Site.Params.copyrightName }}
+ </a>
+ </p>
+ {{ end }}
<p>
- Copyright <i class="ri-copyright-line"></i> · {{ now.Format "2006" }} · {{ .Site.Author.name }} ·
- <a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank"
- style="text-decoration: none;color: inherit;font-size: 14px;font-weight: 500;">
- CC BY-NC 4.0
- </a>
- </p>
- <p>
- {{ if .Site.Params.displayPoweredBy }}
+ {{ if .Site.Params.displayPoweredBy }}
Powered by <a href="https://github.com/gohugoio/hugo">Hugo</a> | Theme is <a href="https://github.com/ThemeTony/hugo-theme-tony">Tony</a>
- {{ end }}
+ {{ end }}
</p>
</div>
</div>
diff --git a/layouts/partials/utils/markdownify.html b/layouts/partials/utils/markdownify.html new file mode 100644 index 0000000..7c660e8 --- /dev/null +++ b/layouts/partials/utils/markdownify.html @@ -0,0 +1,46 @@ +{{- $Deliver := .Deliver -}} +{{- $raw := .raw -}} +{{- $isContent := .isContent -}} + +{{- $Deliver.Scratch.Set "Content" $raw -}} + +{{- $enableEmoji := replaceRE `enableEmoji = (.+)` `$1` (delimit (readFile "config.toml" | findRE `enableEmoji = (.+)` | uniq) " ") -}} + +<!-- New Markdown Syntax: Emphasis Point `..text..` --> +{{- $Content := $Deliver.Scratch.Get "Content" -}} +{{- if $Deliver.Site.Params.enableEmphasisPoint -}} + {{- $regexPatternEmphasisPoint := `([^\.\x60])\.\.([^\.\s\n\/\\]+)\.\.([^\.\x60])` -}} + {{- $regexReplacementEmphasisPoint := `$1<em class="emphasis-point">$2</em>$3` -}} + {{- $Content := $Content | replaceRE $regexPatternEmphasisPoint $regexReplacementEmphasisPoint | safeHTML -}} + {{- $Deliver.Scratch.Set "Content" $Content -}} +{{- end -}} + +<!-- Markdownify --> +{{- $Content := $Deliver.Scratch.Get "Content" -}} +{{- if not $isContent -}} + {{- $Content := $Content | markdownify -}} + {{- $Deliver.Scratch.Set "Content" $Content -}} + + <!-- Emojify --> + {{- $Content := $Deliver.Scratch.Get "Content" -}} + {{- if eq $enableEmoji "true" -}} + {{- $Content := $Content | emojify -}} + {{- $Deliver.Scratch.Set "Content" $Content -}} + {{- end -}} +{{- end -}} + +<!-- External Links --> +{{- $Content := $Deliver.Scratch.Get "Content" -}} +{{- if $Deliver.Site.Params.hrefTargetBlank -}} + {{- $temps := findRE `(<a href="[^"]+")` $Content | uniq -}} + {{- with $temps -}} + {{- range . -}} + {{- if eq (substr . 9 4) "http" -}} + {{- $raw := replaceRE `(<a href="[^"]+")` `$1` . -}} + {{- $replacement := printf `%s target="_blank" rel="noopener"` $raw -}} + {{- $Content := replace ($Deliver.Scratch.Get "Content") . $replacement | safeHTML -}} + {{- $Deliver.Scratch.Set "Content" $Content -}} + {{- end -}} + {{- end -}} + {{- end -}} +{{- end -}} |