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: add option to output document as raw string #1280

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/keystatic/src/reader/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ export type MinimalFs = {
fileExists(path: string): Promise<boolean>;
};

const decoder = new TextDecoder();

async function getAllEntries(
parent: string,
fsReader: MinimalFs
Expand Down Expand Up @@ -350,7 +352,7 @@ const readItem = cache(async function readItem(
}
if (schema.formKind === 'content') {
contentFieldPathsToEagerlyResolve?.push(path);
return async () => {
return async (options?: { raw: boolean }) => {
let content: undefined | Uint8Array;
const filename =
pathWithArrayFieldSlugs.join('/') + schema.contentExtension;
Expand All @@ -362,6 +364,10 @@ const readItem = cache(async function readItem(
undefined;
}

if (options?.raw) {
return decoder.decode(content);
}

return schema.reader.parse(value, { content });
};
}
Expand Down