Migrate blog posts from MDX to TSX
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 32/100
- Tipo di issue
- Refactoring
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- next.js, react, typescript
- Ambito
- build-system, content, web-dev
Direzione di ricerca
Inizia leggendo utils/frontmatterTypings.ts, utils/extractFrontMatter.ts, src/utils/blogPosts.tsx e i post generati esistenti dopo aver eseguito generate:all. Traccia come i metadati alimentano il frontmatter generato, i tag, RSS, la sitemap e gli import delle route. Il lavoro è completato quando i post usano metadati TSX tipizzati, l’estrazione e le build funzionano senza la trasformazione MDX e gli script, le regole di ignore e i file sorgente elencati sono aggiornati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
⚠️ DRAFT ISSUE - STILL IN PROGRESS
Current process (context)
Blog posts are written as .mdx files. The build pipeline transforms them before Next.js compiles the app.
Source files:
src/routes/posts/*.mdx— published blog postssrc/routes/drafts/*.mdx— draft postssrc/routes/test/*.mdx— test posts (used by Cypress)
Build scripts (utils/):
utils/transformMdx.ts/utils/transformMdx.bin.ts— compiles MDX →.mjsusing@mdx-js/mdx(converts markdown syntax to JSX, syntax highlighting viarehype-highlight, heading slugs viarehype-slug)utils/extractFrontMatter.ts/utils/extractFrontMatter.bin.ts— parses YAML frontmatter from.mdxfiles, validates against Zod schema, writes JSON files and barrelindex.jsper folderutils/frontmatterTypings.ts— Zod schema (frontMatterSchema) and inferred types (FrontMatter,FrontMatterPlusSlug,EnrichedFrontMatterPlusSlug)utils/generateImageBarrelFiles.ts— scanssrc/assets/and generates image barrel with dimensionsutils/generateRss.ts— generatespublic/rss.xmlfrom frontmatterutils/generateSitemap.ts— generatespublic/sitemap.xml
Generated files (all in .gitignore, recreated on each build):
src/generated/mdx/posts/*.mjs— compiled MDX as JavaScript modulessrc/generated/mdx/drafts/*.mjssrc/generated/mdx/test/*.mjssrc/generated/frontmatter/posts/*.json+index.js— extracted frontmatter per postsrc/generated/frontmatter/drafts/*.json+index.jssrc/generated/frontmatter/test/*.json+index.jssrc/generated/tags.json— maps tag names to post slugssrc/generated/images.js— image barrel with dimensions
Runtime / routing:
src/utils/blogPosts.tsx—getAllPostFrontmatter(),getFrontmatterFromSlug(),getBlogContent(),getMetadata()src/app/posts/[slug]/page.tsx— dynamic route; callsgetBlogContent()to dynamically import the.mjsfromsrc/generated/mdx/posts/src/app/drafts/[slug]/page.tsx— same pattern for draftssrc/app/test/[slug]/page.tsx— same pattern for test postssrc/app/posts/page.tsx— listing page with tag filtering; callsgetAllPostFrontmatter()src/components/BlogPostFrame/— wraps rendered post contentsrc/components/FrontmatterBox/— renders series box, title, date, next-in-series link
Problem
Writing blog posts in MDX lacks TypeScript tooling support:
- No IDE autocomplete for component props
- No type checking in the editor
- Frontmatter YAML has no type enforcement
Solution
Write blog posts as plain .tsx files with two exports:
- A default React component export (the post content)
- A named typed
metadataexport (replacing YAML frontmatter)
Proposed post format
import { defineMetadata } from "@/utils/blog";
export const metadata = defineMetadata({
meta: {
title: "Post Title",
description: "Description.",
dateCreated: "2026-01-01",
// image: "optional_image_key",
},
// series: { name: "my_series", part: 1, description: "My Series" },
tags: ["react"],
});
export default function MyPost() {
return (
<>
<p>Post content here...</p>
</>
);
}
defineMetadata is a simple identity function providing type inference:
export function defineMetadata(m: PostMetadata): PostMetadata { return m; }
PostMetadata should be defined based on the existing FrontMatter type in utils/frontmatterTypings.ts. defineMetadata should live in a new src/utils/blog.ts (or alongside the type).
Migration of existing MDX posts
- Run
generate:all— this compiles all.mdxfiles to.mjsinsrc/generated/mdx/posts/(markdown already converted to JSX by@mdx-js/mdx) - Remove
src/generated/mdx/from.gitignoreand commit those files - Convert the
frontmatterexport in each.mjsto a typedmetadataexport matchingPostMetadata - Rename files from
.mjsto.tsx - Delete the source
.mdxfiles
The existing src/app/posts/[slug]/page.tsx wildcard handler already reads from src/generated/mdx/posts/ via getBlogContent(), so routing requires no changes.
Build pipeline changes
generate:mdxstep can be removed once all.mdxfiles are goneextractFrontMatter.tscurrently reads YAML from.mdxfiles to producesrc/generated/frontmatter/posts/*.json. This must be adapted to instead dynamically import each.tsxfile and read itsmetadataexport, writing the same JSON format. The rest of the pipeline (tags, RSS, sitemap,getAllPostFrontmatter()) stays unchanged.generate:mdxscript andtransformMdx.tscan be deleted once migration is complete
Files to change
utils/extractFrontMatter.ts— adapt to handle.tsxmetadata exportsutils/frontmatterTypings.ts— add/exportPostMetadatatype (or createsrc/types/blog.ts)src/generated/mdx/posts/*.mjs— rename to.tsx, update metadata export.gitignore— removesrc/generated/mdx/package.json— removegenerate:mdxscript once doneutils/transformMdx.ts+utils/transformMdx.bin.ts— delete once done
- Lingua principale
- MDX
- Stelle
- 3
- Fork
- 1
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di dwjohnston/blacksheepcode
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
dwjohnston/blacksheepcode#274 ·
-
Update all dependenciesAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
dwjohnston/blacksheepcode#273 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
dwjohnston/blacksheepcode#272 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
dwjohnston/blacksheepcode#271 ·
-
Update TypeScript to v7 betaAperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
dwjohnston/blacksheepcode#270 ·
Tutte le issue di dwjohnston/blacksheepcode
Issue simili
-
Remove unused ts-node dependencyForse già presa @marcelofukumoto l’ha presa oggi. Apertaarea/dashboard kind/tech-debt QA/None
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 3 giorni
-
electron tech debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
Algorithmiq/monoprop#390 ·
I maintainer di solito rispondono entro 1 giorno
-
Area: Instruments Bug Difficulty: Low Priority: Low
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
DouglasNeuroInformatics/OpenDataCapture#1801 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
callstack/agent-device#3296 ·
I maintainer di solito rispondono entro 1 giorno