Skip to content

Commit

Permalink
trying a different view
Browse files Browse the repository at this point in the history
  • Loading branch information
elevatebart committed Aug 28, 2023
1 parent 6424ac7 commit f9b5f5d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
6 changes: 3 additions & 3 deletions docs/docgen/docgen.config.react.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const tsconfigPath = path.resolve(
__dirname,
'..',
'..',
'./tsconfig.react.json'
'./tsconfig.react.json',
)
const parser = withCustomConfig(tsconfigPath, {
shouldRemoveUndefinedFromOptional: true,
Expand All @@ -33,15 +33,15 @@ function getTags(tags) {
acc[k] = [{ title: k, content: v }]
return acc
},
{}
{},
)
}

module.exports = defineConfig({
components: './*/react/[A-Z]*.tsx',
getDestFile: (componentPath, { outDir }) => {
const name = componentPath.split('/').pop() || 'unknown'
return path.join(outDir, 'react', name.replace(/\.(tsx|ts)$/, '.md'))
return path.join(outDir, name.replace(/\.(tsx|ts)$/, ''), '/react.md')
},
propsParser(componentPath) {
const props = parser.parse(componentPath)
Expand Down
10 changes: 6 additions & 4 deletions docs/docgen/docgen.config.vue.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = defineConfig({
components: './*/vue/[A-Z]*.{vue,ts}',
getDestFile: (componentPath, { outDir }) => {
const name = componentPath.split('/').pop() || 'unknown'
return path.join(outDir, 'vue', name.replace(/\.(vue|ts)$/, '.md'))
return path.join(outDir, name.replace(/\.(vue|ts)$/, ''), '/vue.md')
},
propsParser: async function (componentPath, _, event) {
if (event === 'add') {
Expand Down Expand Up @@ -49,7 +49,9 @@ module.exports = defineConfig({

const events = meta.events.length
? meta.events.map((e) => {
const event = docgen.events.find((d) => d.name === e.name) ?? {}
const event = docgen?.events?.find((d) => d.name === e.name) ?? {
properties: [],
}

const typeArray =
e.type === 'any[]' ? [] : e.type.slice(1, -1).split(',')
Expand All @@ -58,7 +60,7 @@ module.exports = defineConfig({
properties: e.schema.map((s, i) => {
const name = typeArray[i]?.split(':')[0].trim()
const propDef = event.properties?.find(
(p) => p.name === name
(p) => p.name === name,
) ?? { name }

return {
Expand All @@ -72,7 +74,7 @@ module.exports = defineConfig({

const slots = meta.slots.length
? meta.slots.map(({ name, schema }) => {
const slot = docgen.slots.find((d) => d.name === name) ?? { name }
const slot = docgen?.slots?.find((d) => d.name === name) ?? { name }
return {
...slot,
bindings: extractBindings(schema, slot?.bindings),
Expand Down
13 changes: 12 additions & 1 deletion docs/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './assets/theme.css'
import './assets/markdown.scss'
import './assets/fonts/fonts.css'
import { ViteSSG } from 'vite-ssg'
import { ref } from 'vue'
import { setupLayouts } from 'virtual:generated-layouts'
import Tooltip from '@cypress-design/vue-tooltip'

Expand All @@ -10,7 +11,17 @@ import VueLiveWithLayout from './components/vue-live/vue-live.vue'
import DemoWrapper from './components/DemoWrapper.vue'
import generatedRoutes from '~pages'

const routes = setupLayouts(generatedRoutes)
const routesRaw = setupLayouts(generatedRoutes)
import { getDocsPages } from './utils/docsPages'

const { routeMap } = getDocsPages(ref(''))

const routes = routesRaw.map((route) => {
if (routeMap[route.path]) {
route.path = routeMap[route.path]
}
return route
})

// https://github.com/antfu/vite-ssg
export const createApp = ViteSSG(
Expand Down
5 changes: 3 additions & 2 deletions docs/src/utils/docsPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function getDocsPages(routePath: Ref<string>) {
const serverRoute = p
.replace(/^\.\.\/\.\.\/\.\./, '')
.replace(/\/(\w+)\/ReadMe.md$/, '/$1.md')
.toLowerCase()

const clientRoute = serverRoute.replace(/\.md$/, '')

Expand All @@ -26,7 +27,7 @@ export function getDocsPages(routePath: Ref<string>) {
)

const routeMap = Object.keys(docsPages).reduce((acc, p) => {
const serverRoute = p.replace(/^\.\.\/pages/, '')
const serverRoute = p.replace(/^\.\.\/pages/, '').toLowerCase()

const clientRoute = serverRoute
.replace(/\.md$/, '')
Expand Down Expand Up @@ -55,5 +56,5 @@ export function getDocsPages(routePath: Ref<string>) {
}
}),
)
return { items, routeMap, routeMapComponent }
return { items, routeMap }
}
1 change: 0 additions & 1 deletion docs/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default defineConfig({
// https://github.com/antfu/vite-plugin-vue-markdown
// Don't need this? Try vitesse-lite: https://github.com/antfu/vitesse-lite
Markdown({
wrapperClasses: 'prose prose-sm m-auto text-left',
headEnabled: true,
markdownItSetup(md) {
// https://prismjs.com/
Expand Down

0 comments on commit f9b5f5d

Please sign in to comment.