feat(docs): migrate to vitepress with @unovue/reka-ui's theme (#224)
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { promises as fs } from 'node:fs'
|
||||
|
||||
interface Contributor {
|
||||
login: string
|
||||
}
|
||||
|
||||
async function fetchContributors(page = 1) {
|
||||
const collaborators: string[] = []
|
||||
|
||||
const res = await fetch(`https://api.github.com/repos/moeru-ai/airi/contributors?per_page=100&page=${page}`, {
|
||||
headers: {
|
||||
Accept: 'application/vnd.github+json',
|
||||
},
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
console.error(`Failed to fetch contributors page #${page}: ${res.status} ${res.statusText} ${await res.text()}`)
|
||||
return []
|
||||
}
|
||||
|
||||
const data: Contributor[] = await res.json()
|
||||
|
||||
collaborators.push(...data.map(contributor => contributor.login))
|
||||
if (res.headers.get('Link')?.includes('rel=\"next\"'))
|
||||
collaborators.push(...(await fetchContributors(page + 1)))
|
||||
return collaborators.filter(name => !name.includes('[bot]'))
|
||||
}
|
||||
|
||||
async function generate() {
|
||||
const collaborators = await fetchContributors()
|
||||
await fs.writeFile('.vitepress/contributor-names.json', `${JSON.stringify(collaborators, null, 2)}\n`, 'utf8')
|
||||
}
|
||||
|
||||
generate()
|
||||
@@ -0,0 +1,28 @@
|
||||
import type MarkdownIt from 'markdown-it'
|
||||
|
||||
// Define a custom plugin to transform JSDoc @link tags
|
||||
export function transformJSDocLinks(md: MarkdownIt) {
|
||||
md.core.ruler.push('transform-jsdoc-links', (state) => {
|
||||
state.tokens.forEach((token) => {
|
||||
if (token.type === 'inline' && token.children?.length) {
|
||||
for (let i = 0; i < token.children.length; i++) {
|
||||
const child = token.children[i]
|
||||
if (child.type === 'text' && child.content.startsWith('{@link')) {
|
||||
// eslint-disable-next-line regexp/no-super-linear-backtracking
|
||||
const matches = child.content.match(/\{@link\s+(.*?)\}/)
|
||||
if (matches) {
|
||||
const linkText = matches[1]
|
||||
const linkNode = new state.Token('link_open', 'a', 1)
|
||||
linkNode.attrSet('href', linkText)
|
||||
linkNode.attrSet('target', '_blank')
|
||||
const textNode = new state.Token('text', '', 0)
|
||||
textNode.content = 'reference'
|
||||
token.children.splice(i, 1, linkNode, textNode, new state.Token('link_close', 'a', -1))
|
||||
i += 2 // Skip the added link and text tokens
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user