-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Use Oniguruma only on browsers
- Loading branch information
Showing
3 changed files
with
32 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,40 @@ | ||
import { error } from '@sveltejs/kit'; | ||
import type { Component } from 'svelte'; | ||
|
||
import { | ||
createHighlighterCoreSync, | ||
createOnigurumaEngine, | ||
createJavaScriptRegexEngine, | ||
type HighlighterCore | ||
} from 'shiki'; | ||
import svelte from 'shiki/langs/svelte.mjs'; | ||
import dark from 'shiki/themes/github-dark-default.mjs'; | ||
import { browser } from '$app/environment'; | ||
|
||
export const load = async ({ params }) => { | ||
const { slug } = params; | ||
|
||
const shiki = createHighlighterCoreSync({ | ||
themes: [dark], | ||
langs: [svelte], | ||
// Use the WASM version of Oniguruma on the browser, and the JS engine on the server | ||
engine: browser ? await createOnigurumaEngine(import('shiki/wasm')) : createJavaScriptRegexEngine() | ||
}); | ||
|
||
try { | ||
const post = (await import(`$content/components/${slug}/content.svelte.md`)) as { | ||
default: Component; | ||
const post = (await import(`$content/examples/${slug}/content.svelte.md`)) as { | ||
default: Component<{ shiki: HighlighterCore }>; | ||
metadata: { | ||
title: string; | ||
description: string; | ||
}; | ||
}; | ||
return { | ||
Content: post.default, | ||
meta: { ...post.metadata, slug } | ||
meta: { ...post.metadata, slug }, | ||
shiki | ||
}; | ||
} catch { | ||
error(404, `Component '${slug}' not found`); | ||
error(404, `Example '${slug}' not found`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters