Skip to content

Commit ae599c4

Browse files
committed
feat: Add auto-generated comments to reference MDX files
1 parent c362b85 commit ae599c4

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/layouts/ReferenceItemLayout.astro

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,12 @@ const descriptionParts = description.split(
283283
entry.data.file && entry.data.line &&(
284284
<div class="my-xl">
285285
<div class="text-body [&_a]:text-type-magenta-dark [&_a]:!decoration-type-magenta-dark my-lg">
286-
Notice any errors or typos? <a href ="https://github.com/processing/p5.js/issues">Please let us know</a>. Please feel free to edit
286+
This page is generated from the comments in
287287
<a
288288
href={`https://github.com/processing/p5.js/blob/v${p5Version}/${entry.data.file}#L${entry.data.line}`}
289289
>
290290
{entry.data.file}
291-
</a>
292-
and open a pull request!
291+
</a>. Feel free to edit it and submit a pull request!
293292
</div>
294293
</div>
295294
)

src/scripts/builders/reference.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { sanitizeName } from "../utils";
1818
import path from "path";
1919
import { load } from "cheerio";
2020
import he from "he";
21+
import { p5Version } from "../../globals/p5-version";
2122

2223
/* Base path for the content directory */
2324
const prefix = "./src/content/reference/en/";
@@ -290,14 +291,19 @@ const convertToMDX = async (
290291
);
291292

292293
try {
294+
// Add YAML comment to the frontmatter
295+
const comment = `# This file was auto-generated. Please do not edit it manually!\n# To make changes, edit the comments in the corresponding source file:\n# https://github.com/processing/p5.js/blob/v${p5Version}/${doc.file}#L${doc.line}`;
296+
293297
// Convert the frontmatter to a string
294298
const frontmatter = matter.stringify("", frontMatterArgs);
299+
const frontmatterWithComment = frontmatter.replace('---\n', `---\n${comment}\n`);
300+
295301
// Stores the body of the MDX file
296302
const markdownContent = `# ${sanitizeName(doc.name)}\n`;
297303
// Convert the markdown content to MDX
298304
const mdxContent = remark().use(remarkMDX).processSync(markdownContent);
299305
// Return the full MDX file as a string
300-
return `${frontmatter}\n${mdxContent.toString()}`;
306+
return `${frontmatterWithComment}\n${mdxContent.toString()}`;
301307
} catch (err) {
302308
console.error(`Error converting ${doc.name} to MDX: ${err}`);
303309
return;

0 commit comments

Comments
 (0)