Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Conversation

@gpichot
Copy link

@gpichot gpichot commented Sep 8, 2022

Hello,

Back Story: I really like Spectacle to write slides as MDX content. I am not really satisfied with the output though as I can't style slides or have different layouts. The Deck templateFn property has a deceiving name :).
To give even more context: I have around 400-500 slides that I use for professional workshops.
Yesterday, I started playing a bit with this repository to add support for custom layouts.

It's a bit similar to what does Slidev: layouts.

It adds support to parse slides starting with layout: as frontmatter content that is passed to the next slide using MDXContent.

---

layout: sidedImage
image: ./assets/provider-to-consumer.svg

---

### Context is provided **by the closest Provider ancestor**

---

The frontmatter content is retrieved to change the layout using the MDXProvider and custom components property:

const componentsMap = {
  wrapper: (props: any) => {
    const { children, frontmatter } = props;
    const { layout = 'default' } = (frontmatter || {}) as { layout: string };
    if (layout && layout in Layouts) {
      const Layout = Layouts[layout as keyof typeof Layouts];
      return <Layout {...frontmatter}>{children}</Layout>;
    }
    return children;
  },
}

export const MarkdownDeck = ({ slides, notes }: MarkdownDeckProps) => {
  return (
    <MDXProvider components={componentsMap}>
      <Deck>
        {slides.map((MDXSlide, i: number) => {
          const MDXNote = notes[i];
          return (
            <Slide key={`slide-${i}`}>
              <MDXSlide />
              <Notes>
                <MDXNote />
              </Notes>
            </Slide>
          );
        })}
      </Deck>
    </MDXProvider>
  );
};

In the end, I wrote around 10 layouts that fit my needs and one of them looks like this when outputted:

image

Do you think this PR could be something provided by default? (I can also add some configuration to the loader).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant