Skip to content

Commit ba56852

Browse files
committed
fix
1 parent bf76bd9 commit ba56852

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

packages/site-kit/src/lib/markdown/renderer.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ const theme = createCssVariablesTheme({
2828
fontStyle: true
2929
});
3030

31+
// Hash the contents of this file and its dependencies so that we get a new cache in case we have changed
32+
// how the markdown is rendered (whose logic live here). This is to avoid serving stale code snippets.
3133
const hash = createHash('sha256');
3234
hash.update(fs.readFileSync('../../pnpm-lock.yaml', 'utf-8'));
33-
hash_graph(hash, fileURLToPath(import.meta.url));
35+
// CAREFUL: update this URL in case you ever move this file or start the dev/build process from another directory
36+
const original_file = '../../packages/site-kit/src/lib/markdown/renderer.ts';
37+
if (fs.existsSync(original_file)) {
38+
throw new Error('Update the path to the markdown renderer code. Current value: ' + original_file);
39+
}
40+
hash_graph(hash, fileURLToPath(original_file));
3441
const digest = hash.digest().toString('base64').replace(/\//g, '-');
35-
console.log('hash is', digest);
3642

3743
/**
3844
* Utility function to work with code snippet caching.
@@ -85,8 +91,6 @@ async function create_snippet_cache() {
8591
if (fs.existsSync(file)) {
8692
snippet = fs.readFileSync(file, 'utf-8');
8793
cache.set(source, snippet);
88-
} else {
89-
console.log('cache miss');
9094
}
9195
}
9296

@@ -195,9 +199,7 @@ export async function render_content_markdown(
195199
const headings: string[] = [];
196200
const { check = true } = options ?? {};
197201

198-
const time = Date.now();
199-
200-
const res = await transform(body, {
202+
return await transform(body, {
201203
async walkTokens(token) {
202204
if (token.type === 'code') {
203205
if (snippets.get(token.text)) return;
@@ -321,11 +323,6 @@ export async function render_content_markdown(
321323
return `<blockquote>${content}</blockquote>`;
322324
}
323325
});
324-
325-
if (!filename.startsWith('<two'))
326-
console.log('rendering ', filename, 'took', Date.now() - time, 'ms');
327-
328-
return res;
329326
}
330327

331328
/**
@@ -566,7 +563,6 @@ function find_nearest_node_modules(file: string): string | null {
566563
function hash_graph(hash: Hash, file: string, seen = new Set<string>()) {
567564
if (seen.has(file)) return;
568565
seen.add(file);
569-
console.log('including', file, 'in hash');
570566

571567
const content = fs.readFileSync(file, 'utf-8');
572568

0 commit comments

Comments
 (0)