Skip to content
This repository was archived by the owner on Oct 28, 2025. It is now read-only.

Commit 92b6c7c

Browse files
authored
Merge pull request #31 from alexaveldanez/dynamic-code-block-fixes
(#17) Add language styling to Dynamic Code Block
2 parents 2f313da + 2ae1d04 commit 92b6c7c

File tree

4 files changed

+234
-189
lines changed

4 files changed

+234
-189
lines changed

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "choco-astro",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"packageManager": "yarn@4.2.2",
55
"type": "module",
66
"description": "A global set of dependencies to be used on Chocolatey Software Astro projects.",
@@ -33,8 +33,5 @@
3333
"remark-custom-header-id": "^1.0.0",
3434
"sanitize-html": "^2.17.0",
3535
"typescript": "^5.6.3"
36-
},
37-
"resolutions": {
38-
"brace-expansion": "^4.0.1"
3936
}
4037
}
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
---
2+
import { z } from 'zod';
3+
4+
const dynamicCodeBlockSchema = z.object({
5+
language: z.enum(['markup', 'css', 'clike', 'javascript', 'bash', 'csharp', 'diff', 'json', 'powershell', 'puppet', 'python', 'ruby', 'scss', 'shell-session', 'xml-doc', 'yaml'])
6+
});
7+
8+
type DynamicCodeBlock = z.infer<typeof dynamicCodeBlockSchema>;
9+
type DynamicCodeBlockLanguage = DynamicCodeBlock['language'];
10+
11+
interface Props {
12+
language: DynamicCodeBlockLanguage
13+
}
14+
15+
const { language } = Astro.props;
16+
17+
const content = {
18+
language
19+
}
20+
21+
dynamicCodeBlockSchema.parse(content);
22+
223
const generateRandomClass = () => {
324
const randomNumber = Math.floor(Math.random() * 1000);
425
return `dynamic-code-block-${randomNumber}`;
526
};
627
---
728

829
<div class="dynamic-code-block-container copy-command">
9-
<pre class="language-powershell"><code class={generateRandomClass()}>
30+
<pre class=`language-${language}`><code class={generateRandomClass()}>
1031
<slot />
1132
</code></pre>
1233
</div>
Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
11
---
2-
const { name, defaultValue } = Astro.props;
2+
import { z } from 'zod';
3+
4+
// Define the schema
5+
const dynamicCodeBlockInputSchema = z.object({
6+
name: z.string(),
7+
defaultValue: z.string(),
8+
label: z.string().optional()
9+
});
10+
11+
// Define the type
12+
type DynamicCodeBlockInput = z.infer<typeof dynamicCodeBlockInputSchema>;
13+
14+
interface Props {
15+
name: DynamicCodeBlockInput['name'],
16+
defaultValue: DynamicCodeBlockInput['defaultValue']
17+
label?: DynamicCodeBlockInput['label']
18+
}
19+
20+
const { name, defaultValue, label } = Astro.props;
21+
22+
const content = {
23+
name,
24+
defaultValue,
25+
label
26+
};
27+
28+
// Validate the content
29+
dynamicCodeBlockInputSchema.parse(content);
330
---
431

5-
<div class="col-lg-6">
6-
<input class="form-control mb-3 dynamic-code-block-input" type="text" name={name} data-default-value={defaultValue} placeholder={defaultValue} />
32+
<div class="row align-items-center mb-3">
33+
{label && (
34+
<div class="col-lg-auto pe-lg-0">
35+
<label for={name} class="col-form-label">{label}:</label>
36+
</div>
37+
)}
38+
<div class="col-lg-6">
39+
<input id={name} class="form-control dynamic-code-block-input" type="text" name={name} data-default-value={defaultValue} placeholder={defaultValue} />
40+
</div>
741
</div>

0 commit comments

Comments
 (0)