content icon indicating copy to clipboard operation
content copied to clipboard

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

Open NJKode opened this issue 2 years ago • 7 comments

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.

NJKode avatar Jun 14 '23 00:06 NJKode

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

nobkd avatar Jun 14 '23 13:06 nobkd

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.

NJKode avatar Jun 15 '23 02:06 NJKode

@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

ManasMadrecha avatar Jun 28 '23 13:06 ManasMadrecha

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!

Barbapapazes avatar Jul 08 '23 19:07 Barbapapazes

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.

github-actions[bot] avatar Dec 10 '24 17:12 github-actions[bot]

.

ManasMadrecha avatar Dec 11 '24 10:12 ManasMadrecha

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.

github-actions[bot] avatar Feb 09 '25 12:02 github-actions[bot]