Skip to content

Commit

Permalink
simplify docs config
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostrider-05 committed Oct 25, 2024
1 parent 274309f commit f65d3fb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 38 deletions.
64 changes: 31 additions & 33 deletions docs/.vitepress/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,15 @@ import {

const repoUrl = repository.url.replace('.git', ''), branch = 'main'

// eslint-disable-next-line jsdoc/require-jsdoc
function createOverview(isSidebar: boolean) {
return [
shared.createGuideItem(isSidebar),
isSidebar
? shared.createAppsItem()
: { text: 'API', link: '/api/index.html', activeMatch: '/api/' },
shared.createLinksItem({
branch,
bugsUrl: bugs.url,
repoUrl,
version,
}),
...(!isSidebar ? [
{
component: 'GitHubStat',
props: {
label: 'GitHub stars',
iconClass: 'vpi-social-github',
repo: 'ghostrider-05/patreon-api.ts',
keyName: 'stargazers_count',
},
} as DefaultTheme.NavItemComponent
] : []),
]
}

const createNavItems = () => createOverview(false) as DefaultTheme.NavItem[]
const createSidebarItems = () => createOverview(true) as DefaultTheme.SidebarItem[]
const createSidebarItems = () => [
shared.createGuideItem(true),
shared.createLinksItem({
branch,
bugsUrl: bugs.url,
repoUrl,
version,
}),
] as DefaultTheme.SidebarItem[]

export default defineConfig({
title: name,
Expand All @@ -62,7 +42,25 @@ export default defineConfig({
},

themeConfig: {
nav: createNavItems(),
nav: [
shared.createGuideItem(false),
{ text: 'API', link: '/api/index.html', activeMatch: '/api/' },
shared.createLinksItem({
branch,
bugsUrl: bugs.url,
repoUrl,
version,
}),
{
component: 'GitHubStat',
props: {
label: 'GitHub stars',
iconClass: 'vpi-social-github',
repo: 'ghostrider-05/patreon-api.ts',
keyName: 'stargazers_count',
},
},
] as DefaultTheme.NavItem[],
sidebar: {
'/guide/': createSidebarItems(),
'/apps/': createSidebarItems(),
Expand All @@ -80,7 +78,7 @@ export default defineConfig({
link: '/api/',
},
...useSidebar({
spec: await fetchOpenAPISchema(openAPIUrlV2),
spec: await fetchOpenAPISchema(),
linkPrefix: '/api/',
}).generateSidebarGroups(),
]
Expand All @@ -91,13 +89,13 @@ export default defineConfig({
externalLinkIcon: true,
editLink: {
text: 'Edit this page on GitHub',
pattern: `${repoUrl}/edit/main/docs/:path`,
pattern: `${repoUrl}/edit/${branch}/docs/:path`,
},
socialLinks: [
{
icon: 'github',
link: repoUrl,
}
},
],

outline: 'deep',
Expand Down
4 changes: 2 additions & 2 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { theme, useOpenapi } from 'vitepress-openapi'
// @ts-expect-error Style import
import 'vitepress-openapi/dist/style.css'

import { fetchOpenAPISchema, openAPIUrlV2 } from './openapi'
import { fetchOpenAPISchema } from './openapi'
import Layout from './Layout.vue'
// @ts-expect-error Style import
import './style.css'
Expand All @@ -25,7 +25,7 @@ export default {
DefaultTheme.enhanceApp(ctx)
ctx.app.use(createVuetify())

const spec = await fetchOpenAPISchema(openAPIUrlV2)
const spec = await fetchOpenAPISchema()

// @ts-expect-error Unused variable
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
19 changes: 16 additions & 3 deletions docs/.vitepress/theme/openapi.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import { exec } from 'node:child_process'

// eslint-disable-next-line jsdoc/require-jsdoc
export async function fetchOpenAPISchema (url: string) {
export async function fetchOpenAPISchema () {
return await fetch('https://patreon-docs.ghostrider.workers.dev/proxy', {
method: 'POST',
body: JSON.stringify({
method: 'GET',
url,
url: openAPIUrlV2,
headers: {
'Content-Type': 'application/json',
},
}),
}).then(res => res.json())
}

export const openAPIUrlV2 = 'https://raw.githubusercontent.com/ghostrider-05/patreon-api.ts/refs/heads/openapi-schema/src/schemas/v2/generated/openapi.json'
const getBranch = () => new Promise<string>((resolve, reject) => {
return exec('git rev-parse --abbrev-ref HEAD', (err, stdout) => {
if (err)
reject(`getBranch Error: ${err}`)
else if (typeof stdout === 'string')
resolve(stdout.trim())
})
})

export const currentBranch = await getBranch()

export const openAPIUrlV2 = `https://raw.githubusercontent.com/ghostrider-05/patreon-api.ts/refs/heads/${currentBranch}/src/schemas/v2/generated/openapi.json`
5 changes: 5 additions & 0 deletions docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "Bundler"
},
"include": [
".vitepress/**/*.ts",
],
Expand Down

0 comments on commit f65d3fb

Please sign in to comment.