Skip to content

Commit

Permalink
wip: restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Oct 22, 2023
1 parent c95f0d6 commit aba71fe
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 55 deletions.
53 changes: 53 additions & 0 deletions src/vite/plugins/mdx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import rehypePrettyCode from '@jmoxey/rehype-pretty-code'
import mdxPlugin from '@mdx-js/rollup'
import remarkDirective from 'remark-directive'
import remarkFrontmatter from 'remark-frontmatter'
import remarkGfm from 'remark-gfm'
import remarkMdxFrontmatter from 'remark-mdx-frontmatter'
import {
createDiffProcessor,
createFocusProcessor,
createHighlightProcessor,
getHighlighter,
} from 'shiki-processor'
import type { PluginOption } from 'vite'

import { remarkCallout } from './remark/callout.js'
import { remarkCodeGroup } from './remark/code-group.js'
import { remarkSubheading } from './remark/subheading.js'

export function mdx(): PluginOption {
return mdxPlugin({
remarkPlugins: [
remarkDirective,
remarkFrontmatter,
remarkMdxFrontmatter,
remarkGfm,
remarkCallout,
remarkCodeGroup,
remarkSubheading,
],
rehypePlugins: [
[
rehypePrettyCode as any,
{
keepBackground: false,
getHighlighter(options: any) {
return getHighlighter({
...options,
processors: [
createDiffProcessor(),
createFocusProcessor(),
createHighlightProcessor(),
],
})
},
theme: {
dark: 'github-dark-dimmed',
light: 'github-light',
},
},
],
],
})
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions src/vite/plugins/routes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { resolve } from 'node:path'
import { globby } from 'globby'
import type { PluginOption } from 'vite'

type RoutesParameters = { paths: string }
type RoutesParameters = { paths?: string }

export function routes({ paths: glob }: RoutesParameters): PluginOption {
export function routes({
paths: glob = resolve(process.cwd(), './pages/**/*.{md,mdx,ts,tsx,js,jsx}'),
}: RoutesParameters = {}): PluginOption {
const virtualModuleId = 'virtual:routes'
const resolvedVirtualModuleId = `\0${virtualModuleId}`

Expand Down
55 changes: 2 additions & 53 deletions src/vite/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
import { resolve } from 'node:path'
import rehypePrettyCode from '@jmoxey/rehype-pretty-code'
import mdx from '@mdx-js/rollup'
import react from '@vitejs/plugin-react'
import * as autoprefixer from 'autoprefixer'
import remarkDirective from 'remark-directive'
import remarkFrontmatter from 'remark-frontmatter'
import remarkGfm from 'remark-gfm'
import remarkMdxFrontmatter from 'remark-mdx-frontmatter'
import {
createDiffProcessor,
createFocusProcessor,
createHighlightProcessor,
getHighlighter,
} from 'shiki-processor'
import { defineConfig } from 'vite'

import { mdx } from './plugins/mdx.js'
import { routes } from './plugins/routes.js'
import { remarkCallout } from './remark/callout.js'
import { remarkCodeGroup } from './remark/code-group.js'
import { remarkSubheading } from './remark/subheading.js'

export default defineConfig({
css: {
Expand All @@ -31,41 +16,5 @@ export default defineConfig({
allow: ['..'],
},
},
plugins: [
react(),
mdx({
remarkPlugins: [
remarkDirective,
remarkFrontmatter,
remarkMdxFrontmatter,
remarkGfm,
remarkCallout,
remarkCodeGroup,
remarkSubheading,
],
rehypePlugins: [
[
rehypePrettyCode as any,
{
keepBackground: false,
getHighlighter(options: any) {
return getHighlighter({
...options,
processors: [
createDiffProcessor(),
createFocusProcessor(),
createHighlightProcessor(),
],
})
},
theme: {
dark: 'github-dark-dimmed',
light: 'github-light',
},
},
],
],
}),
routes({ paths: resolve(process.cwd(), './pages/**/*.{md,mdx,ts,tsx,js,jsx}') }),
],
plugins: [react(), mdx(), routes()],
})

0 comments on commit aba71fe

Please sign in to comment.