Skip to content

Commit d9c0f90

Browse files
committed
chore: improves code snippets on home page
1 parent 9d0ea9f commit d9c0f90

6 files changed

Lines changed: 81 additions & 113 deletions

File tree

.vitepress/theme/components/Hero/CodePreview.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ const copyToClipboard = async () => {
4747
<img v-if="copyText === 'Copy'" src="/svg/heroicons-outline-document-duplicate.svg" alt="Copy" class="code-preview__copy-icon">
4848
<img v-else src="/svg/heroicons-outline-check.svg" alt="Copied" class="code-preview__copy-icon">
4949
</button>
50-
<div v-if="$slots.default && preformatted" class="code-preview__block">
51-
<slot></slot>
50+
<div style="margin-top: -16px; margin-bottom: -16px" v-if="$slots.default && preformatted" class="code-preview__block">
51+
<slot "></slot>
5252
</div>
5353
<pre class="code-preview__block" v-else><code><slot></slot>{{ value }}</code></pre>
5454
</div>

.vitepress/theme/components/Hero/Hero.vue

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,62 @@
11
<script setup>
2-
import PlatformCodePreview from "./PlatformCodePreview.vue";
32
import CodePreview from "./CodePreview.vue";
3+
import { createHighlighter } from 'shiki';
4+
import { onMounted, ref } from "vue";
5+
import axios from "axios";
6+
7+
const grammarUrl = "https://raw.githubusercontent.com/stjude-rust-labs/sprocket-vscode/refs/heads/main/syntaxes/wdl.tmGrammar.json";
8+
const installCode = ref(null);
9+
const wdlCode = ref(null);
10+
const runCode = ref(null);
11+
12+
onMounted(async () => {
13+
const wdl = await axios.get(grammarUrl);
14+
15+
const highlighter= await createHighlighter({
16+
themes: ["github-dark"],
17+
langs: ["bash", wdl.data]
18+
});
19+
20+
installCode.value = await highlighter.codeToHtml("cargo install sprocket --locked", {
21+
lang: "bash",
22+
theme: "github-dark",
23+
colorReplacements: {
24+
"#24292e": "none"
25+
}
26+
});
27+
28+
const wdlCodeText = `version 1.2
29+
30+
workflow count_lines {
31+
input { File input_file }
32+
call Count { input: file = input_file }
33+
output { Int num_lines = Count.num_lines }
34+
}
35+
36+
task Count {
37+
input { File file }
38+
command { wc -l \${file} | awk '{print $1}' }
39+
output { Int num_lines = read_int(stdout()) }
40+
}`;
41+
42+
wdlCode.value = await highlighter.codeToHtml(wdlCodeText, {
43+
lang: "wdl",
44+
theme: "github-dark",
45+
colorReplacements: {
46+
"#24292e": "none"
47+
}
48+
});
49+
50+
runCode.value = await highlighter.codeToHtml("sprocket run example.wdl", {
51+
lang: "bash",
52+
theme: "github-dark",
53+
colorReplacements: {
54+
"#24292e": "none"
55+
}
56+
});
57+
58+
});
59+
460
</script>
561

662
<template>
@@ -31,25 +87,25 @@ import CodePreview from "./CodePreview.vue";
3187
<!-- Right: Code Cards -->
3288
<section class="hero__right-column">
3389
<!-- Card 1: Install -->
34-
<PlatformCodePreview
35-
windows-command="cargo install sprocket"
36-
mac-command="cargo install sprocket"
37-
unix-command="cargo install sprocket"
38-
/>
90+
<div class="card" v-if="installCode != null">
91+
<CodePreview header="bash" preformatted>
92+
<div v-html="installCode"></div>
93+
</CodePreview>
94+
</div>
3995

4096
<!-- Card 2: WDL Example -->
41-
<div class="card">
42-
<CodePreview header="WDL" preformatted>
43-
<slot />
97+
<div class="card" v-if="wdlCode != null">
98+
<CodePreview header="wdl" preformatted>
99+
<div v-html="wdlCode"></div>
44100
</CodePreview>
45101
</div>
46102

47103
<!-- Card 3: Run Example -->
48-
<PlatformCodePreview
49-
windows-command="sprocket run example.wdl -vvv"
50-
mac-command="sprocket run example.wdl -vvv"
51-
unix-command="sprocket run example.wdl -vvv"
52-
/>
104+
<div class="card" v-if="runCode != null">
105+
<CodePreview header="bash" preformatted>
106+
<div v-html="runCode"></div>
107+
</CodePreview>
108+
</div>
53109
</section>
54110
</div>
55111
</div>

.vitepress/theme/components/Hero/PlatformCodePreview.vue

Lines changed: 0 additions & 94 deletions
This file was deleted.

.vitepress/theme/components/Homepage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import HomepageContent from './HomepageContent.vue'
66

77
<template>
88
<Hero>
9-
<slot />
9+
<slot></slot>
1010
</Hero>
1111
<Showcase />
1212
<HomepageContent />

.vitepress/theme/styles/utilities.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@
5454
.container {
5555
max-width: 1536px;
5656
}
57-
}
57+
}

index.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ sidebar: false
88

99
<HomePage>
1010

11+
<template #install>
12+
```bash
13+
cargo install sprocket --locked
14+
```
15+
</template>
16+
1117
```wdl
12-
version 1.0
18+
version 1.2
1319
1420
workflow count_lines {
1521
input { File input_file }

0 commit comments

Comments
 (0)