文章末尾添加版权声明
简述
当您浏览到文章末尾时,会看到一段版权声明。这样的版权声明可以清楚地告知读者本文的版权归属和转载/使用条件。
- 如果文章为原创内容:
本文为原创内容,版权归作者所有。如需转载,请在文章中声明本文标题及链接。
文章标题: 文章标题——作者名称
文章链接:xxxxxxxxxxx(文章Url)
许可协议:xxx协议
- 如果文章为转载内容:
本文为转载内容,原文信息如下:
原文标题:xxxxxx
原文作者:xxxxxxxx
原文链接:xxxxxxxxxxx(文章Url) 如有侵权,请联系站长删除
具体添加步骤
1.添加 copyright.html
在 layouts/partials
添加 copyright.html
文件,代码如下。
copyright.html
{{ $lang := .Site.Language.Lang }}
<div class="pe-copyright">
<hr>
<blockquote>
{{ if .Param "reposted" }}
{{ if eq $lang "zh" }}
<p>本文为转载内容,原文信息如下:</p>
<p>原文标题:{{- .Param "repostedTitle" -}}</p>
<p>原文作者:{{- .Param "repostedAuthor" -}}</p>
<p>原文链接:<a href="{{- .Param " repostedLink" -}}" target="_blank">{{- .Param "repostedLink" -}}</a></p>
<p>如有侵权,请联系站长删除。</p>
{{ else }}
<p>This article is a repost, the original information is as follows:</p>
<p>Original title: {{- .Param "repostedTitle" -}}</p>
<p>Original author: {{- .Param "repostedAuthor" -}}</p>
<p>Original link: <a href="{{- .Param " repostedLink" -}}" target="_blank">{{- .Param "repostedLink" -}}</a></p>
<p>If there is any infringement, please contact the blogger</a>
to delete it.</p>
{{ end }}
{{ else }}
{{ if eq $lang "zh" }}
<p>本文为原创内容,版权归作者所有。如需转载,请在文章中声明本文标题及链接。</p>
<p>文章标题:{{ .Title }} —— {{ .Param "author" }}</p>
<p>文章链接:<a href="{{ .Permalink }}" target="_blank">{{ .Permalink }}</a></p>
<p>许可协议:<a href="{{- .Param " licenseLink" -}}" target="_blank">{{- .Param "licenseName" -}}</a></p>
{{ else }}
<p>This article is original content, the copyright belongs to the author. If you need to repost, please declare
the title and link of the article.</p>
<p>Article title: {{ .Title }} —— {{ .Param "author" }}</p>
<p>Article link: <a href="{{ .Permalink }}" target="_blank">{{ .Permalink }}</a></p>
<p>License: <a href="{{- .Param " licenseLink" -}}" target="_blank">{{- .Param "licenseName" -}}</a></p>
{{ end }}
{{ end }}
</blockquote>
</div>
2.添加 copyright.css
在 assets/css/extended
添加 copyright.css
文件,代码如下。
copyright.css
.pe-copyright {
margin-top: 20px;
font-size: 14px;
}
.pe-copyright hr {
border-style: dashed;
color: #1e1e33;
}
.pe-copyright blockquote {
margin: 10px 0;
padding: 0 10px;
border-inline-start: 3px solid #1e1e33;
}
.pe-copyright a {
box-shadow: 0 1px;
box-decoration-break: clone;
-webkit-box-decoration-break: clone;
}
3.调整 single.html
调整 themes/PaperMod/layouts/_default
下的 single.html
文件。
只需要在对应的位置插入这段代码即可。
<!-- 【Begin】版权声明(每篇文章下面的) -->
{{ if .Param "enableCopyright" }}
{{ partial "copyright.html" . }}
{{ end }}
<!-- 【End】版权声明(每篇文章下面的) -->
下面是我完整的 single.html
文件,供参考。
single.html
{{- define "main" }}
<article class="post-single">
<header class="post-header">
{{ partial "breadcrumbs.html" . }}
<h1 class="post-title entry-hint-parent">
{{ .Title }}
{{- if .Draft }}
<span class="entry-hint" title="Draft">
<svg xmlns="http://www.w3.org/2000/svg" height="35" viewBox="0 -960 960 960" fill="currentColor">
<path
d="M160-410v-60h300v60H160Zm0-165v-60h470v60H160Zm0-165v-60h470v60H160Zm360 580v-123l221-220q9-9 20-13t22-4q12 0 23 4.5t20 13.5l37 37q9 9 13 20t4 22q0 11-4.5 22.5T862.09-380L643-160H520Zm300-263-37-37 37 37ZM580-220h38l121-122-18-19-19-18-122 121v38Zm141-141-19-18 37 37-18-19Z" />
</svg>
</span>
{{- end }}
</h1>
{{- if .Description }}
<div class="post-description">
{{ .Description }}
</div>
{{- end }}
{{- if not (.Param "hideMeta") }}
<div class="post-meta">
{{- partial "post_meta.html" . -}}
{{- partial "translation_list.html" . -}}
{{- partial "edit_post.html" . -}}
{{- partial "post_canonical.html" . -}}
</div>
{{- end }}
</header>
{{- $isHidden := (.Param "cover.hiddenInSingle") | default (.Param "cover.hidden") | default false }}
{{- partial "cover.html" (dict "cxt" . "IsSingle" true "isHidden" $isHidden) }}
{{- if (.Param "ShowToc") }}
{{- partial "toc.html" . }}
{{- end }}
{{- if .Content }}
<div class="post-content">
{{- if not (.Param "disableAnchoredHeadings") }}
{{- partial "anchored_headings.html" .Content -}}
{{- else }}{{ .Content }}{{ end }}
</div>
{{- end }}
<!-- 【Begin】版权声明(每篇文章下面的) -->
{{ if .Param "enableCopyright" }}
{{ partial "copyright.html" . }}
{{ end }}
<!-- 【End】版权声明(每篇文章下面的) -->
<footer class="post-footer">
{{- $tags := .Language.Params.Taxonomies.tag | default "tags" }}
<ul class="post-tags">
{{- range ($.GetTerms $tags) }}
<li><a href="{{ .Permalink }}">{{ .LinkTitle }}</a></li>
{{- end }}
</ul>
{{- if (.Param "ShowPostNavLinks") }}
{{- partial "post_nav_links.html" . }}
{{- end }}
{{- if (and site.Params.ShowShareButtons (ne .Params.disableShare true)) }}
{{- partial "share_icons.html" . -}}
{{- end }}
</footer>
{{- if (.Param "comments") }}
{{- partial "comments.html" . }}
{{- end }}
</article>
{{- end }}{{/* end main */}}
4.调整 hugo.yaml
在 params
下添加: enableCopyright: true
,licenseLink
,licenseName
。
在此处添加的作用的以后新写的文章,都默认在文章底部添加版权说明。
params:
enableCopyright: true
licenseLink: "https://creativecommons.org/licenses/by-nc/4.0/"
licenseName: "CC BY-NC 4.0"
5.使用
- 隐藏版权声明
如果你不想在某篇文章启用版权声明,只需在文章的 Front Matter
添加enableCopyright: false
参数即可。
- 原创文章
如果是原创文章的话,不需要在额外地调整文章的 Front Matter
。
当然,如果你本篇文章不采用 CC 4.0 协议的话,可以在当前文章的 Front Matter
添加 licenseLink
和 licenseName
,这样就会覆盖掉 hugo.yaml
配置的 licenseLink
和 licenseName
了。
---
licenseName: "GNU LGPL-3.0" # 使用 GNU LGPL-3.0 协议
licenseLink: "https://opensource.org/license/lgpl-3-0"
---
- 转载文章
如果是转载文章的话,需要在文章的 Front Matter
添加参数:
参数 | 说明 |
---|---|
reposted | true |
repostedTitle | 原文章的标题 |
repostedAuthor | 原文章的作者 |
repostedLink | 原文章的Url |
---
reposted: true
repostedTitle: "xxx"
repostedAuthor: "xxxxx"
repostedLink: "xxxxxxxxxxx"
---
站点底端添加版权声明
1.新添 copyright 文件
1.在 content
文件夹下新添 copyright.zh.md
文件和 copyright.en.md
文件。
copyright.zh.md
---
title: "版权声明"
draft: false
ShowReadingTime: false
showToc: false
TocOpen: false
comments: false
enableCopyright: false
---
本站所有内容采用[CC BY-NC-ND 4.0](https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode.zh-hans)知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可。
这是一份精简版的许可协议,完整版 [请见这里](https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode.zh-hans) 。
### 遵守下列条件
- **署名** — 您必须给出适当的署名(作者及原内容链接),提供指向本许可协议的链接,同时标明是否(对原始作品)作了修改。您可以用任何合理的方式来署名,但是不得以任何方式暗示许可人为您或您的使用背书。
- **非商业性使用** — 您不得将本作品用于商业目的(必须联系作者询问)。
- **禁止演绎** — 如果您再混合、转换、或者基于该作品创作,您不可以分发修改作品。
- **没有附加限制** — 您不得使用法律术语或法律措施来限制其他人做许可协议允许的事情。
### 您可以自由地
- **共享** — 在任何媒介以任何形式复制、发行本作品。
### 声明
- 您不必因为公共领域的作品要素而遵守许可协议,或者您的使用被可适用的例外或限制所允许。
- 不提供担保。许可协议可能不会给与您意图使用的所必须的所有许可。例如,其他权利比如形象权、隐私权或人格权可能限制您如何使用作品。
copyright.en.md
---
title: "Copyright"
draft: false
ShowReadingTime: false
showToc: false
TocOpen: false
comments: false
enableCopyright: false
---
All content on this site is licensed under the [CC BY-NC-ND 4.0](https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode.en) Creative Commons Attribution - Non-Commercial - No Deduction 4.0 International License.
2.调整 footer 文件
先将 themes/PaperMod/layouts/partials
下的 footer.html
文件拷贝一份到 ./layouts/partials
文件夹下。
然后编辑 footer.html
,在对应的位置插入代码:
<!-- Begin. 底部版权声明 -->
<span>
<a href="{{ .Site.LanguagePrefix }}/copyright">{{ i18n "copyright_statement" }}</a>{{- print " · "}}
</span>
<!-- End. 底部版权声明 -->
下面是我完整的 footer.html
文件,供参考。
footer.html
{{- if not (.Param "hideFooter") }}
<footer class="footer">
{{- if not site.Params.footer.hideCopyright }}
{{- if site.Copyright }}
<span>{{ site.Copyright | markdownify }}</span>
{{- else }}
<span>© {{ now.Year }} <a href="{{ "" | absLangURL }}">{{ site.Title }}</a></span>
{{- end }}
{{- print " · "}}
{{- end }}
{{- with site.Params.footer.text }}
{{ . | markdownify }}
{{- print " · "}}
{{- end }}
<!-- Begin. 底部版权声明 -->
<span>
<a href="{{ .Site.LanguagePrefix }}/copyright">{{ i18n "copyright_statement" }}</a>{{- print " · "}}
</span>
<!-- End. 底部版权声明 -->
<span>
Powered by
<a href="https://gohugo.io/" rel="noopener noreferrer" target="_blank">Hugo</a> &
<a href="https://github.com/adityatelange/hugo-PaperMod/" rel="noopener" target="_blank">PaperMod</a>
</span>
</footer>
{{- end }}
{{- if (not site.Params.disableScrollToTop) }}
<a href="#top" aria-label="go to top" title="Go to Top (Alt + G)" class="top-link" id="top-link" accesskey="g">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 6" fill="currentColor">
<path d="M12 6H0l6-6z" />
</svg>
</a>
{{- end }}
{{- partial "extend_footer.html" . }}
<script>
let menu = document.getElementById('menu')
if (menu) {
menu.scrollLeft = localStorage.getItem("menu-scroll-position");
menu.onscroll = function () {
localStorage.setItem("menu-scroll-position", menu.scrollLeft);
}
}
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener("click", function (e) {
e.preventDefault();
var id = this.getAttribute("href").substr(1);
if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView({
behavior: "smooth"
});
} else {
document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView();
}
if (id === "top") {
history.replaceState(null, null, " ");
} else {
history.pushState(null, null, `#${id}`);
}
});
});
</script>
{{- if (not site.Params.disableScrollToTop) }}
<script>
var mybutton = document.getElementById("top-link");
window.onscroll = function () {
if (document.body.scrollTop > 800 || document.documentElement.scrollTop > 800) {
mybutton.style.visibility = "visible";
mybutton.style.opacity = "1";
} else {
mybutton.style.visibility = "hidden";
mybutton.style.opacity = "0";
}
};
</script>
{{- end }}
{{- if (not site.Params.disableThemeToggle) }}
<script>
document.getElementById("theme-toggle").addEventListener("click", () => {
if (document.body.className.includes("dark")) {
document.body.classList.remove('dark');
localStorage.setItem("pref-theme", 'light');
} else {
document.body.classList.add('dark');
localStorage.setItem("pref-theme", 'dark');
}
})
</script>
{{- end }}
{{- if (and (eq .Kind "page") (ne .Layout "archives") (ne .Layout "search") (.Param "ShowCodeCopyButtons")) }}
<script>
document.querySelectorAll('pre > code').forEach((codeblock) => {
const container = codeblock.parentNode.parentNode;
const copybutton = document.createElement('button');
copybutton.classList.add('copy-code');
copybutton.innerHTML = '{{- i18n "code_copy" | default "copy" }}';
function copyingDone() {
copybutton.innerHTML = '{{- i18n "code_copied" | default "copied!" }}';
setTimeout(() => {
copybutton.innerHTML = '{{- i18n "code_copy" | default "copy" }}';
}, 2000);
}
copybutton.addEventListener('click', (cb) => {
if ('clipboard' in navigator) {
navigator.clipboard.writeText(codeblock.textContent);
copyingDone();
return;
}
const range = document.createRange();
range.selectNodeContents(codeblock);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
try {
document.execCommand('copy');
copyingDone();
} catch (e) { };
selection.removeRange(range);
});
if (container.classList.contains("highlight")) {
container.appendChild(copybutton);
} else if (container.parentNode.firstChild == container) {
// td containing LineNos
} else if (codeblock.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "TABLE") {
// table containing LineNos and code
codeblock.parentNode.parentNode.parentNode.parentNode.parentNode.appendChild(copybutton);
} else {
// code blocks not having highlight as parent class
codeblock.parentNode.appendChild(copybutton);
}
});
</script>
{{- end }}
3.翻译
先将 themes/PaperMod/i18n
文件下的 zh.yaml
文件和 en.yaml
翻译文件拷贝到 ./i18n
文件下。
然后在对应的翻译文件添加对应的翻译。
zh.yaml
文件
- id: copyright_statement
translation: "版权声明"
./i18n
文件
- id: copyright_statement
translation: "Copyright"