Open samyosm opened 11 months ago
Yes, that would be nice. Care to take a stab at it and send a PR. The code is here: https://github.com/BuilderIO/qwik/blob/main/packages/qwik-city/runtime/src/head.ts#L52
Hello, please can I be assigned this issue? I will love to fix this. Cheers.
Hi @mhevery is this issue still open, i would like to work on it.
Sure, please go ahead.
@theCephas arrived first 😅 you can do pair programming to solve this race condition
Hi, is this issue fixed already or can I be assigned to it??
I don't believe so. Perhaps all of the interested parties could collaborate on a solution. I am here to answer questions.
Hey @theCephas and @Blossomeze if it's okay with you, let's collaborate on this.
I don't mind. Although, I started working on it already. How do we collaborate to fix it? @Luwa-Tech
If you want you can use our discord server
import { useEffect } from 'react';
const useDocumentHead = (title: string) => { useEffect(() => { // Check if the title is already set const existingTitle = document.title;
// If the title is not set or is the default title, update it
if (!existingTitle || existingTitle === 'Untitled') {
document.title = title;
}
// Return the title (either existing or updated)
return () => {
document.title = existingTitle; // Reset the title on component unmount
};
}, [title]); };
export default useDocumentHead;
import React from 'react';
const Layout = ({ content }) => { // Use the first h1 heading as the title if it is not already set const title = content.headings.length > 0 ? content.headings[0].text : 'Untitled';
// Use the useDocumentHead hook to set or retrieve the title useDocumentHead(title);
return (
); };
export default Layout;
Is your feature request related to a problem?
It would be appreciated to be able to change the title of a page based on the props a component receives or the content (
useContent
).My need
I'm using the MDX feature and I would like the title to be the first
h1
if it hasn't been set in the frontmatter. I.e.,Describe the solution you'd like
Dynamic Head could give you the content of a Markdown page. E.g.,
Describe alternatives you've considered
I considered setting the title myself after the document loads.
Additional context
No response