nuxt / content

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

Add local remark plugin #1367

Open Benbinbin opened 2 years ago

Benbinbin commented 2 years ago

Environment

Reproduction

https://github.com/Benbinbin/nuxt-content-local-remark-plugin

Describe the bug

The former documentation show how to use the local remark plugin, like ~/markdownPlugins/remark-plugin.js

but the new documentation delete this part

when I use the same syntax which is mentioned at the old documentation

export default defineNuxtConfig({
  // ...
  content: {
    // ...
    markdown: {
      remarkPlugins: ['~/markdownPlugins/remarkPlugin.js']
    }
  }
})

but then I get an error (see th Logs part ๐Ÿ‘‡ ) it recognizes the local remark plugin file as a package?

maybe the old documentation just suitable for content v1, any new way to add local remark plugin for content v2?

Additional context

some relative issues about plugin:

Logs

[nuxt] [request error] Cannot find package '~' imported from D:\Work\Code\Web\Frontend\Nuxt\nuxt-content-local-remark-plugin\.nuxt\dev\index.mjs
  at new NodeError (node:internal/errors:371:5)  
  at packageResolve (node:internal/modules/esm/resolve:884:9)  
  at moduleResolve (node:internal/modules/esm/resolve:929:18)  
  at defaultResolve (node:internal/modules/esm/resolve:1044:11)  
  at ESMLoader.resolve (node:internal/modules/esm/loader:422:30)
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40)
  at ESMLoader.import (node:internal/modules/esm/loader:276:22)
  at importModuleDynamically (node:internal/modules/esm/translators:111:35)
  at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14)
  at importPlugins (/D:/Work/Code/Web/Frontend/Nuxt/nuxt-content-local-remark-plugin/.nuxt/dev/index.mjs:1096:32)
NozomuIkuta commented 2 years ago

Here is a debug memo.

Nuxt Content v2 dynamically imports plugins without resolving Nuxt aliases, so they are assumed to be inside node_modules.

https://github.com/nuxt/content/blob/ede65e8337ca3eb597af95c17cfc609e4015238c/src/runtime/server/transformers/markdown.ts#L25-L38

Nuxt Content v1 resolves aliases by resolver:

https://github.com/nuxt/content/blob/776e428eb2987e5a8c237fbc90e2d9beb8e3b0e3/packages/content/lib/utils.js#L58-L83

ManasMadrecha commented 2 years ago

@NozomuIkuta How to solve it then?

Benbinbin commented 2 years ago

@ManasMadrecha My solution is adding the custom Remark plugins as a npm module, you can check this repo for more detail.

Refer to this stackoverflow answer.

ManasMadrecha commented 2 years ago

@Benbinbin

In the BlogiNote link you shared, we don't need to actually publish the plugin to npm, right?
Just use the plugin offline and just change the link in the Package.json to file:... and then Content Module will be able to pick it up, right?

Benbinbin commented 2 years ago

@ManasMadrecha yep, you're right

ManasMadrecha commented 2 years ago

@Benbinbin Amazing! BTW, your website's Table of Contents is just next level. It's magical... ๐Ÿ˜ฎ๐Ÿ‘๐Ÿป

Image ![image](https://user-images.githubusercontent.com/65993481/182031114-6bf5bce4-465c-4c44-b2af-85ac0fd057ae.png)
innocenzi commented 1 year ago

Seems quite inconvenient for one-time, project-specific plugins. Is there not a syntax for importing local plugins?

Benbinbin commented 1 year ago

Seems quite inconvenient for one-time, project-specific plugins. Is there not a syntax for importing local plugins?

@innocenzi maybe the hook content:file:afterParse provided by Nuxt Content is the alternative solution for remark or rehype plugin

ManasMadrecha commented 1 year ago

@Benbinbin But the hook content:file:afterParse works as only rehype plugin and not remark plugin. Still, need to install a local remark plugin as npm module ๐Ÿ˜ฎโ€๐Ÿ’จ

DraftProducts commented 7 months ago

Are there news about this regression ?