Skip to content
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

Docs page on using custom components and data (and more broadly MDX) #89

Merged
merged 9 commits into from
Aug 16, 2022

Conversation

olayway
Copy link
Member

@olayway olayway commented Aug 11, 2022

Don't merge

Closes #20


Changes:

  • docs page (/docs/mdx) about MDX, containing:
    • introduction with basic info about MDX
    • info about syntax elements supported by MDX (Markdown, JSX, ESM import and export statements, JS expressions)
    • info on how to create components
    • info on how to import components
    • info on how to import data
    • info on how to define components locally
    • info on how to define data (variables) locally
  • test page (/test/mdx-components) for components written in MDX (=not JSX components)

Notes

I wasn't sure if we want to write documentation for MDX components as well so I've only tested if they work for now.

@olayway olayway requested a review from rufuspollock August 11, 2022 21:59
@netlify
Copy link

netlify bot commented Aug 11, 2022

Deploy Preview for spectacular-dragon-c1015c ready!

Name Link
🔨 Latest commit ee8d4f3
🔍 Latest deploy log https://app.netlify.com/sites/spectacular-dragon-c1015c/deploys/62fa8756a53c1d0008627a1b
😎 Deploy Preview https://deploy-preview-89--spectacular-dragon-c1015c.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@olayway olayway marked this pull request as ready for review August 14, 2022 17:37
@olayway olayway force-pushed the 20-components-import-docs branch from 1f35cc3 to f1dc37b Compare August 14, 2022 17:40
Copy link
Member

@rufuspollock rufuspollock left a comment

Choose a reason for hiding this comment

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

Great job! 👏 I'm going to merge now.

One major question (to address going forward) is about whether we can locate our components in site/content vs in templates/default as per my one major comment:

🚩 where is the components folders? This is crucial info for someone following along (is it relative to their content directory or where?

Atm it looks like this components folder is inside templates/default. Is there any way to import component relative to content folder or this file and have components in site/content/components or similar? That would be much more realistic for end users who don't have access to templates/default.


Let's see what exactly is MDX and what's so cool about it!

<Callout>
Copy link
Member

Choose a reason for hiding this comment

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

Soon we can replace this with obsidian style callouts!

Copy link
Member Author

Choose a reason for hiding this comment

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

One major question (to address going forward) is about whether we can locate our components in site/content vs in templates/default as per my one major comment

At the moment, having components inside /content folder doesn't work. It will throw an error related to having mixed content there. But maybe this can be set somehow in Contentlayer.

triangular_flag_on_post where is the components folders? This is crucial info for someone following along (is it relative to their content directory or where?

Totally agree, I'll make it more explicit.


# MDX

Flowershow parses all of your Markdown files as MDX. This means you not only can write your content using good old Markdown, but also extend it with JSX, JavaScript expressions, and `import` and `export` statements. It's basically Markdown on steroids 😀💪!
Copy link
Member

Choose a reason for hiding this comment

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

Context: This page is excellent. Comments here are more suggestions unless flagged as otherwise with 🚩

Personally, I might add a tiny bit about why this is powerful. e.g. "What this means is you can enrich your content with the full power of javascript and modern web technologies. [maybe add an examples e.g. adding rich dynamic visualizations or embedding data tables ...]


Flowershow parses all of your Markdown files as MDX. This means you not only can write your content using good old Markdown, but also extend it with JSX, JavaScript expressions, and `import` and `export` statements. It's basically Markdown on steroids 😀💪!

Let's see what exactly is MDX and what's so cool about it!
Copy link
Member

Choose a reason for hiding this comment

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

Love the tone: friendly and direct.

Let's see what exactly is MDX and what's so cool about it!

<Callout>
A basic familiarity with JSX (React components) and JavaScript might be helpful to understand this chapter, but you can also learn by example and start by tweaking some of our code. Opening this page in your text editor side by side with the rendered version in your browser may also help.
Copy link
Member

Choose a reason for hiding this comment

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

🚩 Opening this page in your text editor => link this page to the source in github (?)


### JSX and custom components

JSX allows you to create components, that you can reuse across all of your markdown files. This is especially useful if you find yourself writing a lot of custom HTML in your Markdown, and/or you use the same HTML code parts and copy them again and again to different markdown pages. You soon may find it difficult to tell what a given part of HTML block is supposed to do. And what used to be e.g. your blog content ends up as a Markdown-HTML-CSS soup. On top of that, imagine if you wanted to make some changes to all these copies of HTML blocks, that you used many different pages 🤯.
Copy link
Member

Choose a reason for hiding this comment

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

yes ... and we can also create dynamic components i.e. do programming. I'd almost emphasize that more e.g. we can have a datatable component and pass data to it. or create a chart. These are things you just can't do at all in markdown.


#### Importing components

To see this in action, let's create a React component in the `/components` folder:
Copy link
Member

Choose a reason for hiding this comment

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

🚩 where is the components folders? This is crucial info for someone following along (is it relative to their content directory or where?

Atm it looks like this components folder is inside templates/default. Is there any way to import component relative to content folder or this file and have components in site/content/components or similar? That would be much more realistic for end users who don't have access to templates/default.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with you and I've tried it before. I'll double-check it but I think there is an error related to having mixed content in the /content folder.

@rufuspollock rufuspollock merged commit 1cf8413 into main Aug 16, 2022
@olayway
Copy link
Member Author

olayway commented Aug 16, 2022

@rufuspollock thank you for the great suggestions! I've applied them and just need to double-check the issue re having components in the /content folder

@olayway olayway deleted the 20-components-import-docs branch September 7, 2022 15:22
rufuspollock added a commit to rufuspollock/flowershow that referenced this pull request Oct 27, 2023
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.

MDX support including components and data
2 participants