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

Fragment plugin #354

Merged
merged 13 commits into from
May 19, 2023
Merged

Fragment plugin #354

merged 13 commits into from
May 19, 2023

Conversation

lilyvc
Copy link
Contributor

@lilyvc lilyvc commented May 10, 2023

Summary

A plugin that enables the embedding of pages into pages using the syntax :fragment{src="path-to-fragment"}

This PR

@lilyvc lilyvc requested a review from a team as a code owner May 10, 2023 14:29
@changeset-bot
Copy link

changeset-bot bot commented May 10, 2023

⚠️ No Changeset found

Latest commit: 0dfd4d3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@lilyvc lilyvc marked this pull request as draft May 10, 2023 14:29
@vercel
Copy link

vercel bot commented May 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mosaic ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 19, 2023 10:30am

@coveralls
Copy link

coveralls commented May 10, 2023

Pull Request Test Coverage Report for Build 5023338253

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 63.019%

Totals Coverage Status
Change from base Build 4982472198: 0.0%
Covered Lines: 1278
Relevant Lines: 1773

💛 - Coveralls

@lilyvc lilyvc linked an issue May 10, 2023 that may be closed by this pull request
@DavieReid
Copy link
Contributor

This is really cool @lilyvc. Nice work!

@lilyvc lilyvc requested a review from tomhazledine May 11, 2023 10:32
@lilyvc lilyvc marked this pull request as ready for review May 18, 2023 15:38

## Use Cases

Fragments offer various use cases, such as:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

Here is another example, where the fragment files each contain a `<Tile>` component.

```
:fragment{src="../fragments/tile-a.mdx"} :fragment{src="../fragments/tile-b.mdx"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be nice to use a regex here to include all files in the fragments dir

The below code snippet will render the content from the content-fragment.mdx file in your target file:

```
:fragment{src="../fragments/content-fragment.mdx"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be interested to see what happens when the content fragment uses a meta data expression. Does it render the correct meta data?

Copy link
Contributor

@DavieReid DavieReid May 19, 2023

Choose a reason for hiding this comment

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

Just tried this, it does render but it's rendering int he context of the page "host" page and not the fragment page.

So if you edit the content-fragment.mdx page like:

- ### Fragment title
+ #### {meta.title}

You should see the title of that section on the Fragments page be Content Fragment but what you get is Fragments

One for a follow up

@@ -20,7 +20,7 @@ const ReadingTimePlugin: PluginType<ReadingTimePluginPage> = {
async $afterSource(pages) {
const processor = unified().use(markdown);
for (const page of pages) {
const tree = await processor.parse(page.content);
const tree: any = await processor.parse(page.content);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should have type Node. It's already being used in the file

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.

Content Refs
4 participants