Skip to content

Commit

Permalink
feat: add md5 content hash (#12)
Browse files Browse the repository at this point in the history
this pr adds an md5 content hash to the reader.
  • Loading branch information
stefanprobst authored Feb 7, 2025
2 parents 650a035 + dbfcccf commit b835c9e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/reader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import assert from "node:assert/strict";
import { createHash } from "node:crypto";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
import { serialize } from "node:v8";

import type { Collection, ComponentSchema, Config, Singleton } from "@keystatic/core";
import { createReader as createLocalReader } from "@keystatic/core/reader";
Expand Down Expand Up @@ -62,10 +64,12 @@ export function createReaders<

async function read(id: string) {
const data = await collectionReader.readOrThrow(id, { resolveLinkedFiles: true });
const md5 = createHash("md5").update(serialize(data)).digest("hex");

return {
collection: name,
id,
md5,
data,
compile(code: string) {
return compile(id, code);
Expand Down

0 comments on commit b835c9e

Please sign in to comment.