Skip to content

Commit ff40c6a

Browse files
committed
chore: 🤖 添加加密与应用文章
1 parent ef39162 commit ff40c6a

File tree

29 files changed

+3179
-1894
lines changed

29 files changed

+3179
-1894
lines changed

.github/workflows/deploy.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,23 @@ jobs:
2828
- name: Setup Node
2929
uses: actions/setup-node@v4
3030
with:
31-
node-version: 20
31+
node-version: 22
3232
- name: Setup pnpm
3333
uses: pnpm/action-setup@v4
3434
id: pnpm-install
3535
with:
3636
version: 9
37+
- name: Get pnpm store directory
38+
shell: bash
39+
run: |
40+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
41+
- name: Setup pnpm cache
42+
uses: actions/cache@v4
43+
with:
44+
path: ${{ env.STORE_PATH }}
45+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
46+
restore-keys: |
47+
${{ runner.os }}-pnpm-store-
3748
- name: Install dependencies
3849
run: pnpm i --no-frozen-lockfile
3950
- name: Build
@@ -44,5 +55,5 @@ jobs:
4455
github_token: ${{ secrets.GITHUB_TOKEN }}
4556
personal_token: ${{ secrets.PERSONAL_TOKEN }}
4657
publish_dir: .vitepress/dist
47-
user_name: 幺幺零玖
58+
user_name: 零玖
4859
user_email: [email protected]

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
registry=https://registry.npmjs.org/
2+
strict-ssl=false

.vitepress/config.mts

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,64 @@
1-
import { defineConfig } from 'vitepress';
2-
import type { DefaultTheme } from 'vitepress';
3-
import imagePlugin from './markdown/imagePlugin';
4-
import { getPosts } from './theme/serverUtils';
1+
import type { DefaultTheme } from 'vitepress'
2+
import { globby } from 'globby'
3+
import { defineConfig } from 'vitepress'
4+
import { generatePaginationPages } from './data/post.data.ts'
5+
import imagePlugin from './markdown/imagePlugin'
56

