Skip to content

Commit

Permalink
chore: 🤖 添加加密与应用文章
Browse files Browse the repository at this point in the history
  • Loading branch information
vxow committed Jan 6, 2025
1 parent ef39162 commit ff40c6a
Show file tree
Hide file tree
Showing 29 changed files with 3,179 additions and 1,894 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
- name: Setup pnpm
uses: pnpm/action-setup@v4
id: pnpm-install
with:
version: 9
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm i --no-frozen-lockfile
- name: Build
Expand All @@ -44,5 +55,5 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
personal_token: ${{ secrets.PERSONAL_TOKEN }}
publish_dir: .vitepress/dist
user_name: 幺幺零玖
user_name: 零玖
user_email: gmj413966791@163.com
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
registry=https://registry.npmjs.org/
strict-ssl=false
106 changes: 61 additions & 45 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,48 +1,64 @@
import { defineConfig } from 'vitepress';
import type { DefaultTheme } from 'vitepress';
import imagePlugin from './markdown/imagePlugin';
import { getPosts } from './theme/serverUtils';
import type { DefaultTheme } from 'vitepress'
import { globby } from 'globby'
import { defineConfig } from 'vitepress'
import { generatePaginationPages } from './data/post.data.ts'
import imagePlugin from './markdown/imagePlugin'

const navize = 10;

