Skip to content

Commit 3b338ea

Browse files
committed
add copyright layout
1 parent 2768e2f commit 3b338ea

File tree

6 files changed

+181
-24
lines changed

6 files changed

+181
-24
lines changed

docs/.vuepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { defineUserConfig } from "vuepress"
99
export default defineUserConfig({
1010
bundler: viteBundler(),
1111
theme: nesercodeTheme({
12+
domain: "http://localhost:8080",
1213
giscus: {
1314
repo: "NeserCode/NeserCode.github.io",
1415
repoId: "R_kgDOHf8WIA",
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<script lang="ts" setup>
2+
import { AutoLink } from "vuepress/client"
3+
import { computed, toRefs } from "vue"
4+
5+
const $props = defineProps<{
6+
isOriginal: boolean
7+
originalUrl?: string
8+
tips?: string[]
9+
}>()
10+
const { isOriginal, originalUrl, tips } = toRefs($props)
11+
12+
const decodedUrl = computed(() => {
13+
if (originalUrl && originalUrl.value) {
14+
return decodeURIComponent(originalUrl.value)
15+
}
16+
return ""
17+
})
18+
19+
const linkItem = computed(() => ({
20+
text: "CC BY-SA 4.0",
21+
link: "https://creativecommons.org/licenses/by-sa/4.0/deed",
22+
}))
23+
24+
function copyInfo() {
25+
const text = `本文遵循 ${linkItem.value.text} 版权协议,转载请附上出处链接及本声明。文章出处:${decodedUrl.value}`
26+
if (navigator && navigator.clipboard) navigator.clipboard.writeText(text)
27+
}
28+
function copyLink() {
29+
if (navigator && navigator.clipboard)
30+
navigator.clipboard.writeText(decodedUrl.value)
31+
}
32+
function goLink() {
33+
window.open(decodedUrl.value)
34+
}
35+
</script>
36+
37+
<template>
38+
<div class="v-nc-copyright">
39+
<div class="copyright-container">
40+
<span class="info">
41+
<span class="title" v-if="isOriginal"
42+
>本文为原创文章,遵循
43+
<AutoLink :config="linkItem" />
44+
版权协议,转载请附上原文出处链接及本声明。</span
45+
>
46+
<span class="title" v-else>本文为转载文章,如欲转载请联系原作者</span>
47+
<span v-for="tip in tips" :key="tip" class="tip">{{ tip }}</span>
48+
<span class="origin-url">文章链接:{{ decodedUrl }}</span>
49+
<span class="operate">
50+
<button class="btn" @click="copyInfo">一键复制</button>
51+
<button class="btn" @click="copyLink">复制文章地址</button>
52+
<button class="btn" @click="goLink" v-if="!isOriginal">
53+
前往文章地址
54+
</button>
55+
</span>
56+
</span>
57+
<span class="icon">
58+
<svg
59+
t="1679731809836"
60+
class="cc-svg"
61+
viewBox="0 0 1024 1024"
62+
version="1.1"
63+
xmlns="http://www.w3.org/2000/svg"
64+
p-id="893"
65+
>
66+
<path
67+
d="M516.56 512.016m-461.376 0a461.376 461.376 0 1 0 922.752 0 461.376 461.376 0 1 0-922.752 0Z"
68+
fill="transparent"
69+
p-id="894"
70+
></path>
71+
<path
72+
class="cc-svg-path"
73+
d="M511.056 0c143.216 0 265.152 50 365.712 149.952 48.128 48.144 84.72 103.168 109.712 165.024 24.976 61.872 37.504 127.536 37.504 197.024 0 70.096-12.368 135.776-37.024 197.008-24.688 61.248-61.12 115.36-109.248 162.288-49.968 49.36-106.656 87.168-170.064 113.376-63.376 26.208-128.912 39.312-196.56 39.312s-132.416-12.928-194.288-38.864c-61.856-25.888-117.328-63.376-166.4-112.432-49.072-49.056-86.4-104.384-112-165.952S0 580.272 0 512c0-67.664 12.944-132.72 38.848-195.2 25.904-62.48 63.552-118.4 112.912-167.776C249.28 49.696 369.04 0 511.056 0z m1.856 92.352c-117.024 0-215.472 40.848-295.328 122.512-40.24 40.848-71.168 86.704-92.8 137.6a403.264 403.264 0 0 0-32.464 159.552c0 54.864 10.8 107.744 32.464 158.608 21.648 50.928 52.56 96.336 92.8 136.256 40.224 39.936 85.616 70.384 136.24 91.44a410.432 410.432 0 0 0 159.088 31.536c54.848 0 108-10.64 159.568-31.984 51.504-21.36 97.936-52.112 139.408-92.336 79.84-78.016 119.744-175.84 119.744-293.504 0-56.688-10.368-110.32-31.088-160.912-20.688-50.592-50.88-95.68-90.464-135.328-82.336-82.288-181.36-123.44-297.168-123.44z m-6.416 334.64l-68.592 35.664c-7.328-15.216-16.304-25.904-26.96-32-10.672-6.08-20.576-9.136-29.728-9.136-45.696 0-68.576 30.16-68.576 90.512 0 27.424 5.792 49.344 17.36 65.808 11.584 16.464 28.656 24.704 51.216 24.704 29.872 0 50.896-14.64 63.104-43.888l63.072 32c-13.408 25.008-32 44.656-55.776 58.976-23.744 14.336-49.968 21.488-78.624 21.488-45.712 0-82.608-14-110.64-42.064-28.032-28.032-42.048-67.04-42.048-117.008 0-48.768 14.176-87.456 42.512-116.112 28.336-28.64 64.144-42.976 107.44-42.976 63.408-0.032 108.8 24.656 136.24 74.032z m295.312 0l-67.664 35.664c-7.312-15.216-16.32-25.904-26.976-32-10.688-6.08-20.912-9.136-30.624-9.136-45.712 0-68.592 30.16-68.592 90.512 0 27.424 5.808 49.344 17.376 65.808 11.568 16.464 28.624 24.704 51.216 24.704 29.84 0 50.88-14.64 63.056-43.888l64 32c-14 25.008-32.912 44.656-56.656 58.976a147.728 147.728 0 0 1-77.712 21.488c-46.336 0-83.344-14-111.056-42.064-27.776-28.032-41.632-67.04-41.632-117.008 0-48.768 14.16-87.456 42.528-116.112 28.32-28.64 64.128-42.976 107.408-42.976 63.392-0.032 108.528 24.656 135.328 74.032z"
74+
p-id="895"
75+
></path>
76+
</svg>
77+
</span>
78+
</div>
79+
</div>
80+
</template>
81+
82+
<style lang="postcss" scoped>
83+
.v-nc-copyright {
84+
@apply w-full my-4 mt-12 flex
85+
opacity-90 overflow-hidden;
86+
}
87+
88+
.v-nc-copyright .copyright-container {
89+
@apply relative w-full flex p-4
90+
rounded border-2 border-slate-400 dark:border-slate-500;
91+
}
92+
93+
.copyright-container .info {
94+
@apply w-full inline-flex flex-col
95+
z-10;
96+
}
97+
.copyright-container .icon {
98+
@apply absolute w-36 right-2 top-2
99+
fill-slate-400 dark:fill-slate-500
100+
z-0;
101+
}
102+
103+
.info .operate {
104+
@apply w-fit inline-flex flex-wrap gap-x-2 mt-2;
105+
}
106+
107+
.info .operate .btn {
108+
@apply w-fit inline-block px-2 py-1
109+
rounded bg-slate-200 dark:bg-slate-700
110+
text-sm
111+
transition-all ease-in-out duration-300;
112+
}
113+
</style>

docs/.vuepress/theme/lib/client/components/GithubRepo.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ onBeforeMount(() => {
6767
<span class="prefix">Linked Github Repo</span>
6868
<a :href="repoInfo?.data?.html_url" class="card-main" target="_blank">
6969
<span class="repo-title">
70-
<BookmarkSquareIcon class="icon" />
71-
<span class="repo-name">
72-
<span class="repo">{{ repo }}</span>
73-
<span class="owner">{{ owner }}</span>
74-
</span>
70+
<span class="repo-name"> {{ repo }} / {{ owner }} </span>
7571
</span>
7672
<span class="repo-description" v-if="repoInfo?.data?.description">{{
7773
repoInfo?.data?.description
@@ -84,11 +80,11 @@ onBeforeMount(() => {
8480
<span class="other">
8581
<span
8682
class="license"
87-
v-html="`[License] ${repoInfo?.data?.license?.spdx_id}`"
83+
v-html="`License - ${repoInfo?.data?.license?.spdx_id}`"
8884
/>
8985
<span
9086
class="lang"
91-
v-html="`[Language] ${repoInfo?.data?.language}`"
87+
v-html="`Language - ${repoInfo?.data?.language}`"
9288
/>
9389
</span>
9490
</a>

docs/.vuepress/theme/lib/client/components/Page.vue

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ setupHeaders()
9191
<slot name="before-content"></slot>
9292

9393
<Content class="v-nc-content" />
94+
95+
<div class="content-end">
96+
<span class="text">- END -</span>
97+
</div>
98+
<slot name="before-comment"></slot>
99+
94100
<Comment :options="commentOption" />
95101

96102
<slot name="after-content"> </slot>
@@ -115,15 +121,15 @@ setupHeaders()
115121
@apply hidden;
116122
}
117123
.v-nc-content h2,
118-
.v-nc-content + .v-nc-theme-comment h2,
124+
.v-nc-content ~ .v-nc-theme-comment h2,
119125
.v-nc-content h3,
120-
.v-nc-content + .v-nc-theme-comment h3,
126+
.v-nc-content ~ .v-nc-theme-comment h3,
121127
.v-nc-content h4,
122-
.v-nc-content + .v-nc-theme-comment h4,
128+
.v-nc-content ~ .v-nc-theme-comment h4,
123129
.v-nc-content h5,
124-
.v-nc-content + .v-nc-theme-comment h5,
130+
.v-nc-content ~ .v-nc-theme-comment h5,
125131
.v-nc-content h6,
126-
.v-nc-content + .v-nc-theme-comment h6 {
132+
.v-nc-content ~ .v-nc-theme-comment h6 {
127133
margin-top: calc(0.5rem - 64px);
128134
padding-top: calc(0.5rem + 64px);
129135
@apply relative mb-8 pb-4
@@ -133,37 +139,37 @@ setupHeaders()
133139
}
134140
135141
.v-nc-content h2 a.header-anchor::before,
136-
.v-nc-content + .v-nc-theme-comment h2 a.header-anchor::before,
142+
.v-nc-content ~ .v-nc-theme-comment h2 a.header-anchor::before,
137143
.v-nc-content h3 a.header-anchor::before,
138-
.v-nc-content + .v-nc-theme-comment h3 a.header-anchor::before,
144+
.v-nc-content ~ .v-nc-theme-comment h3 a.header-anchor::before,
139145
.v-nc-content h4 a.header-anchor::before,
140-
.v-nc-content + .v-nc-theme-comment h4 a.header-anchor::before,
146+
.v-nc-content ~ .v-nc-theme-comment h4 a.header-anchor::before,
141147
.v-nc-content h5 a.header-anchor::before,
142-
.v-nc-content + .v-nc-theme-comment h5 a.header-anchor::before,
148+
.v-nc-content ~ .v-nc-theme-comment h5 a.header-anchor::before,
143149
.v-nc-content h6 a.header-anchor::before,
144-
.v-nc-content + .v-nc-theme-comment h6 a.header-anchor::before {
150+
.v-nc-content ~ .v-nc-theme-comment h6 a.header-anchor::before {
145151
content: "#";
146152
@apply absolute sm:inline-block hidden
147153
text-green-500
148154
font-thin -translate-x-5;
149155
}
150156
151157
.v-nc-content h2,
152-
.v-nc-content + .v-nc-theme-comment h2 {
158+
.v-nc-content ~ .v-nc-theme-comment h2 {
153159
@apply text-2xl font-bold;
154160
}
155161
.v-nc-content h3,
156-
.v-nc-content + .v-nc-theme-comment h3 {
162+
.v-nc-content ~ .v-nc-theme-comment h3 {
157163
@apply text-xl font-bold;
158164
}
159165
.v-nc-content h4,
160-
.v-nc-content + .v-nc-theme-comment h4 {
166+
.v-nc-content ~ .v-nc-theme-comment h4 {
161167
@apply text-lg font-bold;
162168
}
163169
.v-nc-content h5,
164-
.v-nc-content + .v-nc-theme-comment h5,
170+
.v-nc-content ~ .v-nc-theme-comment h5,
165171
.v-nc-content h6,
166-
.v-nc-content + .v-nc-theme-comment h6 {
172+
.v-nc-content ~ .v-nc-theme-comment h6 {
167173
@apply text-base font-bold;
168174
}
169175
@@ -298,4 +304,11 @@ section.footnotes::before {
298304
h1.page-title {
299305
@apply text-3xl font-black;
300306
}
307+
308+
.content-end {
309+
@apply w-full inline-flex justify-center items-center py-2 mt-8;
310+
}
311+
.content-end .text {
312+
@apply text-xl font-mono font-black;
313+
}
301314
</style>

docs/.vuepress/theme/lib/client/layouts/Layout.vue

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ import Page from "../components/Page.vue"
44
import Home from "../components/Home.vue"
55
66
import GithubRepo from "../components/GithubRepo.vue"
7+
import Copyright from "../components/Copyright.vue"
78
8-
import { usePageFrontmatter } from "vuepress/client"
9+
import { usePageData, usePageFrontmatter, useSiteData } from "vuepress/client"
910
import { computed } from "vue"
10-
import { DefaultThemeNormalPageFrontmatter } from "../../shared"
11+
import {
12+
DefaultThemeData,
13+
DefaultThemeNormalPageFrontmatter,
14+
DefaultThemePageData,
15+
} from "../../shared"
16+
import { useThemeData } from "@vuepress/plugin-theme-data/client"
1117
18+
const pageData = usePageData<DefaultThemePageData>()
1219
const pageFrontmatter = usePageFrontmatter<DefaultThemeNormalPageFrontmatter>()
20+
const themeLocale = useThemeData<DefaultThemeData>()
21+
const siteData = useSiteData()
1322
1423
// repo info
1524
const githubRepoData = computed(() => {
@@ -20,6 +29,21 @@ const githubRepoData = computed(() => {
2029
repo: data[1],
2130
}
2231
})
32+
33+
/* Original */
34+
const isOriginal = computed(() => {
35+
if (pageFrontmatter.value.original === false) return false
36+
else return true
37+
})
38+
const originalUrl = computed(() => {
39+
if (pageFrontmatter.value.originalUrl)
40+
return pageFrontmatter.value.originalUrl
41+
return (
42+
themeLocale.value.domain +
43+
((siteData.value.base ?? "") + pageData.value.path).replace("//", "/")
44+
)
45+
})
46+
const copyrightTips = [""]
2347
</script>
2448

2549
<template>
@@ -47,6 +71,13 @@ const githubRepoData = computed(() => {
4771
<template #before-content>
4872
<slot name="before-content" />
4973
</template>
74+
<template #before-comment>
75+
<Copyright
76+
:isOriginal="isOriginal"
77+
:originalUrl="originalUrl"
78+
:tips="copyrightTips"
79+
/>
80+
</template>
5081
<template #after-content>
5182
<slot name="after-content" />
5283
</template>

docs/.vuepress/theme/lib/shared/page.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export interface DefaultThemeNormalPageFrontmatter
6868
prev?: string | AutoLinkConfig
6969
next?: string | AutoLinkConfig
7070

71+
original?: boolean
72+
originalUrl?: string
73+
7174
repo?: `${string}/${string}`
7275
}
7376

0 commit comments

Comments
 (0)