|
| 1 | +## AGENTS |
| 2 | + |
| 3 | +Purpose: Help AI coding agents work productively in this Gatsby (v5) + MDX (v2) blog. |
| 4 | + |
| 5 | +Big picture |
| 6 | +- Static site built with Gatsby 5.x, content in `content/blog/**/index.md` (MDX). Images live next to posts. |
| 7 | +- Programmatic pages are created in `gatsby-node.ts` using GraphQL over MDX nodes; custom fields `fields.slug` and `fields.postPath` are added in `onCreateNode` and used across templates. |
| 8 | +- Main templates live in `src/templates/` (blog-post, blog-page, tag-page, author-page). Shared UI in `src/components/`. |
| 9 | +- Site config and plugin wiring in `gatsby-config.js`. Two filesystem sources (`content/blog`, `content/assets`). MDX is configured with remark plugins (images, prism, etc.). |
| 10 | + # AGENTS |
| 11 | + |
| 12 | +Purpose: Help AI coding agents work productively in this Gatsby (v5) + MDX (v2) blog. |
| 13 | + |
| 14 | +Big picture |
| 15 | + |
| 16 | +- Static site built with Gatsby 5.x, content in `content/blog/**/index.md` (MDX). Images live next to posts. |
| 17 | + |
| 18 | +- Programmatic pages are created in `gatsby-node.ts` using GraphQL over MDX nodes; custom fields `fields.slug` and `fields.postPath` are added in `onCreateNode` and used across templates. |
| 19 | + |
| 20 | +- Main templates live in `src/templates/` (blog-post, blog-page, tag-page, author-page). Shared UI in `src/components/`. |
| 21 | + |
| 22 | +- Site config and plugin wiring in `gatsby-config.js`. Two filesystem sources (`content/blog`, `content/assets`). MDX is configured with remark plugins (images, prism, etc.). |
| 23 | +# AGENTS |
| 24 | + |
| 25 | +Purpose: Help AI coding agents work productively in this Gatsby (v5) + MDX (v2) blog. |
| 26 | + |
| 27 | +Big picture |
| 28 | + |
| 29 | +- Static site built with Gatsby 5.x, content in `content/blog/**/index.md` (MDX). Images live next to posts. |
| 30 | + |
| 31 | +- Programmatic pages are created in `gatsby-node.ts` using GraphQL over MDX nodes; custom fields `fields.slug` and `fields.postPath` are added in `onCreateNode` and used across templates. |
| 32 | + |
| 33 | +- Main templates live in `src/templates/` (blog-post, blog-page, tag-page, author-page). Shared UI in `src/components/`. |
| 34 | + |
| 35 | +- Site config and plugin wiring in `gatsby-config.js`. Two filesystem sources (`content/blog`, `content/assets`). MDX is configured with remark plugins (images, prism, etc.). |
| 36 | + |
| 37 | +Key workflows |
| 38 | + |
| 39 | +- Install deps: `npm ci` (use Node 18+). |
| 40 | + |
| 41 | +- Dev server: `npm run develop` (hot-reload preview while editing content/components). |
| 42 | + |
| 43 | +- Build: `npm run build` then preview: `npm run serve` (site at <http://localhost:9000>). |
| 44 | + |
| 45 | +- Test script: `npm run test` runs lint then build. Lint uses ESLint 8 with `.eslintrc` (flat config is NOT used here). |
| 46 | + |
| 47 | +Project-specific conventions |
| 48 | + |
| 49 | +- Posts are MDX files at `content/blog/<slug>/index.md` with frontmatter: `title`, `date` (ISO8601), `author`, optional `featuredImage`, `description` for home excerpts. See README for examples. |
| 50 | + |
| 51 | +- Author metadata in `content/authors.json`; author images resolved to `content/assets/authors/<key>.jpg`. If missing, `gatsby-node.ts` downloads GitHub avatar at build time using global `fetch` and writes to that path. |
| 52 | + |
| 53 | +- GraphQL usage relies on custom `fields` on `Mdx` nodes (set in `gatsby-node.ts`). Templates query `fields { slug, postPath }` and `frontmatter { ... }`. When creating new templates/queries, ensure those fields exist or add similar fields in `onCreateNode`. |
| 54 | + |
| 55 | +- Pagination: `gatsby-node.ts` creates `/page/1..N`; index shows up to 10 posts, template queries use `$skip`/`$limit`. |
| 56 | + |
| 57 | +- RSS: only generated in production (`npm run build && npm run serve`). |
| 58 | + |
| 59 | +Important files |
| 60 | + |
| 61 | +- `gatsby-node.ts`: page creation, tag pages, author pages, MDX fields. Uses Node 18 global `fetch` and `fs.promises.writeFile(new Uint8Array(...))` when downloading author avatars. |
| 62 | + |
| 63 | +- `gatsby-config.js`: plugins & site metadata; MDX/remark configuration; Google Analytics; feed; typography. |
| 64 | + |
| 65 | +- `src/templates/*.js`: GraphQL queries + rendering logic per page type. |
| 66 | + |
| 67 | +- `src/components/*`: Layout, SEO, ArticlePreview, Byline, Tags, Comments, etc. |
| 68 | + |
| 69 | +- `content/`: blog posts and assets; authors.json. |
| 70 | + |
| 71 | +Patterns to follow |
| 72 | + |
| 73 | +- When adding GraphQL fields to `Mdx`, define them in `onCreateNode` (slug, postPath). All templates assume these fields are present. |
| 74 | + |
| 75 | +- Use `internal.contentFilePath` when creating pages for MDX (`?__contentFilePath=`) to enable MDX rendering. |
| 76 | + |
| 77 | +- For author pages, ensure each author key in `authors.json` maps to a `.jpg` in `content/assets/authors/` or the avatar fetch will run at build time. |
| 78 | + |
| 79 | +- Keep queries in templates in sync with the schema defined by the plugins and the fields created in `gatsby-node.ts`. |
| 80 | + |
| 81 | +Common pitfalls |
| 82 | + |
| 83 | +- If you see GraphQL errors like “Cannot query field 'fields' on type 'Mdx'”, check `onCreateNode` in `gatsby-node.ts` is creating those fields and that Gatsby is picking up the TS node file (it is, via `gatsby-node.ts`). Run `npm run clean` before `npm run build` after changes. |
| 84 | + |
| 85 | +- Do not upgrade React to v19 or MDX to v3 without coordinating upgrades to Gatsby v6+ and `gatsby-plugin-mdx` v6+. This repo is pinned to Gatsby 5.x with MDX v2. |
| 86 | + |
| 87 | +- ESLint 8 with `.eslintrc` is the current setup; ESLint 9 flat config caused parsing issues. Update only if necessary, and migrate carefully. |
| 88 | + |
| 89 | +Examples |
| 90 | + |
| 91 | +- Creating a new blog post: add `content/blog/hello-world/index.md` with frontmatter, optional images; run `npm run develop`, verify at `/` and `/page/2`. |
| 92 | + |
| 93 | +- Linking to posts: use `node.fields.postPath` provided by `gatsby-node.ts` when building lists (see `src/templates/blog-page.js`). |
| 94 | + |
| 95 | +Local commands (copy/paste) |
| 96 | + |
| 97 | +- Install: `npm ci` |
| 98 | + |
| 99 | +- Dev: `npm run develop` |
| 100 | + |
| 101 | +- Clean + build: `npm run clean && npm run build` |
| 102 | + |
| 103 | +- Preview build: `npm run serve` (<http://localhost:9000>) |
| 104 | + |
| 105 | +Maintainer notes for agents |
| 106 | + |
| 107 | +- Prefer minimal, surgical changes. Avoid upgrading major versions unless explicitly requested. |
| 108 | + |
| 109 | +- When changing GraphQL, run a clean build to regenerate `.cache/schema.gql` and catch schema issues early. |
| 110 | + |
| 111 | +Azure note |
| 112 | + |
| 113 | +- If asked to generate Azure code or commands, follow the Azure best-practices tool guidance available in your environment. |
| 114 | + |
| 115 | +Contribution flow |
| 116 | + |
| 117 | +- Create feature branches from `master` (or the working update branch if collaborating). |
| 118 | + |
| 119 | +- Validate locally before PR: |
| 120 | + |
| 121 | + - `npm ci` |
| 122 | + |
| 123 | + - `npm run test` (runs lint + build) |
| 124 | + |
| 125 | + - Optional: `npm run serve` and verify key pages (/, /page/2, a post, /tags/{tag}, /author/{key}). |
| 126 | + |
| 127 | +- Keep changes minimal; avoid dependency major bumps unless the PR is dedicated to that effort. |
| 128 | + |
| 129 | +- In PRs, call out changes to GraphQL queries/templates and any content structure updates. |
| 130 | +Maintainer notes for agents |
| 131 | + |
| 132 | +- Prefer minimal, surgical changes. Avoid upgrading major versions unless explicitly requested. |
| 133 | + |
| 134 | +- When changing GraphQL, run a clean build to regenerate `.cache/schema.gql` and catch schema issues early. |
| 135 | + |
| 136 | +Azure note |
| 137 | + |
| 138 | +- If asked to generate Azure code or commands, follow the Azure best-practices tool guidance available in your environment. |
| 139 | + |
| 140 | +Contribution flow |
| 141 | + |
| 142 | +- Create feature branches from `master` (or the working update branch if collaborating). |
| 143 | + |
| 144 | +- Validate locally before PR: |
| 145 | + |
| 146 | + - `npm ci` |
| 147 | + |
| 148 | + - `npm run test` (runs lint + build) |
| 149 | + |
| 150 | + - Optional: `npm run serve` and verify key pages (/, /page/2, a post, /tags/<tag>, /author/<key>). |
| 151 | + |
| 152 | +- Keep changes minimal; avoid dependency major bumps unless the PR is dedicated to that effort. |
| 153 | + |
| 154 | +- In PRs, call out changes to GraphQL queries/templates and any content structure updates. |
0 commit comments