#Best way of getting headings from a file that embeds components into an MDX file

10 messages · Page 1 of 1 (latest)

open lily
#

Per the title of my question, I'm struggling to get all the headings from an MDX file.

Using the recommended useContent hook only works if the heading is explicitly typed in the file. However, if you return a JSX component with the same content, the headings won't be read by the useContent hook.

So for example the first code would work but the second one won't:

## I'm a good heading!!!
<BadHeading />

I'm not aware of any alternative solutions to this problem that don't require eager access to the DOM. Is there an alternative hook or API I could use on the qwik-city side of things to read all the headings from the file?

idle rampart
#

or maybe you want to "set" or "change" the website title but not by the route?

#

maybe if you only want to change the title?

import { component$ } from '@builder.io/qwik';

export const MyTitle = component$(() => {
  return <button onClick$={() => {
    document.title = 'this is a new title';
  }}>Change the website title</button>
});

this component for example should work

#

same if you useVisibleTask$ to change it on the browser mimic "onMount" function

open lily
#

I just want to read all titles in the page

#

This can only be done if you write out each heading when using markdown

#

I think I should've said headings

#

Since I believe most people call h1-h5 as headings

#

Best way of getting headings from a file that embeds components into an MDX file