cloudflare-docs icon indicating copy to clipboard operation
cloudflare-docs copied to clipboard

Add custom components to dev docs

Open abracchi-tw opened this issue 6 years ago • 1 comments

Hello,

With the help from a frontend developer on the Teams team, I've tried to add ProductGrid.js to https://developers.cloudflare.com/cloudflare-one/ by copying it (and its .css) from developers.cloudflare.com/src. I then proceeded to use the component to the .docs/src/content/index.md page.

However, as we made our changes in the .docs/src/components/ folder, and then ran npm run savechanges in the product directory, the changes in .docs/src/components/ were not copied to the cloudflare-one/src/ folder, and thus could not be committed. I suspect this is because npm run savechanges only copies the content of .docs/src/content/ into cloudflare-one/src/content/, and nothing else.

This of course caused the build to fail.

What's the best way to go about this? Could we have some guidance on how to add custom components to each product section? It would be so helpful to be able to recycle components across the dev docs.

Thank you!

cc @TownLake

abracchi-tw avatar Dec 02 '20 11:12 abracchi-tw

We should definitely add some guidance to the engine docs. That being said, it’s worth noting that the linked minimal example site demonstrates the current best recommendation for importing a custom component.

Site: https://docs-engine-example.adam.workers.dev/another-page Code: https://github.com/adamschwartz/docs-engine-example/blob/6d725ffa554454e1daa4c0d2a8a7e44408056e6b/src/content/another-page.md#L1

Essentially the idea is to just put the component JS files inside src/content—whether directly or inside a components sub-folder is up to the author.

The behavior you’re seeing with npm run savechanges is intended, though I would agree it’s not ideal. We considered allowing a site to place components inside src/components, but files placed there would either overwrite or collide in some way with the engine’s components (https://github.com/cloudflare/cloudflare-docs-engine/tree/master/src/components). This is actually something we’d like to enable one day, but for the purpose of “shadowing” (similar to how Gatsby itself works). This would be used primarily for the purpose of replacing or augmenting stock engine components rather than using your own.

Lastly, placing components inside src/content might seem awkward at first, it actually feels somewhat reasonable to me when the types of components I would expect being placed there would really be another form of custom content for a specific docs site. On the other hand, we should definitely advise authors to consider contributing their components back to the engine when they’re not specific to that product’s domain.

For example, if a specific docs site wanted to build its own button component, I’d rather see us propose that to https://github.com/cloudflare/cloudflare-brand-assets (a dependency of https://github.com/cloudflare/cloudflare-docs-engine/) rather than implement it themselves in their docs site.

For a real-world example of how this benefits everyone, the Stream docs don’t implement a component for displaying a Stream video player. Instead the engine supplies that https://github.com/cloudflare/cloudflare-docs-engine/blob/ea2031c9575f7785ec9356963fd9cf6e00d2c379/src/components/mdx/stream-video.js and as a result, other docs sites (e.g. 1.1.1.1 and Access) get to take advantage as well.

I hope this helps! And to reiterate, I think it would make a lot of sense to add some guidance to the docs engine docs directly, perhaps as another page inside the content contributions section (https://github.com/cloudflare/cloudflare-docs/tree/production/products/docs-engine/src/content/contributing/content) (maybe “Using custom components”).

adamschwartz avatar Dec 02 '20 22:12 adamschwartz