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

Don't render frontmatter for chapters of type "slides" and use standard .md extension #51

Merged
merged 6 commits into from
May 31, 2024

Conversation

raar1
Copy link
Collaborator

@raar1 raar1 commented May 29, 2024

Fixes #32

This PR does two things:

  1. Makes the raw markdown available to the Slides component, which then strips the yaml frontmatter before rendering with reveal.js
  2. Checks the type value in a chapter's frontmatter. If it is "slides" then it goes to the <Slides> component; anything else goes to the standard <ContentRenderer> used by NuxtContent.

This is the result of trying many different ways of achieving this (various examples in Nuxt docs simply don't work as advertised or are too vaguely explained to know why things are silently failing, NuxtContent plugin does not make the raw markdown available after parsing and annoyingly ignores all custom props you might attempt to add in a custom plugin (see e.g. nuxt/content#2056), reveal.js does not want to add the functionality to ignore frontmatter etc etc) so this is the least hacky way I've come up with so far.

Something we should still solve (or clearly put in the documentation if not) regards the way the frontmatter is removed. Currently I regex for the first occurrence of text between "---" separators. As this is the same as the default reveal.js slide separator, there is potential for confusion if users forget to add frontmatter to their chapters (or misformat it somehow) and wonder why the first slide of their presentation is missing. We can either change the default, document it clearly or make the stripFrontmatter() function more intelligent. Not sure what is best.

Note that there are node packages that claim to do the stripping but https://www.npmjs.com/package/front-matter is unmaintained and the replacement, https://www.npmjs.com/package/gray-matter, also seems no longer maintained. I did try gray-matter but got some cryptic error that I think is to do with it assuming it runs in a browser, so breaks when we do SSR. Not sure though.

Anyway, for now it seems to be working, at least locally. We should now test with deployment.

server/plugins/content.ts Show resolved Hide resolved
components/Slides.vue Outdated Show resolved Hide resolved
Copy link
Collaborator

@JaroCamphuijsen JaroCamphuijsen left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks for the work @raar1

@raar1 raar1 merged commit 0eace46 into main May 31, 2024
2 checks passed
@raar1 raar1 deleted the fix_slides_metadata branch May 31, 2024 11:19
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.

Ignore metadata header in reveal js for .pmd files
3 participants