docs(ComponentTheme): avoid using prettier to improve performances

This commit is contained in:
Benjamin Canac
2024-09-04 09:40:02 +02:00
parent 9f49796bd7
commit eb2667fa81

View File

@@ -4,7 +4,6 @@ import { camelCase } from 'scule'
import * as theme from '#build/ui' import * as theme from '#build/ui'
const route = useRoute() const route = useRoute()
const { $prettier } = useNuxtApp()
const name = camelCase(route.params.slug[route.params.slug.length - 1]) const name = camelCase(route.params.slug[route.params.slug.length - 1])
@@ -37,20 +36,18 @@ function stripCompoundVariants(component) {
} }
const component = computed(() => { const component = computed(() => {
const component = { ...theme[name] } return {
ui: {
return stripCompoundVariants(component) [name]: stripCompoundVariants(theme[name])
}
}
}) })
const { data: ast } = await useAsyncData(`component-theme-${name}`, async () => { const { data: ast } = await useAsyncData(`component-theme-${name}`, async () => {
const md = ` const md = `
::code-collapse ::code-collapse
\`\`\`ts [app.config.ts] \`\`\`ts [app.config.ts]
export default defineAppConfig({ export default defineAppConfig(${json5.stringify(component.value, null, 2).replace(/,([ |\t\n]+[}|\])])/g, '$1')})
ui: {
${name}: ${json5.stringify(component.value, null, 2)}
}
})
\`\`\`\ \`\`\`\
:: ::
@@ -63,18 +60,7 @@ Some colors in \`compoundVariants\` are omitted for readability. Check out the s
: ''} : ''}
` `
let formatted = '' return parseMarkdown(md)
try {
formatted = await $prettier.format(md, {
trailingComma: 'none',
semi: false,
singleQuote: true
})
} catch {
formatted = md
}
return parseMarkdown(formatted)
}) })
</script> </script>