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

Commit 437716f

Browse files
committed
create ImportCode component
1 parent b17c04b commit 437716f

File tree

6 files changed

+33
-74
lines changed

6 files changed

+33
-74
lines changed

docs/reference/cli.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ To verify your [installation](/getting-started/installation) run `nitric version
88

99
To get a list of the available commands, run the `nitric help` command and you will see the following:
1010

11-
```text file=<rootDir>/src/assets/cli-usage.txt
12-
13-
```
11+
<ImportCode file="/src/assets/cli-usage.txt" />
1412

1513
## Common Commands
1614

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"react-icons": "^5.3.0",
6868
"rehype-autolink-headings": "^7.1.0",
6969
"remark": "^15.0.1",
70-
"remark-code-import": "^1.2.0",
7170
"remark-gfm": "^4.0.0",
7271
"remark-mdx": "^3.0.0",
7372
"simple-functional-loader": "^1.2.1",

src/components/code/ImportCode.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react'
2+
import { Code } from './Code'
3+
import { RawCode } from 'codehike/code'
4+
import path from 'path'
5+
import fs from 'fs/promises'
6+
7+
export const ImportCode: React.FC<{ file: string; meta: string }> = async ({
8+
file,
9+
meta = '',
10+
}) => {
11+
try {
12+
const contents = await fs.readFile(path.join(process.cwd(), file), 'utf-8')
13+
14+
const lang = path.extname(file).replace('.', '')
15+
16+
const codeBlock: RawCode = {
17+
value: contents.trim(),
18+
lang,
19+
meta,
20+
}
21+
22+
return <Code codeblock={codeBlock} />
23+
} catch (error) {
24+
console.error('Error reading file for ImportCode:', error)
25+
return <div>Error reading file {file} for ImportCode</div>
26+
}
27+
}

src/components/mdx.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,5 @@ export { HomeHeader } from '@/components/HomeHeader'
161161
export { ShowIfLang } from '@/components/ShowIfLang'
162162

163163
export { Libraries } from '@/components/Libraries'
164+
165+
export { ImportCode } from '@/components/code/ImportCode'

src/mdx/remark.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { mdxAnnotations } from 'mdx-annotations'
22
import remarkGfm from 'remark-gfm'
3-
import codeImport from 'remark-code-import'
43

5-
export const remarkPlugins = [mdxAnnotations.remark, remarkGfm, codeImport]
4+
export const remarkPlugins = [mdxAnnotations.remark, remarkGfm]

yarn.lock

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,7 @@
18401840
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-3.0.3.tgz#acaab0f919ce69cce629c2d4ed2eb4adc1b6c20c"
18411841
integrity sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==
18421842

1843-
"@types/unist@^2.0.0", "@types/unist@^2.0.2":
1843+
"@types/unist@^2.0.0":
18441844
version "2.0.11"
18451845
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.11.tgz#11af57b127e32487774841f7a4e54eab166d03c4"
18461846
integrity sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA==
@@ -4284,11 +4284,6 @@ is-boolean-object@^1.1.0:
42844284
call-bind "^1.0.2"
42854285
has-tostringtag "^1.0.0"
42864286

4287-
is-buffer@^2.0.0:
4288-
version "2.0.5"
4289-
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.5.tgz#ebc252e400d22ff8d77fa09888821a24a658c191"
4290-
integrity sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==
4291-
42924287
is-bun-module@^1.0.2:
42934288
version "1.1.0"
42944289
resolved "https://registry.yarnpkg.com/is-bun-module/-/is-bun-module-1.1.0.tgz#a66b9830869437f6cdad440ba49ab6e4dc837269"
@@ -5538,11 +5533,6 @@ mimic-function@^5.0.0:
55385533
resolved "https://registry.yarnpkg.com/mimic-function/-/mimic-function-5.0.1.tgz#acbe2b3349f99b9deaca7fb70e48b83e94e67076"
55395534
integrity sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA==
55405535

5541-
min-indent@^1.0.1:
5542-
version "1.0.1"
5543-
resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.1.tgz#a63f681673b30571fbe8bc25686ae746eefa9869"
5544-
integrity sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==
5545-
55465536
55475537
version "9.0.3"
55485538
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.3.tgz#a6e00c3de44c3a542bfaae70abfc22420a6da825"
@@ -6256,15 +6246,6 @@ rehype-stringify@^10.0.0:
62566246
hast-util-to-html "^9.0.0"
62576247
unified "^11.0.0"
62586248

6259-
remark-code-import@^1.2.0:
6260-
version "1.2.0"
6261-
resolved "https://registry.yarnpkg.com/remark-code-import/-/remark-code-import-1.2.0.tgz#2f879c05909eb5f7cf5a1236bab415010eec69dd"
6262-
integrity sha512-fgwLruqlZbVOIhCJFjY+JDwPZhA4/eK3InJzN8Ox8UDdtudpG212JwtRj6la+lAzJU7JmSEyewZSukVZdknt3Q==
6263-
dependencies:
6264-
strip-indent "^4.0.0"
6265-
to-gatsby-remark-plugin "^0.1.0"
6266-
unist-util-visit "^4.1.0"
6267-
62686249
remark-frontmatter@^5.0.0:
62696250
version "5.0.0"
62706251
resolved "https://registry.yarnpkg.com/remark-frontmatter/-/remark-frontmatter-5.0.0.tgz#b68d61552a421ec412c76f4f66c344627dc187a2"
@@ -6862,13 +6843,6 @@ strip-final-newline@^3.0.0:
68626843
resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-3.0.0.tgz#52894c313fbff318835280aed60ff71ebf12b8fd"
68636844
integrity sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==
68646845

6865-
strip-indent@^4.0.0:
6866-
version "4.0.0"
6867-
resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-4.0.0.tgz#b41379433dd06f5eae805e21d631e07ee670d853"
6868-
integrity sha512-mnVSV2l+Zv6BLpSD/8V87CW/y9EmmbYzGCIavsnsI6/nwn26DwffM/yztm30Z/I2DY9wdS3vXVCMnHDgZaVNoA==
6869-
dependencies:
6870-
min-indent "^1.0.1"
6871-
68726846
strip-json-comments@^3.1.1:
68736847
version "3.1.1"
68746848
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
@@ -7019,28 +6993,13 @@ tmp@~0.2.3:
70196993
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.3.tgz#eb783cc22bc1e8bebd0671476d46ea4eb32a79ae"
70206994
integrity sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==
70216995

7022-
to-gatsby-remark-plugin@^0.1.0:
7023-
version "0.1.0"
7024-
resolved "https://registry.yarnpkg.com/to-gatsby-remark-plugin/-/to-gatsby-remark-plugin-0.1.0.tgz#34167b2c3cf3209745cf97e5a488042586f9990d"
7025-
integrity sha512-blmhJ/gIrytWnWLgPSRCkhCPeki6UBK2daa3k9mGahN7GjwHu8KrS7F70MvwlsG7IE794JLgwAdCbi4hU4faFQ==
7026-
dependencies:
7027-
to-vfile "^6.1.0"
7028-
70296996
to-regex-range@^5.0.1:
70306997
version "5.0.1"
70316998
resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-5.0.1.tgz#1648c44aae7c8d988a326018ed72f5b4dd0392e4"
70326999
integrity sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==
70337000
dependencies:
70347001
is-number "^7.0.0"
70357002

7036-
to-vfile@^6.1.0:
7037-
version "6.1.0"
7038-
resolved "https://registry.yarnpkg.com/to-vfile/-/to-vfile-6.1.0.tgz#5f7a3f65813c2c4e34ee1f7643a5646344627699"
7039-
integrity sha512-BxX8EkCxOAZe+D/ToHdDsJcVI4HqQfmw0tCkp31zf3dNP/XWIAjU4CmeuSwsSoOzOTqHPOL0KUzyZqJplkD0Qw==
7040-
dependencies:
7041-
is-buffer "^2.0.0"
7042-
vfile "^4.0.0"
7043-
70447003
toml@^3.0.0:
70457004
version "3.0.0"
70467005
resolved "https://registry.yarnpkg.com/toml/-/toml-3.0.0.tgz#342160f1af1904ec9d204d03a5d61222d762c5ee"
@@ -7262,13 +7221,6 @@ unist-util-remove-position@^5.0.0:
72627221
"@types/unist" "^3.0.0"
72637222
unist-util-visit "^5.0.0"
72647223

7265-
unist-util-stringify-position@^2.0.0:
7266-
version "2.0.3"
7267-
resolved "https://registry.yarnpkg.com/unist-util-stringify-position/-/unist-util-stringify-position-2.0.3.tgz#cce3bfa1cdf85ba7375d1d5b17bdc4cada9bd9da"
7268-
integrity sha512-3faScn5I+hy9VleOq/qNbAd6pAx7iH5jYBMS9I1HgQVijz/4mv5Bvw5iw1sC/90CODiKo81G/ps8AJrISn687g==
7269-
dependencies:
7270-
"@types/unist" "^2.0.2"
7271-
72727224
unist-util-stringify-position@^4.0.0:
72737225
version "4.0.0"
72747226
resolved "https://registry.yarnpkg.com/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz#449c6e21a880e0855bf5aabadeb3a740314abac2"
@@ -7292,7 +7244,7 @@ unist-util-visit-parents@^6.0.0:
72927244
"@types/unist" "^3.0.0"
72937245
unist-util-is "^6.0.0"
72947246

7295-
unist-util-visit@^4.1.0, unist-util-visit@^4.1.1:
7247+
unist-util-visit@^4.1.1:
72967248
version "4.1.2"
72977249
resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-4.1.2.tgz#125a42d1eb876283715a3cb5cceaa531828c72e2"
72987250
integrity sha512-MSd8OUGISqHdVvfY9TPhyK2VdUrPgxkUtWSuMHF6XAAFuL4LokseigBnZtPnJMu+FbynTkFNnFlyjxpVKujMRg==
@@ -7400,14 +7352,6 @@ vfile-location@^5.0.0:
74007352
"@types/unist" "^3.0.0"
74017353
vfile "^6.0.0"
74027354

7403-
vfile-message@^2.0.0:
7404-
version "2.0.4"
7405-
resolved "https://registry.yarnpkg.com/vfile-message/-/vfile-message-2.0.4.tgz#5b43b88171d409eae58477d13f23dd41d52c371a"
7406-
integrity sha512-DjssxRGkMvifUOJre00juHoP9DPWuzjxKuMDrhNbk2TdaYYBNMStsNhEOt3idrtI12VQYM/1+iM0KOzXi4pxwQ==
7407-
dependencies:
7408-
"@types/unist" "^2.0.0"
7409-
unist-util-stringify-position "^2.0.0"
7410-
74117355
vfile-message@^4.0.0:
74127356
version "4.0.2"
74137357
resolved "https://registry.yarnpkg.com/vfile-message/-/vfile-message-4.0.2.tgz#c883c9f677c72c166362fd635f21fc165a7d1181"
@@ -7416,16 +7360,6 @@ vfile-message@^4.0.0:
74167360
"@types/unist" "^3.0.0"
74177361
unist-util-stringify-position "^4.0.0"
74187362

7419-
vfile@^4.0.0:
7420-
version "4.2.1"
7421-
resolved "https://registry.yarnpkg.com/vfile/-/vfile-4.2.1.tgz#03f1dce28fc625c625bc6514350fbdb00fa9e624"
7422-
integrity sha512-O6AE4OskCG5S1emQ/4gl8zK586RqA3srz3nfK/Viy0UPToBc5Trp9BVFb1u0CjsKrAWwnpr4ifM/KBXPWwJbCA==
7423-
dependencies:
7424-
"@types/unist" "^2.0.0"
7425-
is-buffer "^2.0.0"
7426-
unist-util-stringify-position "^2.0.0"
7427-
vfile-message "^2.0.0"
7428-
74297363
vfile@^6.0.0, vfile@^6.0.1:
74307364
version "6.0.3"
74317365
resolved "https://registry.yarnpkg.com/vfile/-/vfile-6.0.3.tgz#3652ab1c496531852bf55a6bac57af981ebc38ab"

0 commit comments

Comments
 (0)