-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added dynamic meta export to events_$eventId and groups_.$groupId components #163
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
app/routes/events_.$eventId.tsx
Outdated
@@ -102,3 +102,12 @@ export function ErrorBoundary() { | |||
const { eventId } = useParams(); | |||
return <div className="error-container">There was an error loading event by the id {eventId}.</div>; | |||
} | |||
|
|||
export const meta: MetaFunction = ({ data }) => { | |||
const eventFullName = data.event.name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out this section in the Remix docs: https://remix.run/docs/en/main/route/meta#data.
You can use the loader
function to infer the type of data!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Bravo!
Left just non-blocking comments.
app/routes/events_.$eventId.tsx
Outdated
@@ -126,3 +126,12 @@ export function ErrorBoundary() { | |||
const { eventId } = useParams(); | |||
return <div className="error-container">There was an error loading event by the id {eventId}.</div>; | |||
} | |||
|
|||
export const meta: MetaFunction<typeof loader> = ({ data }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Can we move Metafunction to the top? 🙂 I feel it should be there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
app/routes/events_.$eventId.tsx
Outdated
|
||
export const meta: MetaFunction<typeof loader> = ({ data }) => { | ||
const eventFullName = data.event.name; | ||
const regex = /^[^:]+/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker: Why do we need regex? If it's necessary, should we place a tiny comment on what it does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's a title in the format 'Tech Talks: Exploring the Latest Web Development Trends', it will only take the text before the colon.
app/routes/events_.$eventId.tsx
Outdated
const eventName = eventFullName.match(regex); | ||
const eventDescription = data.event.description; | ||
|
||
return [{ title: `${eventName} | Social Plan-It` }, { name: 'description', content: `${eventDescription}` }]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great boost of SEO!
Another NIT: Should we shorten the title if it's lengthy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super!
export async function loader({ params }: LoaderFunctionArgs) { | ||
export const meta: MetaFunction<typeof loader> = ({ data }) => { | ||
const eventFullName = data.event.name; | ||
const regex = /^[^:]+/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: is there a reason we cleaning up only : , or should we go further and only allow a-z A-Z 0-9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the meta tags!
const eventName = eventFullName.match(regex); | ||
const eventDescription = data.event.description; | ||
|
||
return [{ title: `${eventName} | Social Plan-It` }, { name: 'description', content: `${eventDescription}` }]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return [{ title: `${eventName} | Social Plan-It` }, { name: 'description', content: `${eventDescription}` }]; | |
return [{ title: `${eventName} | Social Plan-It` }, { name: 'description', content: eventDescription }]; |
export const meta: MetaFunction<typeof loader> = ({ data }) => { | ||
const group = data.group; | ||
|
||
return [{ title: `${group.name} | Social Plan-It` }, { name: 'description', content: `${group.description}` }]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return [{ title: `${group.name} | Social Plan-It` }, { name: 'description', content: `${group.description}` }]; | |
return [{ title: `${group.name} | Social Plan-It` }, { name: 'description', content: group.description }]; |
Issue: #
Summary (1-2 sentences)
Added dynamic meta export to the events_$eventId and groups_.$groupId components. Using the data object, I display the event name as the title and the event description in the meta description.
Details (reason and description of the changes)
Enhances the SEO for this page.
Challenges (what problems did I face?) (optional)
Had TS compliance issues. Ended up inferring the type of data in the MetaFunction per suggestion below.