6-
const navize = 10;
7-
8-
export default defineConfig({
9-
title: '幺幺零玖',
10-
description: 'A VitePress Site',
11-
themeConfig: {
12-
outline: {
13-
label: '页面导航',
14-
// level: [2, 3],
15-
},
16-
posts: await getPosts(navize),
17-
nav: [
18-
{ text: '首页', link: '/' },
19-
{ text: '分类', link: '/nav/category' },
20-
{ text: '标签', link: '/nav/tags' },
21-
{ text: '历史', link: '/nav/archives' },
22-
{
23-
text: '基础知识',
24-
items: [
25-
{ text: '设计', link: '/frontend/design' },
26-
{ text: '浏览器', link: '/frontend/browser' },
27-
{ text: 'html', link: '/frontend/html' },
28-
{ text: 'css', link: '/frontend/css' },
29-
{ text: 'javaScript', link: '/frontend/javaScript' },
30-
{ text: 'vue', link: '/frontend/vue' },
31-
],
7+
export default async () => {
8+
const posts = await globby(['posts/**.md'])
9+
await generatePaginationPages(posts.length, 10)
10+
return defineConfig({
11+
title: '零玖',
12+
description: 'A VitePress Site',
13+
themeConfig: {
14+
outline: {
15+
label: '导航',
16+
// level: [2, 3],
17+
},
18+
nav: [
19+
{ text: '首页', link: '/' },
20+
{
21+
text: '文章',
22+
items: [
23+
{ text: '历史', link: '/nav/archives' },
24+
{ text: '分类', link: '/nav/category' },
25+
{ text: '标签', link: '/nav/tags' },
26+
],
27+
},
28+
{
29+
text: '基础知识',
30+
items: [
31+
{ text: '设计', link: '/frontend/design' },
32+
{ text: '浏览器', link: '/frontend/browser' },
33+
{ text: 'html', link: '/frontend/html' },
34+
{ text: 'css', link: '/frontend/css' },
35+
{ text: 'javaScript', link: '/frontend/javaScript' },
36+
{ text: 'vue', link: '/frontend/vue' },
37+
],
38+
},
39+
{
40+
text: '导航',
41+
items: [
42+
{ text: '工具', link: '/frontend/nav/tool' },
43+
{ text: '镜像', link: '/frontend/nav/mirrors' },
44+
],
45+
},
46+
{ text: '关于', link: '/nav/about' },
47+
],
48+
search: {
49+
provider: 'local',
50+
},
51+
socialLinks: [
52+
{
53+
icon: 'github',
54+
link: 'https://github.com/vuejs/vitepress',
55+
},
56+
],
57+
} as DefaultTheme.Config,
58+
markdown: {
59+
config: (md) => {
60+
md.use(imagePlugin as any)
3261
},
33-
{ text: '前端导航', link: '/frontend/nav' },
34-
{ text: '关于', link: '/nav/about' },
35-
],
36-
search: {
37-
provider: 'local',
38-
},
39-
socialLinks: [
40-
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' },
41-
],
42-
} as DefaultTheme.Config,
43-
markdown: {
44-
config: (md) => {
45-
md.use(imagePlugin as any);
4662
},
47-
},
48-
});
63+
})
64+
}

.vitepress/data/post.data.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { resolve } from 'node:path'
2+
import fs from 'fs-extra'
3+
import matter from 'gray-matter'
4+
5+
interface Post {
6+
frontMatter: {
7+
date: string
8+
title: string
9+
category: string
10+
tags: string[]
11+
description: string
12+
}
13+
regularPath: string
14+
}
15+
16+
export async function generatePaginationPages(total: number, pageSize: number) {
17+
// pagesNum
18+
const pagesNum = total % pageSize === 0 ? total / pageSize : Number.parseInt(`${total / pageSize}`) + 1
19+
const paths = resolve('./')
20+
if (total > 0) {
21+
for (let i = 1; i < pagesNum + 1; i++) {
22+
const page = `
23+
---
24+
page: true
25+
title: ${i === 1 ? 'home' : `page_${i}`}
26+
aside: false
27+
---
28+
<script setup>
29+
import Page from "./.vitepress/theme/components/Page.vue";
30+
import { data } from './.vitepress/data/post.data'
31+
const posts = data.slice(${pageSize * (i - 1)},${pageSize * i})
32+
</script>
33+
<Page :posts="posts" :pageCurrent="${i}" :pagesNum="${pagesNum}" />
34+
`.trim()
35+
const file = `${paths}/page_${i}.md`
36+
await fs.writeFile(file, page)
37+
}
38+
}
39+
// rename page_1 to index for homepage
40+
await fs.move(`${paths}/page_1.md`, `${paths}/index.md`, { overwrite: true })
41+
}
42+
43+
function _convertDate(date = new Date().toString()) {
44+
const json_date = new Date(date).toJSON()
45+
return json_date.split('T')[0]
46+
}
47+
48+
function _compareDate(obj1, obj2) {
49+
return obj1.frontMatter.date < obj2.frontMatter.date ? 1 : -1
50+
}
51+
52+
export const data = [] as Post[]
53+
54+
export default {
55+
watch: ['../../posts/**/*.md'],
56+
async load(paths: string[]) {
57+
const posts = await Promise.all(
58+
paths.map(async (item) => {
59+
const content = await fs.readFile(item, 'utf-8')
60+
const { data } = matter(content)
61+
data.date = _convertDate(data.date)
62+
return {
63+
frontMatter: data,
64+
regularPath: `/${item.replace('.md', '.html')}`,
65+
}
66+
}),
67+
)
68+
posts.sort(_compareDate)
69+
return posts
70+
},
71+
}

.vitepress/theme/components/Archives.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<script lang="ts" setup>
2-
import { useData, withBase } from 'vitepress'
2+
import { withBase } from 'vitepress'
33
import { computed } from 'vue'
4+
import { data } from '../../data/post.data'
45
import { useYearSort } from '../functions'
56
6-
const { theme } = useData()
7-
const data = computed(() => useYearSort(theme.value.posts))
7+
const sortData = computed(() => useYearSort(data))
88
</script>
99

1010
<template>
11-
<div v-for="(yearList, key) in data" :key="key">
11+
<div v-for="(yearList, key) in sortData" :key="key">
1212
<div class="year">
1313
{{ yearList[0].frontMatter.date.split('-')[0] }}
1414
</div>

.vitepress/theme/components/Category.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<script lang="ts" setup>
2-
import { useData, withBase } from 'vitepress'
2+
import { withBase } from 'vitepress'
33
import { computed } from 'vue'
4+
import { data } from '../../data/post.data'
45
import { initCategory } from '../functions'
56
6-
const { theme } = useData()
7-
const data = computed(() => initCategory(theme.value.posts))
7+
const sortData = computed(() => initCategory(data))
88
</script>
99

1010
<template>
11-
<div v-for="(posts, key) in data" :key="key">
11+
<div v-for="(posts, key) in sortData" :key="key">
1212
<div class="category">
1313
{{ key }}
1414
</div>

.vitepress/theme/components/Tags.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script lang="ts" setup>
2+
import { withBase } from 'vitepress'
23
import { computed, ref } from 'vue'
3-
import { useData, withBase } from 'vitepress'
4+
import { data } from '../../data/post.data'
45
import { initTags } from '../functions'
56
67
const url = location.href.split('?')[1]
78
const params = new URLSearchParams(url)
8-
const { theme } = useData()
9-
const data = computed(() => initTags(theme.value.posts))
9+
const sortData = computed(() => initTags(data))
1010
const selectTag = ref<string | number>(params.get('tag') as string ? params.get('tag') as string : '')
1111
function toggleTag(tag: string | number) {
1212
selectTag.value = tag
@@ -15,8 +15,8 @@ function toggleTag(tag: string | number) {
1515

1616
<template>
1717
<div class="tags">
18-
<span v-for="(item, key) in data" :key="key" class="tag" @click="toggleTag(key)">
19-
{{ key }} <strong>{{ data[key].length }}</strong>
18+
<span v-for="(item, key) in sortData" :key="key" class="tag" @click="toggleTag(key)">
19+
{{ key }} <strong>{{ sortData[key].length }}</strong>
2020
</span>
2121
</div>
2222
<div class="tag-header">

.vitepress/theme/functions.ts

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,70 @@
1-
type Post = {
1+
interface Post {
22
frontMatter: {
3-
date: string;
4-
title: string;
5-
category: string;
6-
tags: string[];
7-
description: string;
8-
};
9-
regularPath: string;
10-
};
3+
date: string
4+
title: string
5+
category: string
6+
tags: string[]
7+
description: string
8+
}
9+
regularPath: string
10+
}
1111

1212
export function initTags(post: Post[]) {
13-
const data: any = {};
13+
const data: any = {}
1414
for (let index = 0; index < post.length; index++) {
15-
const element = post[index];
16-
const tags = element.frontMatter.tags;
15+
const element = post[index]
16+
const tags = element.frontMatter.tags
1717
if (tags) {
1818
tags.forEach((item) => {
1919
if (data[item]) {
20-
data[item].push(element);
21-
} else {
22-
data[item] = [];
23-
data[item].push(element);
20+
data[item].push(element)
21+
}
22+
else {
23+
data[item] = []
24+
data[item].push(element)
2425
}
25-
});
26+
})
2627
}
2728
}
28-
return data;
29+
return data
2930
}
3031

3132
export function initCategory(post: Post[]) {
32-
const data: any = {};
33+
const data: any = {}
3334
for (let index = 0; index < post.length; index++) {
34-
const element = post[index];
35-
const category = element.frontMatter.category;
35+
const element = post[index]
36+
const category = element.frontMatter.category
3637
if (category) {
3738
if (data[category]) {
38-
data[category].push(element);
39-
} else {
40-
data[category] = [];
41-
data[category].push(element);
39+
data[category].push(element)
40+
}
41+
else {
42+
data[category] = []
43+
data[category].push(element)
4244
}
4345
}
4446
}
45-
return data;
47+
return data
4648
}
4749

4850
export function useYearSort(post: Post[]) {
49-
const data = [];
50-
let year = '0';
51-
let num = -1;
51+
const data: any = []
52+
let year = '0'
53+
let num = -1
5254
for (let index = 0; index < post.length; index++) {
53-
const element = post[index];
55+
const element = post[index]
5456
if (element.frontMatter.date) {
55-
const y = element.frontMatter.date.split('-')[0];
57+
const y = element.frontMatter.date.split('-')[0]
5658
if (y === year) {
57-
data[num].push(element);
58-
} else {
59-
num++;
60-
data[num] = [] as any;
61-
data[num].push(element);
62-
year = y;
59+
data[num].push(element)
60+
}
61+
else {
62+
num++
63+
data[num] = [] as any
64+
data[num].push(element)
65+
year = y
6366
}
6467
}
6568
}
66-
return data;
69+
return data
6770
}

0 commit comments

Comments
 (0)