nuxt / content

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

Original Markdown from content files should be accessible (as it was in Nuxt Content v1) #2105

Open NJKode opened 1 year ago

NJKode commented 1 year ago

Problem Description

I am migrating a site to Nuxt v3 and Nuxt Content v2. Previously, I could access the markdown for a given page by passing the text: true option to the $content() function.

However, that markdown is simply no longer accessible. The migration guide here specifies:

queryContent provides same utilities as legacy $content

Which is evidently not the case.

Desired Behaviour

Both useContent() and queryContent() should return text (or equivalent) along with the rest of the data. I don't see why this shouldn't be the case. If I want to filter this out (i.e. fetch the page data without the markdown), I can just use without() or only() as part of my query.

Alternatives considered

I have considered processing the returned body object to extract the text. However, this seems overly complicated - especially as I was able to just obtain the text in v1.

nobkd commented 1 year ago

If you want to modify the markdown before it is parsed, you can use the content:file:beforeParse hook

NJKode commented 1 year ago

I do not want to modify the markdown.

My main use case is getting a word count from the original markdown text - I should have stated this earlier sorry.

I've investigated using a beforeParse hook, but:

So this method is infeasible.

The alternative, as stated, is to create a function extracts all the text from the parsed body. This body is a complex object representation of the DOM. This is a painful amount of work for something that should be simple, and was simple in Nuxt Content v1.

ManasMadrecha commented 1 year ago

@NJKode Yes, V1 was easy.

Here is the code to get original body of the markdown: https://github.com/nuxt/content/issues/2056#issuecomment-1560200992

Barbapapazes commented 1 year ago

I do not want to modify the markdown.

My main use case is getting a word count from the original markdown text - I should have stated this earlier sorry.

I've investigated using a beforeParse hook, but:

  • The pre-parsed file.body is the entire file contents, including front matter
  • I cannot add a new property (e.g. word count) to the file

So this method is infeasible.

The alternative, as stated, is to create a function extracts all the text from the parsed body. This body is a complex object representation of the DOM. This is a painful amount of work for something that should be simple, and was simple in Nuxt Content v1.

You can create a PR to solve this using a flag to enable or not this feature!