Skip to content

Commit

Permalink
improve mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtsam committed Jan 30, 2025
1 parent bcce3b8 commit 22fcf3f
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 21 deletions.
6 changes: 6 additions & 0 deletions app/routes/_site+/blog_.$slug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ import {
GeneralErrorBoundary,
generalNotFoundHandler,
} from '#app/components/error-boundary.tsx'
import shikiStylesheet from '#app/styles/shiki.css?url'
import { posts as config } from '#app/utils/content/config.ts'
import { bundleMDX } from '#app/utils/content/mdx/bundler.server.ts'
import { getMdxSource } from '#app/utils/content/mdx/mdx.server.ts'
import { useMdxComponent } from '#app/utils/content/mdx/mdx.tsx'
import { retrieve, retrieveAll } from '#app/utils/content/retrieve.ts'
import { pipeHeaders } from '#app/utils/remix.server'
import { ServerTiming } from '#app/utils/timings.server'
import { type Route } from './+types/blog_.$slug'

export const links: Route.LinksFunction = () => [
{ rel: 'stylesheet', href: shikiStylesheet },
]

export const handle: SEOHandle = {
getSitemapEntries: serverOnly$(async () => {
Expand Down
9 changes: 9 additions & 0 deletions app/styles/shiki.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
html.dark .shiki,
html.dark .shiki span {
color: var(--shiki-dark) !important;
background-color: var(--shiki-dark-bg) !important;
/* Optional, if you also want font styles */
font-style: var(--shiki-dark-font-style) !important;
font-weight: var(--shiki-dark-font-weight) !important;
text-decoration: var(--shiki-dark-text-decoration) !important;
}
18 changes: 17 additions & 1 deletion app/utils/content/mdx/bundler.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { remember } from '@epic-web/remember'
import rehypeShiki from '@shikijs/rehype'
import { bundleMDX as _bundleMDX } from 'mdx-bundler'
import { type BundleMDX } from 'mdx-bundler/dist/types'
import PQueue from 'p-queue'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypeSlug from 'rehype-slug'
import { cachified, longLivedCache } from '#app/utils/cache.server.ts'
import { type ServerTiming } from '#app/utils/timings.server.ts'

Expand All @@ -16,7 +19,20 @@ async function bundleMDX({ source, files }: MdxSource) {
files,
mdxOptions(options) {
options.remarkPlugins = [...(options.remarkPlugins ?? [])]
options.rehypePlugins = [...(options.rehypePlugins ?? [])]
options.rehypePlugins = [
...(options.rehypePlugins ?? []),
[
rehypeShiki,
{
themes: {
light: 'catppuccin-latte',
dark: 'tokyo-night',
},
},
],
rehypeSlug,
[rehypeAutolinkHeadings, { behavior: 'wrap' }],
]
return options
},
})
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@sentry/react": "8.50.0",
"@sentry/remix": "8.47.0",
"@sentry/vite-plugin": "2.22.7",
"@shikijs/rehype": "2.2.0",
"@testing-library/dom": "10.4.0",
"@tusbar/cache-control": "1.0.2",
"address": "2.0.3",
Expand Down Expand Up @@ -88,6 +89,8 @@
"react-dom": "^19.0.0",
"react-router": "7.1.1",
"reading-time": "1.5.0",
"rehype-autolink-headings": "7.1.0",
"rehype-slug": "6.0.0",
"remix-auth": "4.1.0",
"remix-auth-discord": "1.4.1",
"remix-auth-github": "3.0.2",
Expand Down
Loading

0 comments on commit 22fcf3f

Please sign in to comment.