Skip to content

Enhancement: Support Creation of "new" .mdx content items #218

Closed

Description

@farmerau

Is your feature request related to a problem? Please describe.
As someone who exclusively uses MDX for content creation (as well as FrontMatter) I'm frustrated when creating new content because I need to change the file extension manually to support my workflow-- despite the plugin generally supporting FrontMatter in MDX files.

Describe the solution you'd like
In ArticleHelper, the createContent method hard-codedly decides that the file extension should be ".md". Similarly, this happens in template generation as well.

I'd propose this be determined via a frontmatter setting.

Describe alternatives you've considered

  • Manually changing the file extension on my own every time I create new content (not preferred)
  • Creating a field to the content type template definitions in frontMatter.taxonomy.contentTypes per @zivbk1 here.
  • Respecting the file extension for template files per @zivbk1 here

Additional context
I would anticipate a change like this would be fully backwards compatible, as the default extension should remain ".md".

I'm happy to open a PR to address this once there's some buy-in.

Activity

  1. zivbk1 commented on Jan 3, 2022

    @zivbk1

    It seems like this could be a field in the content type template definition frontMatter.taxonomy.contentTypes.
    Adding an 'extension' variable with the string for what the file extension should be for that type.

    Another option is to respect the file extension for a template file in the .frontmatter/templates folder.
    https://frontmatter.codes/docs/content-types#creating-a-template

  2. farmerau commented on Jan 3, 2022

    @farmerau
    ContributorAuthor

    @zivbk1 I agree that these are also great alternatives. Updated description.

  3. estruyf commented on Jan 4, 2022

    @estruyf
    Owner

    @farmerau fair point! This should be a configuration by the template from which you create the content or from the content type. This needs to be enhanced on both ends.

  4. added a commit that references this issue on Jan 4, 2022
  5. estruyf commented on Jan 4, 2022

    @estruyf
    Owner

    @farmerau I have added better mdx support for content creation. Things that changed:

    • When creating content from a template, it will use the file extension of the template.
    • When creating content for a content type, it will use the defined file type md | mdx. This is a new property (optional) on the frontMatter.taxonomy.contentTypes setting called fileType.
    • When creating content for a content type, it will check if it has a defined file type, if not, it uses the new frontMatter.content.defaultFileType setting for the file type to create. This setting is by default set to md, but if you change it to mdx, all new content will be created as mdx files. The benefit of this setting is that you only need to specify it once, and all content types will use it.

    This is now available in the beta version. Feel free to give it a try, and let me know how it works for you. Beta version can be found here: https://marketplace.visualstudio.com/items?itemName=eliostruyf.vscode-front-matter-beta

    Info: In order to use the beta, you have to uninstall the main version. Nothing will be lost, it is just a limitation of VS Code.

  6. farmerau commented on Jan 4, 2022

    @farmerau
    ContributorAuthor

    @estruyf I pulled the latest Beta down and can confirm setting frontMatter.content.defaultFileType behaved as expected.

    One odd thing I noticed is that the documentation for the setting doesn't appear to be loading via tooltip-- I'm not sure if that's due to caching or the way that the beta is built:

    For example, a previously existing setting:

    frontmatter.content.fmHighlight with tooltip

    The new setting:
    frontMatter.content.defaultFileType with no tooltip

    Thanks for the super quick turnaround on this-- I'd totally be happy to contribute in the future.

  7. estruyf commented on Jan 4, 2022

    @estruyf
    Owner

    That is normal, as the documentation and site still need to be updated. Will be for when I finalize the next release.

  8. farmerau commented on Jan 4, 2022

    @farmerau
    ContributorAuthor
  9. added this to the 5.10.0 milestone on Jan 7, 2022
  10. estruyf commented on Jan 10, 2022

    @estruyf
    Owner

    Released in v5.10.0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions