nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.12k stars 623 forks source link

Import code snippets like vitepress #1646

Open hunterliu1003 opened 2 years ago

hunterliu1003 commented 2 years ago

I have a component library that using nuxt content as the documentation. The documentaion has a lot of examples using code-group. Is that any way to avoid to copy entire file into the markdown?

I wish nuxt content can provide similar markdown syntax to Import code snippets in Vitepress.

for example:

::code-group
  <<< @/components/content/myComponent.vue

  <<< @/components/content/myComponentPreview.vue

  ::code-block{label="Preview" preview}
    ::my-compontent-preview
  ::
::
atinux commented 2 years ago

What about having:

:code-block{src="~/components/content/MyComponent.vue"}

?

hunterliu1003 commented 2 years ago

Sounds nice to me!😍

ManasMadrecha commented 2 years ago

I think merely importing the text of any file (incl. components) can be done via already existing remark plugins.

drusellers commented 1 year ago

I'm also interested in doing something with a snippet based approach.

  1. Is it possible to extend the content query to add other "content types" - I'd really like to be able to query my code in a similar fashion.

  2. A :code-block{file=abc.java,language=java} would also be much appreciated.

phojie commented 1 year ago

You can check this module I've created, ideas came from https://vitepress.dev/guide/markdown#import-code-snippets

🔗 https://github.com/phojie/nuxt-content-snippet

ManasMadrecha commented 1 year ago

@phojie Lovely. Kindly ensure that the module even considers the fact that the files imported in markdown may reside not just in local PC. So, the module should modify the source to import the files from Nuxt cache.

phojie commented 1 year ago

@phojie Lovely. Kindly ensure that the module even considers the fact that the files imported in markdown may reside not just in local PC. So, the module should modify the source to import the files from Nuxt cache.

I'm not sure what you mean, please feel free to contribute or submit an issue to the repo thanks 😸