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

Reverse generating a file #26

Open
qimingweng opened this issue Oct 10, 2015 · 3 comments
Open

Reverse generating a file #26

qimingweng opened this issue Oct 10, 2015 · 3 comments
Labels

Comments

@qimingweng
Copy link

Just curious if there are any plans to support the reverse action; which is to take a object with "attributes" and "body" and return a string to be written to a file?

Or if you would be open to accepting a PR with that functionality.

@jxson
Copy link
Owner

jxson commented Oct 12, 2015

Hi @qimingweng!

Actually yeah, @bcomnes had brought this up in the past in #16. I think it's a good idea, and probably warrants a new major version bump.

Before submitting a PR lets settle on/work out an API for how this would work, some requirements/questions off the top of my head:

  • front-matter should not do any file IO directly, but should interop easily with fs APIs.
  • There was a feature suggestion to support streams (Streaming Support #24), what would a stream API for the "reverse" feature look like?

Do you have a specific use-case in mind? I am curious to learn how you are using front-matter and how you intend to use this new feature.

@qimingweng
Copy link
Author

Ah yes, streams would be the most "ideal" way to do this I suppose, although I'm not sure it would really be that effective. You could always just have everything done in memory but expose it as a stream for people so that the API can be consistent in the future if and when performance really can be sped up with a stream. Or even if it's just to play nice with the read and write file APIs on the fs package. I don't have too much experience actually writing streams.

Something I was thinking about was that all the comments would get lost in the rewrite from object back to YAML... But maybe there can be some kind of proprietary API around that (actually that's probably a bad idea).

Anyway, I use a folder of markdown files as kind of a small database for internal business intelligence. It's much easier for people at the company to understand. I can see times where I would want to automate some of the routine updates or cleaning of the files though - that's where the reverse part of it would happen.

Or if I ever wanted the API to actually write those files back (although if it ever gets that complex I think maybe I would just use a real database).

@jxson jxson added the Feature label Oct 20, 2015
@axdg axdg mentioned this issue Feb 13, 2016
9 tasks
@IonicaBizau
Copy link

This is supported in a module I published recently: https://github.com/IonicaBizau/mdify

It's more related to Markdown world, but for this specific task, it will probably work nicely (see the stringify method):

const mdify = require("mdify");

let md = mdify.stringify({
    author: "Johnny B."
  , date: new Date()
  , tags: ["hello", "world"]
}, `## Hello World!
Hey **there**!`);

console.log(md);
// ---
// author: Johnny B.
// date: 2016-06-06T07:12:17.533Z
// tags:
//   - hello
//   - world
// ---
// ## Hello World!
// Hey **there**!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants