Skip to content

Commit

Permalink
feat: add api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Mar 23, 2024
1 parent d8204bc commit e11f73c
Show file tree
Hide file tree
Showing 21 changed files with 1,511 additions and 631 deletions.
2 changes: 1 addition & 1 deletion demo/custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"valaxy-theme-custom": "file:./valaxy-theme-custom"
},
"devDependencies": {
"typescript": "^5.4.2"
"typescript": "^5.4.3"
}
}
4 changes: 2 additions & 2 deletions demo/custom/valaxy-theme-custom/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "valaxy-theme-custom",
"version": "0.0.0",
"packageManager": "pnpm@8.15.4",
"packageManager": "pnpm@8.15.5",
"author": {
"email": "me@yunyoujun.cn",
"name": "YunYouJun",
Expand All @@ -22,6 +22,6 @@
"types": "types/index.d.ts",
"dependencies": {
"@iconify-json/ant-design": "^1.1.15",
"@iconify-json/simple-icons": "^1.1.94"
"@iconify-json/simple-icons": "^1.1.96"
}
}
6 changes: 6 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ public/feed.xml

# valaxy rss
public/feed.json

# api docs
pages/api

# valaxy fuse
public/valaxy-fuse-list.json
149 changes: 147 additions & 2 deletions docs/.valaxy/typed-router.d.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"valaxy-theme-press": "link:../packages/valaxy-theme-press"
},
"devDependencies": {
"@iconify-json/simple-icons": "^1.1.94",
"@iconify-json/simple-icons": "^1.1.96",
"nodemon": "^3.1.0",
"vite": "^5.1.5",
"vite": "^5.2.4",
"vitepress": "1.0.0-rc.45"
}
}
6 changes: 0 additions & 6 deletions docs/pages/api/addon.md

This file was deleted.

33 changes: 0 additions & 33 deletions docs/pages/api/index.md

This file was deleted.

8 changes: 0 additions & 8 deletions docs/pages/api/theme.md

This file was deleted.

28 changes: 28 additions & 0 deletions docs/pages/themes/write.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,34 @@ export interface ValaxyConfig {

:::

### Client

#### Toggle Dark

- `isDark`: Whether dark mode is enabled
- `toggleDark`: Toggle dark mode
- `toggleDarkWithTransition`: Toggle dark mode with transition

Example:

```vue
<script lang="ts" setup>
import { isDark, toggleDarkWithTransition } from 'valaxy'
</script>
<template>
<button class="yun-icon-btn" @click="toggleDarkWithTransition">
<div i="ri-sun-line dark:ri-moon-line" />
</button>
</template>
```

### Node

#### Hooks

- [钩子](/guide/custom/hooks.md)

## 开始编写

### App.vue
Expand Down
19 changes: 19 additions & 0 deletions docs/pages/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://typedoc.org/schema.json",
"entryPoints": [
"../../packages/valaxy/client",
"../../packages/valaxy/node"
],
"plugin": [
"typedoc-plugin-markdown",
"typedoc-vitepress-theme"
],
"out": "./api",
"docsRoot": ".",
"githubPages": false,
"excludePrivate": true,
"excludeProtected": true,
"excludeInternal": true,
"readme": "none",
"includes": "../../packages/valaxy"
}
44 changes: 30 additions & 14 deletions docs/valaxy.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineValaxyConfig } from 'valaxy'
import type { PressTheme } from 'valaxy-theme-press'
import { addonAlgolia } from 'valaxy-addon-algolia'
import { addonComponents } from 'valaxy-addon-components'
import typedocSidebar from './pages/api/typedoc-sidebar.json'

const COMMIT_ID = process.env.CF_PAGES_COMMIT_SHA || process.env.COMMIT_REF
const commitRef = COMMIT_ID?.slice(0, 8) || 'dev'
Expand All @@ -13,6 +14,30 @@ const safelist = [
'i-ri-github-line',
]

export function getTypeDocSidebar() {
// replace .md to ''
function replaceMd(str: string) {
if (str.endsWith('/index.md'))
return str.slice(0, -9)
if (str.endsWith('.md'))
return str.slice(0, -3)
}

function formatSidebar(sidebar: PressTheme.SidebarItem[]): PressTheme.SidebarItem[] {
return sidebar.map((item) => {
if (item.link)
item.link = replaceMd(item.link)

if (item.items)
item.items = formatSidebar(item.items)

return item
})
}

return formatSidebar(typedocSidebar as PressTheme.SidebarItem[])
}

export default defineValaxyConfig<PressTheme.Config>({
siteConfig: {
title: 'Valaxy',
Expand Down Expand Up @@ -69,6 +94,10 @@ export default defineValaxyConfig<PressTheme.Config>({
'theme',
'addon',
'dev',
{
text: 'API',
items: getTypeDocSidebar(),
},
],
socialLinks: [
{ icon: 'i-ri-github-line', link: 'https://github.com/YunYouJun/valaxy' },
Expand All @@ -89,20 +118,7 @@ export default defineValaxyConfig<PressTheme.Config>({
},
{
text: 'API',
items: [
{
text: 'Core',
link: '/api/',
},
{
text: 'Theme',
link: '/api/theme',
},
{
text: 'Addon',
link: '/api/addon',
},
],
link: '/api/',
},
{
text: 'nav.theme',
Expand Down
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"version": "0.18.5",
"private": true,
"packageManager": "pnpm@8.15.4",
"packageManager": "pnpm@8.15.5",
"description": "📄 Vite & Vue powered static blog generator.",
"author": {
"email": "me@yunyoujun.cn",
Expand Down Expand Up @@ -40,9 +40,10 @@
"dev:lib": "pnpm -C packages/valaxy run dev",
"dev": "pnpm -r --filter=./packages/** --parallel run dev",
"devtools": "pnpm -C packages/devtools run dev",
"predocs": "typedoc --options docs/pages/typedoc.json",
"docs": "pnpm -C docs run dev",
"docs:dev": "pnpm -C docs run dev",
"docs:build": "pnpm -C docs run build",
"docs:build": "npm run predocs && pnpm -C docs run build",
"docs:serve": "pnpm -C docs run serve",
"docs:vitepress": "pnpm -C docs run vitepress:dev",
"e2e": "playwright test",
Expand Down Expand Up @@ -76,13 +77,13 @@
"@antfu/eslint-config": "2.8.0",
"@iconify-json/logos": "^1.1.42",
"@iconify-json/vscode-icons": "^1.1.33",
"@microsoft/api-extractor": "^7.42.3",
"@microsoft/api-extractor": "^7.43.0",
"@playwright/test": "^1.42.1",
"@types/debug": "^4.1.12",
"@types/markdown-it-attrs": "^4.1.3",
"@types/markdown-it-container": "^2.0.9",
"@types/markdown-it-emoji": "^2.0.4",
"@types/node": "^20.11.25",
"@types/node": "^20.11.30",
"@types/prompts": "^2.4.9",
"@types/resolve": "^1.20.6",
"bumpp": "^9.4.0",
Expand All @@ -99,9 +100,12 @@
"stylelint-config-standard-scss": "^13.0.0",
"tsup": "^8.0.2",
"tsx": "^4.7.1",
"typescript": "^5.4.2",
"typedoc": "^0.25.12",
"typedoc-plugin-markdown": "4.0.0-next.23",
"typedoc-vitepress-theme": "1.0.0-next.3",
"typescript": "^5.4.3",
"unbuild": "^2.0.0",
"vitest": "^1.3.1",
"vitest": "^1.4.0",
"vue-tsc": "2.0.6",
"zx": "^7.2.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-valaxy/template-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"valaxy-theme-yun": "0.18.5"
},
"devDependencies": {
"typescript": "^5.4.2"
"typescript": "^5.4.3"
}
}
8 changes: 4 additions & 4 deletions packages/devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@rollup/pluginutils": "^5.1.0",
"axios": "^1.6.7",
"axios": "^1.6.8",
"body-parser": "^1.20.2",
"http-proxy-middleware": "^2.0.6",
"picocolors": "^1.0.0",
Expand All @@ -42,9 +42,9 @@
"@types/splitpanes": "^2.2.6",
"gray-matter": "^4.0.3",
"splitpanes": "^3.1.5",
"typescript": "^5.4.2",
"typescript": "^5.4.3",
"unbuild": "^2.0.0",
"unplugin-vue-router": "^0.8.4",
"vite": "^5.1.5"
"unplugin-vue-router": "^0.8.5",
"vite": "^5.2.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const htmlText = computed(() => t(props.item.text || ''))
<component :is="textTag" v-else class="text ml-1" v-html="htmlText" />

<button
v-if="item.collapsed != null"
v-if="item.collapsed != null && item.items"
tabindex="0" role="button" aria-label="toggle section"
class="caret folder-action inline-flex cursor-pointer"
@click="onCaretClick" @keydown.enter="onCaretClick"
Expand Down
2 changes: 1 addition & 1 deletion packages/valaxy-theme-yun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@explosions/fireworks": "^0.0.2",
"@iconify-json/ant-design": "^1.1.15",
"@iconify-json/simple-icons": "^1.1.94",
"@iconify-json/simple-icons": "^1.1.96",
"animejs": "^3.2.2"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/valaxy/node/plugins/markdown/markdownToVue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export async function createMarkdownToVueRenderFn(
): Promise<MarkdownCompileResult> => {
const file = id
const relativePath = path.relative(srcDir, file)
// do not await, depend options.env
const deadLinks = scanDeadLinks(code, id)

// only in build
const cacheKey = JSON.stringify({ code, id })
Expand Down Expand Up @@ -113,7 +115,6 @@ export async function createMarkdownToVueRenderFn(
// run it before vue and after md parse
code = await transformEncrypt(code, id, pageData)

const deadLinks = scanDeadLinks(code, id)
code = transformMarkdown(code, id, pageData)

debug(`[render] ${file} in ${Date.now() - start}ms.`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { EXTERNAL_URL_RE } from '../../../constants'
import { treatAsHtml } from '../utils'

export function createScanDeadLinks(options: ResolvedValaxyOptions) {
const srcDir = options.userRoot
const srcDir = path.resolve(options.userRoot, 'pages')
const { ignoreDeadLinks } = options.config
const publicDir = options.config.vite?.publicDir || 'public'

Expand Down

1 comment on commit e11f73c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://yun.valaxy.site as production
🚀 Deployed on https://65fef7aefb849b18fcc1279b--valaxy.netlify.app

Please sign in to comment.