Skip to content

Commit 86ea101

Browse files
ZTL-UwUijkml
authored andcommitted
docs: fix code snippet
Signed-off-by: ZTL-UwU <[email protected]>
1 parent 6b53d67 commit 86ea101

File tree

7 files changed

+1098
-696
lines changed

7 files changed

+1098
-696
lines changed

Diff for: .github/workflows/nuxthub.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on: push
33

44
jobs:
55
deploy:
6-
name: "Deploy to NuxtHub"
6+
name: Deploy to NuxtHub
77
runs-on: ubuntu-latest
88
environment:
99
name: ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
@@ -22,7 +22,7 @@ jobs:
2222
uses: actions/setup-node@v4
2323
with:
2424
node-version: 22
25-
cache: 'pnpm'
25+
cache: pnpm
2626

2727
- name: Install dependencies
2828
run: pnpm install

Diff for: .vscode/extensions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"antfu.goto-alias",
66
"csstools.postcss",
77
"dbaeumer.vscode-eslint",
8-
"vue.volar",
8+
"vue.volar"
99
]
1010
}

Diff for: .vscode/settings.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"node_modules": true,
1717
".unlighthouse": true,
1818
".output": true,
19-
"dist": true,
20-
},
19+
"dist": true
20+
}
2121
}

Diff for: assets/css/tailwind.css

+9-3
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,25 @@
8787
}
8888

8989
html {
90-
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
90+
font-family:
91+
Inter,
92+
ui-sans-serif,
93+
system-ui,
94+
-apple-system,
95+
BlinkMacSystemFont,
96+
sans-serif;
9197
/* @apply text-balance text-pretty; */
9298
}
9399

94100
body {
95101
@apply bg-background text-foreground;
96102
}
97103

98-
footer>div {
104+
footer > div {
99105
@apply flex !flex-row;
100106
}
101107

102-
.hero-card-group .iconify[class*="i-ph"] {
108+
.hero-card-group .iconify[class*='i-ph'] {
103109
@apply text-primary;
104110
}
105111

Diff for: components/content/CodeSnippet.vue

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<script setup lang="ts">
2+
const { file, url, language, title, highlights, meta, start, offset } = defineProps<{
3+
file?: string;
4+
url?: string;
5+
language: string;
6+
title?: string;
7+
highlights?: string;
8+
meta?: string;
9+
start?: number;
10+
offset?: number;
11+
}>();
12+
13+
const loadedCode = ref('');
14+
15+
const rawFiles = import.meta.glob([
16+
// Path you want to import
17+
], {
18+
query: '?raw',
19+
import: 'default',
20+
});
21+
22+
if (file) {
23+
const importer = rawFiles[file];
24+
if (importer) {
25+
loadedCode.value = (await importer()) as string;
26+
}
27+
}
28+
else if (url) {
29+
try {
30+
const data = await $fetch(url, { parseResponse: txt => txt });
31+
if (data) {
32+
loadedCode.value = data as string;
33+
}
34+
}
35+
catch {}
36+
}
37+
38+
if (loadedCode.value && start && offset) {
39+
const lines = loadedCode.value.split('\n');
40+
loadedCode.value = lines.slice(Number(start || 1) - 1, Number(start || 1) - 1 + Number(offset)).join('\n');
41+
}
42+
43+
const md = `
44+
::div
45+
\`\`\`\`${language} ${title && `[${title}]`} ${highlights && `{${highlights}}`} ${meta || ''}
46+
${loadedCode.value}
47+
\`\`\`\`
48+
::
49+
`;
50+
</script>
51+
52+
<template>
53+
<ClientOnly>
54+
<MDC v-if="loadedCode" :value="md" class="[&:not(:first-child)]:mt-5" />
55+
<UiAlert v-else variant="destructive">
56+
<UiAlertTitle>Error</UiAlertTitle>
57+
<UiAlertDescription>
58+
Cannot load code: <ProseCodeInline>{{ file || url }}</ProseCodeInline>
59+
</UiAlertDescription>
60+
</UiAlert>
61+
</ClientOnly>
62+
</template>

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"@iconify-json/ph": "^1.2.2",
1717
"nuxt": "^3.15.4",
1818
"nuxt-umami": "^3.2.0",
19-
"shadcn-docs-nuxt": "^0.8.16",
19+
"shadcn-docs-nuxt": "^0.8.19",
2020
"vue": "^3.5.13"
2121
},
2222
"devDependencies": {
23-
"@antfu/eslint-config": "^4.3.0",
23+
"@antfu/eslint-config": "^4.4.0",
2424
"@nuxt/icon": "^1.10.3",
2525
"eslint": "^9.21.0",
2626
"eslint-plugin-format": "^1.0.1"

0 commit comments

Comments
 (0)