Open NJKode opened 1 year ago
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:
file.body
is the entire file contents, including front matterSo 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
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!
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:
Which is evidently not the case.
Desired Behaviour
Both
useContent()
andqueryContent()
should returntext
(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 usewithout()
oronly()
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.