-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Custom output formatter #5848
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
Labels
area: formats
pinned
type: feature
code contributing to the implementation of a feature and/or user facing functionality
Comments
Closed
Anything else required before the PR/build could be approved? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hello I am recent activity. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area: formats
pinned
type: feature
code contributing to the implementation of a feature and/or user facing functionality
Is your feature request related to a problem? Please describe.
I'm setting up Netlify CMS for a mostly-static site, written in Next.js and TypeScript. None of the output types seem quite right for the project:
md
: requires using a frontmatter parser, either at build time or runtime - and what's parsed will be typed asany
toml
: similar to aboveyaml
: similar to abovejson
: can be directlyimport
-ed and will be strongly-typed, so this is the best option for right now. But multiline markdown blobs are hard to read, compared tomd
oryaml
And for all of the above, any markdown has to be run through a markdown-to-jsx type library (we're currently using markdown-to-jsx).
All of the above problems are surmountable, and most likely even without perf hits, by some combination of babel, webpack, and static-page-generation. But it feels like there's a trick being missed, because any processing needed of the content could be done when it's generated, rather than leaving it to build-time or runtime, either server-side or client-side.
Describe the solution you'd like
The output that would probably be most useful for our team specifically would be something like a data-only typescript file:
But of course, that's very project-specific. It depends on the
strip-indent
library, which is fine for our team, but isn't in general. So I'm not proposing netlify-cms include a typescript formatter. But it'd be great if you could let us define our own. I'm imagining an API something like:This formatter would then be inferred for pages with
file: foobar.ts
.The actual API of a formatter is really nice and simple (I'm basing this on the json example) so it's easy to imagine users being able to get pretty creative with how the output file gets persisted, to make sure it's a combination of human-readable and useful for the project it lives in.
If users wanted to, they could even do markdown processing in the
toFile
function to build up a ready-to-render AST.Describe alternatives you've considered
Conceivably this could be done by wrapping an existing backend but that seems more invasive and scary. There might also be a way to do this already, I haven't found it in the docs though.
There might also be a hacky way to do
window.CMS.something.formatters.toFile = ...
but I'm not familiar enough with the codebase to know how/whether formatters are exposed.Additional context
I'm new to Netlify CMS, so please let me know if I'm thinking about things in The Wrong Way.
The text was updated successfully, but these errors were encountered: