Skip to content

Conversation

@roadlittledawn
Copy link
Contributor

@roadlittledawn roadlittledawn commented Nov 3, 2020

Closes #194

Adds a <RelatedContent /> component to all pages that do not already have a For more help section populated. If just <h2>For more help</h2> element is present without content following it, it's removed during migration so the basicDoc.js template knows to insert the default content via the <RelatedContent /> component.

This also adds a prop to MDXContainer component so RelatedContent is contained within the container to take advantage of all the CSS rules.

Example of doc that has custom For more help content pre-populated:
https://docs-preview.newrelic.com/docs/browser/new-relic-browser/page-load-timing-resources/session-tracking

image

@roadlittledawn
Copy link
Contributor Author

Note to selves: I could not get turndown.remove() to work, but .addRule() did the trick. Maybe someone has insight why this wouldn't work:

.remove(
  (node) => node.nodeName === 'H2' && node.textContent === 'For more help' && !node.nextElementSibling
)```

Copy link
Contributor

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a few questions for you.

children,
className,
components,
relatedContent = {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid setting this default to an empty object. If you happen to hit this use case, React will complain about trying to render objects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit mixed on this approach. While this solves the issue of making sure the content shows up in the correct container with the correct styles applied, this doesn't allow us any customization on the "extra" UI that is no longer markdown. Any additional UI that we want to add for any template would need its own prop.

What about potentially creating a body prop for the MDX body content and instead reserving children for this use case? This gives us a pretty good way to customize this component with extra UI without needing to open up new props every time we need to do so. This might look like this in practice:

import MDXContainer from './MDXContainer'

// ...
// Body with no additional UI
<MDXContainer body={body} />

// Body with additional UI
<MDXContainer body={body}>
  {moreHelpExists ? null : <RelatedContent />}
</MDXContainer>

This means that the MDXContainer doesn't have to care about the type of component that is rendered underneath the markdown. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see what you're saying. makes sense to me. i like that extra flexibility in putting any additional stuff in children. doing that now.

one question about that. would would the PropType be for children then? would it still be children: PropTypes.node

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! PropTypes.node works great!

replacement: (content) =>
`<div className="landing-page-tile">\n\n${content}\n\n</div>\n\n`,
})
.addRule('moreHelp', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

} = mdx;

const moreHelpExists = mdxAST.children.find(
(node) => node.type === 'heading' && toString(node) === 'For more help'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Would it make sense to pull the For more help out to a constant at the top of the file so that its easy to reference/tweak?

@jerelmiller
Copy link
Contributor

Very odd that would't work. Thats ok. addRule works fine for me!

@jerelmiller jerelmiller merged commit 66f8d6f into develop Nov 4, 2020
@jerelmiller jerelmiller deleted the clinton/related-content branch November 4, 2020 18:59
kanderson250 pushed a commit to kanderson250/docs-website that referenced this pull request Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Templates] Related content component with hard-coded defaults

3 participants