Skip to content

Conversation

@jamiehenson
Copy link
Member

@jamiehenson jamiehenson commented Apr 11, 2025

This PR introduces a successive approach to using the Textile templating language - the long-awaited MDX. As a result of this PR, two templates are converted which correspond to the following pages (situated on the review env for ease):

MDX pages are placed in src/pages to utilise Gatsby's standard routing. Within these templates, normal Markdown syntax is supported as expected, but this PR also introduces the means to do certain other things that bridge the gap to functionality with the older Textile templates:

  • the If component is a basic conditional block. It takes a lang prop in the form of a string consisting of accepted languages joined by commas (i.e. "javascript,swift,ruby). If the active page language (determined by the overall page context) matches one of these languages, then the child content is rendered, and vice versa.

Example:

<If lang="javascript">
  Use the `unsubscribe()` function returned in the `subscribe()` response to remove a chat message listener:
</If>
  • the Code component (an alias for CodeSnippet, for ease) is a rich code snippet that's best demonstrated in Storybook - it has a run down of various props and modifications. Its child elements are Markdown code snippets (denoted by three backticks either side) - whatever the language qualifier is for each snippet determines how it's represented as a tab in the CodeSnippet.

Example (spaces added to backticks to allow rendering in this description):

<Code>
`` `javascript
// Initial subscription
const { unsubscribe } = room.messages.subscribe((event) => console.log(event.message));

// To remove the listener
unsubscribe();
`` `

`` `kotlin
subscription.unsubscribe()
`` `
</Code>

I'll add some testing before merge, but I want to get the ball rolling on reviews first and get onto any queries or questions.

Word of bot

This pull request introduces multiple changes focused on improving MDX file handling, adding support for GitHub Flavored Markdown (GFM), and enhancing the layout and functionality of the documentation platform. Key updates include the introduction of an MDXWrapper component, improved handling of code snippets and headers, and updates to dependencies and configurations.

Enhancements to MDX Handling:

  • Added a new MDXWrapper component to provide a structured layout for MDX files, including support for custom components like CodeSnippet, responsive tables, and Aside blocks. This component integrates with the layout context to manage active languages and page-specific features. (src/components/Layout/MDXWrapper.tsx, [1] [2] [3] [4]
  • Introduced the If component to conditionally render content in MDX files based on the active language. (src/components/Layout/mdx/If.tsx, src/components/Layout/mdx/If.tsxR1-R20)

Improved Markdown and Header Features:

  • Integrated the gatsby-remark-autolink-headers plugin to add clickable and copyable headers in Markdown files, including a utility hook (useCopyableHeaders) for setting header links dynamically. (gatsby-config.ts, [1] [2]
  • Enhanced the MarkdownProvider to allow overriding default components and added support for GitHub Flavored Markdown (GFM) via the remark-gfm plugin. (src/components/Markdown/MarkdownProvider.tsx, [1] [2] [3]

Updates to Layout Context:

  • Extended the LayoutContext to include page-specific context, such as available languages and frontmatter data, enabling better integration with MDX files. (src/contexts/layout-context.tsx, [1] [2] [3]

Dependency and Configuration Updates:

  • Updated dependencies in package.json to include remark-gfm, gatsby-remark-autolink-headers, and other related packages, and upgraded existing packages like gatsby-plugin-mdx. (package.json, [1] [2] [3]
  • Adjusted .prettierignore to exclude MDX files in src/pages for better inline rendering. (.prettierignore, .prettierignoreR1-R3)

Removal of Deprecated Content:

  • Removed the content/chat/index.textile file, which contained outdated documentation for the Ably Chat product.

These changes collectively enhance the platform's ability to handle MDX files, improve the user experience with Markdown content, and streamline the integration of language-specific features.

@coderabbitai
Copy link

coderabbitai bot commented Apr 11, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xhevpid April 11, 2025 11:21 Inactive
@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy April 28, 2025 16:35 Inactive
@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy April 29, 2025 13:42 Inactive
@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy April 29, 2025 14:50 Inactive
@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy April 29, 2025 15:33 Inactive
@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy April 29, 2025 16:43 Inactive
@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy April 29, 2025 21:35 Inactive
@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy April 29, 2025 21:50 Inactive
@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy April 30, 2025 12:17 Inactive
@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy April 30, 2025 14:39 Inactive
@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy April 30, 2025 15:53 Inactive
@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy April 30, 2025 16:34 Inactive
@@ -0,0 +1,68 @@
import { useEffect } from 'react';
Copy link
Member Author

@jamiehenson jamiehenson Apr 30, 2025

Choose a reason for hiding this comment

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

Basically, the whole reason for this is because we can't set customIds via gatsby-remark-autolink-headers. The plugin offers that functionality, but we're held back by the requirement that this Gatsby project adhere to ES Modules - which is a bit of tech debt @m-hulbert and I have discussed. It holds us back from a number of other remark plugins as well.

Small t-shirt, but still a blocker.

To get around this, we bodge in custom link tags and travel the DOM for them.

};

// Table components with responsive styling
const Table = (props: React.HTMLAttributes<HTMLTableElement>) => (
Copy link
Member Author

Choose a reason for hiding this comment

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

Very minimal table styling. This is basically here to expose an entry point for better styling later.

Copy link
Member

Choose a reason for hiding this comment

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

Better styling is still on the table 🥁 (I'll see myself out now)


const WrappedAside = (props: PropsWithChildren<{ 'data-type': string }>) => {
return (
<Aside
Copy link
Member Author

Choose a reason for hiding this comment

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

These are also temporary. Converting to ES Modules will allow us to use Github-inspired "admonitions" plugins which would give us those "note" blockquotes and stuff out of the box and put this old component to rest.

export const onCreatePage: GatsbyNode['onCreatePage'] = ({ page, actions }) => {
const { createPage } = actions;
// Function to extract code element classes from an MDX file
const extractCodeLanguages = async (filePath: string): Promise<Set<string>> => {
Copy link
Member Author

Choose a reason for hiding this comment

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

A first go at something a little less "runtime". Since the syntax for defining codeblocks is set by Markdown which is quite rigid itself - we can dig through MDX files for present languages and build a representative superset that way. Textile files are still determined at runtime as they are still tied into the half-Textile-half-React world.

Copy link
Member

Choose a reason for hiding this comment

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

This is nice! It would have been super convenient if the raw content of the file was available in onCreatePage, then you could forego all the duplicate IO (just a wishlist item)

@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy April 30, 2025 16:45 Inactive
@jamiehenson jamiehenson changed the title Web 3888 mdx [WEB-3888] Introduce support for MDX templating Apr 30, 2025
@jamiehenson jamiehenson marked this pull request as ready for review April 30, 2025 16:57
@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy April 30, 2025 18:40 Inactive
@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy May 1, 2025 09:34 Inactive
[HtmlDataTypes.article]: Article,
[HtmlDataTypes.section]: Section,
[HtmlDataTypes.aside]: Aside,
[HtmlDataTypes.aside]: (props) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bit wonky, but a circular dependency arises when using Aside outside of this context - like we do in MDXWrapper as a temporary means before we can use cleaner, Markdown-derived aside components. The bandage here is to load this on demand instead of webpack's normal module loading.

Alternatively, if the dust settles and GFM asides are still a no go, we can consider React-oriented admonitions like this: https://github.com/nebrelbug/react-admonitions

@jamiehenson jamiehenson requested review from a team, kennethkalmer and m-hulbert May 1, 2025 09:43
Copy link
Contributor

@m-hulbert m-hulbert left a comment

Choose a reason for hiding this comment

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

This LGTM after a monumental piece of work 🚀

I found 1 niche issue that I'm happy to raise as a bug post-release.

Would you mind removing the 2 converted chat pages before we merge too? I'd like to migrate the whole section in 1 go which I'll do separately.

Copy link
Contributor

@aralovelace aralovelace left a comment

Choose a reason for hiding this comment

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

This is really great @jamiehenson I think the code for extracting code from MDX file and formatting is really clever. I wait for @kennethkalmer to have final review for this as the expert. but I only have feedback if it possible

@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy May 2, 2025 09:34 Inactive
Copy link
Contributor

@aralovelace aralovelace left a comment

Choose a reason for hiding this comment

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

til

@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy May 2, 2025 11:58 Inactive
Copy link
Member

@kennethkalmer kennethkalmer left a comment

Choose a reason for hiding this comment

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

That is slick (and sick) @jamiehenson. One of those things where the diff betrays how much work went into it.

Just remember @m-hulbert's ask to revert the actual content changes before merging!

export const onCreatePage: GatsbyNode['onCreatePage'] = ({ page, actions }) => {
const { createPage } = actions;
// Function to extract code element classes from an MDX file
const extractCodeLanguages = async (filePath: string): Promise<Set<string>> => {
Copy link
Member

Choose a reason for hiding this comment

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

This is nice! It would have been super convenient if the raw content of the file was available in onCreatePage, then you could forego all the duplicate IO (just a wishlist item)

};

// Table components with responsive styling
const Table = (props: React.HTMLAttributes<HTMLTableElement>) => (
Copy link
Member

Choose a reason for hiding this comment

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

Better styling is still on the table 🥁 (I'll see myself out now)

@jamiehenson jamiehenson temporarily deployed to ably-docs-web-3888-mdx-xsqhpiy May 2, 2025 12:58 Inactive
@jamiehenson
Copy link
Member Author

The CodeSnippet component was most of the diff for this tbh 😄

@jamiehenson jamiehenson merged commit 4a1b3da into main May 2, 2025
6 checks passed
@jamiehenson jamiehenson deleted the web-3888-mdx branch May 2, 2025 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants