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

feat: change compile option to files #103

Merged
merged 6 commits into from
Jan 4, 2024
Merged

feat: change compile option to files #103

merged 6 commits into from
Jan 4, 2024

Conversation

ignatiusmb
Copy link
Owner

@ignatiusmb ignatiusmb commented Dec 15, 2023

This PR introduces a new option to traverse called files, which replaces compile option, that filters the files in the directory tree and executes the hydrate function, which is now a required parameter.

The HydrateChunk also receives marker as a new passthrough argument for convenience and full control of the renderer.


The compile option in traverse is confusing and hard to differentiate between the compile function that is exported. It also checks if it returns true for a path and.. calls compile with the same hydrate? To make it even more confusing, it checks if the returned data is truthy, else it will.. executes hydrate again (what)?

Okay, the first one which passes it to the compile function wants the content to be rendered to HTML. The !hydrate checking also kind of makes sense in a way that we just want to compile a markdown file and get its content, but in that case it's better to just call the compile function directly without passing in hydrate. For cases where we want to compile all the markdown files in a or multiple directories, we can do them with buffer + parse and now marker.render

import { compile, traverse } from 'marqua/fs';

const data = traverse('content', ({ buffer, marker, parse }) => {
  const { content, metadata } = parse(buffer.toString('utf-8'));
  return { ...metadata, content: marker.render(content) };
});

@ignatiusmb ignatiusmb added the breaking Pull requests that is a breaking change label Dec 15, 2023
@ignatiusmb ignatiusmb added this to the v0.6.0 milestone Dec 15, 2023
Copy link

vercel bot commented Dec 15, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
marqua ✅ Ready (Inspect) Visit Preview Jan 1, 2024 9:58am

@ignatiusmb ignatiusmb merged commit 2bd83a6 into master Jan 4, 2024
11 checks passed
@ignatiusmb ignatiusmb deleted the traverse-files branch January 4, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Pull requests that is a breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant