-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ZTL-UwU <zhangtianli2006@163.com>
- Loading branch information
Showing
4 changed files
with
100 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<template> | ||
<MDC v-if="loadedCode" :value="md" class="[&:not(:first-child)]:mt-5" /> | ||
<UiAlert v-else variant="destructive"> | ||
<UiAlertTitle>Error</UiAlertTitle> | ||
<UiAlertDescription> | ||
Cannot load code: <ProseCodeInline>{{ file }}</ProseCodeInline> | ||
</UiAlertDescription> | ||
</UiAlert> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const { file, language, title, highlights, meta } = defineProps<{ | ||
file: string; | ||
language: string; | ||
title?: string; | ||
highlights?: string; | ||
meta?: string; | ||
}>(); | ||
const rawFiles = import.meta.glob(['@/**/*', '!@/**/nuxt.config.ts'], { | ||
query: '?raw', | ||
import: 'default', | ||
}); | ||
const importer = rawFiles[file]; | ||
const loadedCode = ref(''); | ||
if (importer) | ||
loadedCode.value = await importer() as string; | ||
const md = ` | ||
::div | ||
\`\`\`${language} ${title && `[${title}]`} ${highlights && `{${highlights}}`} ${meta} | ||
${loadedCode.value} | ||
\`\`\` | ||
:: | ||
`; | ||
</script> |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
title: Code Snippet | ||
icon: lucide:clipboard | ||
navBadges: | ||
- value: New | ||
type: lime | ||
badges: | ||
- value: 0.8.11 | ||
- value: Source | ||
icon: lucide:code | ||
to: https://github.com/ZTL-UwU/shadcn-docs-nuxt/blob/main/components/content/CodeSnippet.vue | ||
target: _blank | ||
--- | ||
|
||
## Usage | ||
|
||
::stack | ||
::div{class="p-4"} | ||
:code-snippet{file="/components/DarkModeToggle.vue" language="vue"} | ||
:: | ||
```mdc | ||
:code-snippet{file="/components/DarkModeToggle.vue" language="vue"} | ||
``` | ||
:: | ||
|
||
### Arguments | ||
|
||
::stack | ||
::div{class="p-4"} | ||
:code-snippet{file="/composables/useBreadcrumb.ts" language="ts" title="useBreadcrumb" highlights="9-11" meta="line-numbers height=300"} | ||
:: | ||
```mdc | ||
:code-snippet{file="/composables/useBreadcrumb.ts" language="ts" title="useBreadcrumb" highlights="9-11" meta="line-numbers height=300"} | ||
``` | ||
:: | ||
|
||
Translates to: | ||
|
||
````md | ||
```ts [useBreadcrumb] {9-11} line-numbers height=300 | ||
// code imported from /composables/useBreadcrumb.ts | ||
``` | ||
```` | ||
|
||
## Props | ||
|
||
::alert{icon="lucide:info"} | ||
The `/nuxt.config.ts` file can not be imported due to framework constraints | ||
:: | ||
|
||
::field-group | ||
:field{name="file" type="string"}[The path to the imported file] | ||
:field{name="title" type="string"}[Code block title] | ||
:field{name="language" type="string"}[Code block highlight language] | ||
:field{name="highlights" type="string"}[Code block highlights lines] | ||
:field{name="meta" type="string"}[Code block meta] | ||
:: |
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