Original Markdown from content files should be accessible (as it was in Nuxt Content v1)
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.
If you want to modify the markdown before it is parsed, you can use the content:file:beforeParse hook
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.bodyis 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.
@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
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
beforeParsehook, but:
- The pre-parsed
file.bodyis 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!
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.
.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.