Skip to content

Commit 83d6795

Browse files
yuyinwsWestonSeylersxzz
authored
docs: move docs (#369)
Co-authored-by: wawa0584 <[email protected]> Co-authored-by: 三咲智子 Kevin Deng <[email protected]>
1 parent 99fb6d9 commit 83d6795

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3766
-126
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ dist
77
node_modules
88
temp
99
.eslintcache
10+
11+
# docs
12+
docs/showcase/*.md
13+
!docs/showcase/index.md
14+
docs/.vitepress/cache
15+
docs/.vitepress/components.d.ts
16+
docs/.env
17+
docs/.vitepress/data/repository.json

.npmrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignore-workspace-root-check=true
2+
shell-emulator=true

docs/.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GITHUB_TOKEN=
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<script setup lang="ts">
2+
defineProps<{
3+
owner: string
4+
name: string
5+
stars: number
6+
forks: number
7+
}>()
8+
</script>
9+
10+
<template>
11+
<div flex gap-3 items-center justify-end>
12+
<div class="flex items-center text-gray-500 dark:text-gray-300 cursor-default">
13+
<i class="i-heroicons-star-solid" />
14+
<span ml-1>
15+
{{ stars.toLocaleString() }}
16+
</span>
17+
</div>
18+
19+
<div class="flex items-center text-gray-500 dark:text-gray-300 cursor-default">
20+
<i class="i-lucide-git-fork" />
21+
<span ml-1>
22+
{{ forks.toLocaleString() }}
23+
</span>
24+
</div>
25+
26+
<a target="_blank" :href="`https://github.com/${owner}/${name}`">
27+
<div class="flex text-gray-400" hover="text-gray-900" dark:hover="text-gray-200">
28+
<i class="i-radix-icons-github-logo" />
29+
<i class="i-heroicons-arrow-up-right-20-solid h-3 w-3" />
30+
</div>
31+
</a>
32+
33+
<a target="_blank" :href="`https://www.npmjs.com/package/${name}`">
34+
<div class="flex text-gray-400" hover="text-#C12127">
35+
<i class="i-simple-icons-npm " />
36+
<i class="i-heroicons-arrow-up-right-20-solid h-3 w-3" />
37+
</div>
38+
</a>
39+
</div>
40+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<script setup lang="ts">
2+
import { data as repositoryData } from '../data/repository.data'
3+
</script>
4+
5+
<template>
6+
<div flex="~ wrap" gap-3 items-center>
7+
<a
8+
v-for="(item, index) in repositoryData" :key="index"
9+
w-20rem h-42 px-4 py-3 cursor-pointer
10+
border="1 solid $vp-c-divider" rounded-md
11+
important-transition-all duration-400
12+
hover="shadow-md bg-$vp-c-bg-soft"
13+
:href="`/showcase/${item.name}`"
14+
flex="~ col"
15+
justify-between
16+
>
17+
<div flex items-center gap-2>
18+
<img :src="item.owner?.avatarUrl" rounded-full w-4 h-4 alt="">
19+
<span dark="text-gray-400" text-gray-500 text-16px>{{ item.owner.login }}/</span>
20+
</div>
21+
<div font-semibold dark="text-gray-200" text-gray-900 text-16px>
22+
{{ item.name }}
23+
</div>
24+
<div text-gray-500 dark="text-gray-400" flex-auto mt-2 text-14px>
25+
<span line-clamp-2>
26+
{{ item.description }}
27+
</span>
28+
</div>
29+
<div flex gap-5>
30+
<div flex items-center gap-1>
31+
<div
32+
w-3 h-3 rounded-full :style="{
33+
'background-color': item.primaryLanguage.color,
34+
}"
35+
/>
36+
<div text="14px gray-500" dark="text-gray-400">{{ item.primaryLanguage.name }}</div>
37+
</div>
38+
<div flex items-center gap-1 text="14px gray-500" dark="text-gray-400">
39+
<i class="i-radix-icons-star" />
40+
<div>{{ (item.stargazers.totalCount).toLocaleString() }}</div>
41+
</div>
42+
<div flex items-center gap-1 text="14px gray-500" dark="text-gray-400">
43+
<i class="i-lucide-git-fork" />
44+
<div>{{ (item.forkCount).toLocaleString() }}</div>
45+
</div>
46+
</div>
47+
</a>
48+
</div>
49+
</template>
50+
51+
<style scoped>
52+
a {
53+
cursor: pointer;
54+
text-decoration: none!important;
55+
}
56+
</style>

docs/.vitepress/config.ts

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import MarkdownItGitHubAlerts from 'markdown-it-github-alerts'
2+
import { defineConfig } from 'vitepress'
3+
4+
import { transformerTwoslash } from 'vitepress-plugin-twoslash'
5+
import { repositoryMeta } from './data/meta'
6+
import { description, ogImage, title } from './constance'
7+
8+
import vite from './vite.config'
9+
10+
// https://vitepress.dev/reference/site-config
11+
export default defineConfig({
12+
title,
13+
description,
14+
lastUpdated: true,
15+
themeConfig: {
16+
// https://vitepress.dev/reference/default-theme-config
17+
nav: [
18+
{ text: 'Guide', link: '/guide/', activeMatch: '/guide/' },
19+
{ text: 'Showcase', link: '/showcase/', activeMatch: '/showcase/' },
20+
],
21+
search: {
22+
provider: 'local',
23+
},
24+
logo: {
25+
light: '/logo_light.svg',
26+
dark: '/logo_dark.svg',
27+
},
28+
29+
sidebar: {
30+
'/': [
31+
{
32+
text: 'Guide',
33+
items: [
34+
{ text: 'Getting Started', link: '/guide/' },
35+
// { text: 'Why Unplugin', link: '/guide/why' },
36+
{ text: 'Plugin Conventions', link: '/guide/plugin-conventions' },
37+
],
38+
},
39+
{
40+
text: 'Showcase',
41+
link: '/showcase/',
42+
items: [
43+
{
44+
text: 'Overview',
45+
link: '/showcase/',
46+
},
47+
...repositoryMeta.map(repo => (
48+
{
49+
text: repo.name,
50+
link: `/showcase/${repo.name}`,
51+
}
52+
)),
53+
],
54+
},
55+
],
56+
},
57+
58+
socialLinks: [
59+
{ icon: 'github', link: 'https://github.com/unplugin' },
60+
],
61+
62+
footer: {
63+
message: 'Released under the MIT License.',
64+
copyright: 'Copyright (c) 2021-PRESENT UnJS Team',
65+
},
66+
},
67+
head: [
68+
['meta', { name: 'theme-color', content: '#ffffff' }],
69+
['link', { rel: 'icon', href: '/logo.svg', type: 'image/svg+xml' }],
70+
['meta', { name: 'author', content: 'Nuxt Contrib' }],
71+
['meta', { property: 'og:title', content: title }],
72+
['meta', { property: 'og:image', content: ogImage }],
73+
['meta', { property: 'og:description', content: description }],
74+
['meta', { name: 'twitter:card', content: 'summary_large_image' }],
75+
['meta', { name: 'twitter:image', content: ogImage }],
76+
['meta', { name: 'viewport', content: 'width=device-width, initial-scale=1.0, viewport-fit=cover' }],
77+
],
78+
markdown: {
79+
config: (md: any) => {
80+
md.use(MarkdownItGitHubAlerts)
81+
},
82+
codeTransformers: [
83+
transformerTwoslash(),
84+
],
85+
},
86+
ignoreDeadLinks: true,
87+
vite: vite as any,
88+
})

docs/.vitepress/constance.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const title = 'Unplugin'
2+
export const description = 'Unified plugin system. Support Vite, Rollup, webpack, esbuild, and every frameworks on top of them.'
3+
export const url = 'https://unplugin.vercel.app/'
4+
export const ogImage = `${url}/og.png`

docs/.vitepress/data/gen-files.ts

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import 'dotenv/config'
2+
import { writeFileSync } from 'node:fs'
3+
import { dirname, join } from 'node:path'
4+
import { fileURLToPath } from 'node:url'
5+
import { env } from 'node:process'
6+
import { $fetch } from 'ofetch'
7+
import { consola } from 'consola'
8+
import type { Repository } from './repository.data'
9+
import { repositoryMeta } from './meta'
10+
11+
const GITHUB_TOKEN = env.GITHUB_TOKEN
12+
13+
const gql = `#graphql
14+
query repositoryQuery($owner: String!, $name: String!, $readme: String!) {
15+
repository(owner: $owner, name: $name) {
16+
name
17+
stargazers {
18+
totalCount
19+
}
20+
owner {
21+
avatarUrl
22+
login
23+
}
24+
description
25+
primaryLanguage {
26+
name
27+
color
28+
}
29+
forkCount
30+
object(expression: $readme) {
31+
... on Blob {
32+
text
33+
}
34+
}
35+
}
36+
}`
37+
38+
async function fetchRepo(meta: {
39+
owner: string
40+
name: string
41+
readme?: string
42+
}) {
43+
const { owner, name, readme } = meta
44+
45+
const _readme = readme || 'main:README.md'
46+
try {
47+
const results = await $fetch('https://api.github.com/graphql', {
48+
method: 'POST',
49+
headers: {
50+
'Content-Type': 'application/json',
51+
'Authorization': `Bearer ${GITHUB_TOKEN}`,
52+
},
53+
body: JSON.stringify({
54+
query: gql,
55+
variables: {
56+
owner,
57+
name,
58+
readme: _readme,
59+
},
60+
}),
61+
})
62+
63+
const repositoryInfo = results.data.repository as Repository
64+
65+
const markdownFrontmatter = `---
66+
title: ${repositoryInfo.name}
67+
owner: ${repositoryInfo.owner.login}
68+
name: ${repositoryInfo.name}
69+
stars: ${repositoryInfo.stargazers.totalCount}
70+
forks: ${repositoryInfo.forkCount}
71+
outline: deep
72+
---
73+
74+
<RepoInfo :owner="$frontmatter.owner" :name="$frontmatter.name" :stars="$frontmatter.stars" :forks="$frontmatter.forks" />
75+
76+
---
77+
78+
`
79+
80+
writeFileSync(
81+
join(dirname(fileURLToPath(import.meta.url)), `../../showcase/${name}.md`),
82+
markdownFrontmatter + repositoryInfo.object.text,
83+
)
84+
consola.success(`[${name}.md]: generate success`)
85+
return repositoryInfo
86+
}
87+
catch (error) {
88+
consola.error(`[${name}.md]: generate failed: ${error}`)
89+
}
90+
}
91+
92+
function main() {
93+
if (!GITHUB_TOKEN) {
94+
consola.error('GITHUB_TOKEN is missing, please refer to https://github.com/unplugin/docs#development')
95+
return false
96+
}
97+
98+
const fetchs = repositoryMeta.map((repository) => {
99+
return fetchRepo({
100+
name: repository.name,
101+
owner: repository.owner,
102+
readme: repository.defaultBranch ? `${repository.defaultBranch}:README.md` : 'main:README.md',
103+
})
104+
})
105+
106+
Promise.allSettled(fetchs).then((res) => {
107+
const repoMeta = res?.map((item) => {
108+
if (item.status === 'fulfilled') {
109+
return {
110+
name: item.value?.name,
111+
stargazers: item.value?.stargazers,
112+
owner: item.value?.owner,
113+
description: item.value?.description,
114+
url: item.value?.url,
115+
isTemplate: item.value?.isTemplate,
116+
primaryLanguage: item.value?.primaryLanguage,
117+
forkCount: item.value?.forkCount,
118+
}
119+
}
120+
121+
return null
122+
})?.filter(item => item && item.name)
123+
124+
writeFileSync(
125+
join(dirname(fileURLToPath(import.meta.url)), './repository.json'),
126+
JSON.stringify(repoMeta, null, 2),
127+
)
128+
consola.success('[repository.json] generate success!')
129+
consola.success('All files generate done!')
130+
}).catch((error) => {
131+
consola.error(error)
132+
})
133+
}
134+
135+
main()

docs/.vitepress/data/meta.ts

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
export const repositoryMeta = [
2+
{
3+
owner: 'unplugin',
4+
name: 'unplugin-vue-components',
5+
},
6+
{
7+
owner: 'unplugin',
8+
name: 'unplugin-icons',
9+
},
10+
{
11+
owner: 'unplugin',
12+
name: 'unplugin-auto-import',
13+
},
14+
{
15+
owner: 'unplugin',
16+
name: 'unplugin-vue2-script-setup',
17+
},
18+
{
19+
owner: 'unplugin',
20+
name: 'unplugin-vue-markdown',
21+
},
22+
{
23+
owner: 'unplugin',
24+
name: 'unplugin-swc',
25+
},
26+
{
27+
owner: 'unplugin',
28+
name: 'unplugin-turbo-console',
29+
},
30+
{
31+
owner: 'unplugin',
32+
name: 'unplugin-imagemin',
33+
},
34+
{
35+
owner: 'unplugin',
36+
name: 'unplugin-vue-cssvars',
37+
defaultBranch: 'master',
38+
},
39+
{
40+
owner: 'unplugin',
41+
name: 'unplugin-vue',
42+
},
43+
{
44+
owner: 'unplugin',
45+
name: 'unplugin-macros',
46+
},
47+
{
48+
owner: 'unplugin',
49+
name: 'unplugin-vue-ce',
50+
defaultBranch: 'master',
51+
},
52+
]

0 commit comments

Comments
 (0)