-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
3,179 additions
and
1,894 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
registry=https://registry.npmjs.org/ | ||
strict-ssl=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}, | ||
}); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.