export default defineConfig({
title: '幺幺零玖',
description: 'A VitePress Site',
themeConfig: {
outline: {
label: '页面导航',
// level: [2, 3],
},
posts: await getPosts(navize),
nav: [
{ text: '首页', link: '/' },
{ text: '分类', link: '/nav/category' },
{ text: '标签', link: '/nav/tags' },
{ text: '历史', link: '/nav/archives' },
{
text: '基础知识',
items: [
{ text: '设计', link: '/frontend/design' },
{ text: '浏览器', link: '/frontend/browser' },
{ text: 'html', link: '/frontend/html' },
{ text: 'css', link: '/frontend/css' },
{ text: 'javaScript', link: '/frontend/javaScript' },
{ text: 'vue', link: '/frontend/vue' },
],
export default async () => {
const posts = await globby(['posts/**.md'])
await generatePaginationPages(posts.length, 10)
return defineConfig({
title: '零玖',
description: 'A VitePress Site',
themeConfig: {
outline: {
label: '导航',
// level: [2, 3],
},
nav: [
{ text: '首页', link: '/' },
{
text: '文章',
items: [
{ text: '历史', link: '/nav/archives' },
{ text: '分类', link: '/nav/category' },
{ text: '标签', link: '/nav/tags' },
],
},
{
text: '基础知识',
items: [
{ text: '设计', link: '/frontend/design' },
{ text: '浏览器', link: '/frontend/browser' },
{ text: 'html', link: '/frontend/html' },
{ text: 'css', link: '/frontend/css' },
{ text: 'javaScript', link: '/frontend/javaScript' },
{ text: 'vue', link: '/frontend/vue' },
],
},
{
text: '导航',
items: [
{ text: '工具', link: '/frontend/nav/tool' },
{ text: '镜像', link: '/frontend/nav/mirrors' },
],
},
{ text: '关于', link: '/nav/about' },
],
search: {
provider: 'local',
},
socialLinks: [
{
icon: 'github',
link: 'https://github.com/vuejs/vitepress',
},
],
} as DefaultTheme.Config,
markdown: {
config: (md) => {
md.use(imagePlugin as any)
},
{ text: '前端导航', link: '/frontend/nav' },
{ text: '关于', link: '/nav/about' },
],
search: {
provider: 'local',
},
socialLinks: [
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' },
],
} as DefaultTheme.Config,
markdown: {
config: (md) => {
md.use(imagePlugin as any);
},
},
});
})
}
71 changes: 71 additions & 0 deletions .vitepress/data/post.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { resolve } from 'node:path'
import fs from 'fs-extra'
import matter from 'gray-matter'

interface Post {
frontMatter: {
date: string
title: string
category: string
tags: string[]
description: string
}
regularPath: string
}

export async function generatePaginationPages(total: number, pageSize: number) {
// pagesNum
const pagesNum = total % pageSize === 0 ? total / pageSize : Number.parseInt(`${total / pageSize}`) + 1
const paths = resolve('./')
if (total > 0) {
for (let i = 1; i < pagesNum + 1; i++) {
const page = `
---
page: true
title: ${i === 1 ? 'home' : `page_${i}`}
aside: false
---
<script setup>
import Page from "./.vitepress/theme/components/Page.vue";
import { data } from './.vitepress/data/post.data'
const posts = data.slice(${pageSize * (i - 1)},${pageSize * i})
</script>
<Page :posts="posts" :pageCurrent="${i}" :pagesNum="${pagesNum}" />
`.trim()
const file = `${paths}/page_${i}.md`
await fs.writeFile(file, page)
}
}
// rename page_1 to index for homepage
await fs.move(`${paths}/page_1.md`, `${paths}/index.md`, { overwrite: true })
}

function _convertDate(date = new Date().toString()) {
const json_date = new Date(date).toJSON()
return json_date.split('T')[0]
}

function _compareDate(obj1, obj2) {
return obj1.frontMatter.date < obj2.frontMatter.date ? 1 : -1
}

export const data = [] as Post[]

export default {
watch: ['../../posts/**/*.md'],
async load(paths: string[]) {
const posts = await Promise.all(
paths.map(async (item) => {
const content = await fs.readFile(item, 'utf-8')
const { data } = matter(content)
data.date = _convertDate(data.date)
return {
frontMatter: data,
regularPath: `/${item.replace('.md', '.html')}`,
}
}),
)
posts.sort(_compareDate)
return posts
},
}
8 changes: 4 additions & 4 deletions .vitepress/theme/components/Archives.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script lang="ts" setup>
import { useData, withBase } from 'vitepress'
import { withBase } from 'vitepress'
import { computed } from 'vue'
import { data } from '../../data/post.data'
import { useYearSort } from '../functions'
const { theme } = useData()
const data = computed(() => useYearSort(theme.value.posts))
const sortData = computed(() => useYearSort(data))
</script>

<template>
<div v-for="(yearList, key) in data" :key="key">
<div v-for="(yearList, key) in sortData" :key="key">
<div class="year">
{{ yearList[0].frontMatter.date.split('-')[0] }}
</div>
Expand Down
8 changes: 4 additions & 4 deletions .vitepress/theme/components/Category.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script lang="ts" setup>
import { useData, withBase } from 'vitepress'
import { withBase } from 'vitepress'
import { computed } from 'vue'
import { data } from '../../data/post.data'
import { initCategory } from '../functions'
const { theme } = useData()
const data = computed(() => initCategory(theme.value.posts))
const sortData = computed(() => initCategory(data))
</script>

<template>
<div v-for="(posts, key) in data" :key="key">
<div v-for="(posts, key) in sortData" :key="key">
<div class="category">
{{ key }}
</div>
Expand Down
10 changes: 5 additions & 5 deletions .vitepress/theme/components/Tags.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script lang="ts" setup>
import { withBase } from 'vitepress'
import { computed, ref } from 'vue'
import { useData, withBase } from 'vitepress'
import { data } from '../../data/post.data'
import { initTags } from '../functions'
const url = location.href.split('?')[1]
const params = new URLSearchParams(url)
const { theme } = useData()
const data = computed(() => initTags(theme.value.posts))
const sortData = computed(() => initTags(data))
const selectTag = ref<string | number>(params.get('tag') as string ? params.get('tag') as string : '')
function toggleTag(tag: string | number) {
selectTag.value = tag
Expand All @@ -15,8 +15,8 @@ function toggleTag(tag: string | number) {

<template>
<div class="tags">
<span v-for="(item, key) in data" :key="key" class="tag" @click="toggleTag(key)">
{{ key }} <strong>{{ data[key].length }}</strong>
<span v-for="(item, key) in sortData" :key="key" class="tag" @click="toggleTag(key)">
{{ key }} <strong>{{ sortData[key].length }}</strong>
</span>
</div>
<div class="tag-header">
Expand Down
79 changes: 41 additions & 38 deletions .vitepress/theme/functions.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,70 @@
type Post = {
interface Post {
frontMatter: {
date: string;
title: string;
category: string;
tags: string[];
description: string;
};
regularPath: string;
};
date: string
title: string
category: string
tags: string[]
description: string
}
regularPath: string
}

export function initTags(post: Post[]) {
const data: any = {};
const data: any = {}
for (let index = 0; index < post.length; index++) {
const element = post[index];
const tags = element.frontMatter.tags;
const element = post[index]
const tags = element.frontMatter.tags
if (tags) {
tags.forEach((item) => {
if (data[item]) {
data[item].push(element);
} else {
data[item] = [];
data[item].push(element);
data[item].push(element)
}
else {
data[item] = []
data[item].push(element)
}
});
})
}
}
return data;
return data
}

export function initCategory(post: Post[]) {
const data: any = {};
const data: any = {}
for (let index = 0; index < post.length; index++) {
const element = post[index];
const category = element.frontMatter.category;
const element = post[index]
const category = element.frontMatter.category
if (category) {
if (data[category]) {
data[category].push(element);
} else {
data[category] = [];
data[category].push(element);
data[category].push(element)
}
else {
data[category] = []
data[category].push(element)
}
}
}
return data;
return data
}

export function useYearSort(post: Post[]) {
const data = [];
let year = '0';
let num = -1;
const data: any = []
let year = '0'
let num = -1
for (let index = 0; index < post.length; index++) {
const element = post[index];
const element = post[index]
if (element.frontMatter.date) {
const y = element.frontMatter.date.split('-')[0];
const y = element.frontMatter.date.split('-')[0]
if (y === year) {
data[num].push(element);
} else {
num++;
data[num] = [] as any;
data[num].push(element);
year = y;
data[num].push(element)
}
else {
num++
data[num] = [] as any
data[num].push(element)
year = y
}
}
}
return data;
return data
}
Loading

0 comments on commit ff40c6a

Please sign in to comment.