New Rendering Pipeline for Vocabulary Collection using Unified and Rehype

Summary

Implemented a new rendering pipeline for the vocabulary collection using the unified ecosystem (remark/rehype) to process markdown content with enhanced Astro features. This change improves the handling of special markdown formats and provides better type safety.

Technical Details

Core Components

  1. Dynamic Route Handler (site/src/pages/more-about/[vocabulary].astro):
typescript
import unified from 'unified';
import remarkParse from 'remark-parse';
import remarkAsf from '@utils/markdown/remark-asf';

// Process content with custom remark plugin
const processedContent = await unified()
  .use(remarkParse)
  .use(remarkAsf, { markdownFile: entry.id })
  .process(entry.body);
  1. Custom Remark Plugin (site/src/utils/markdown/remark-asf.ts):
typescript
export default function remarkAsf(options?: RemarkAsfOptions): Plugin<[], Root, Root> {
  if (!options?.markdownFile) {
    throw new Error('markdownFile is required for remarkAsf plugin');
  }

  return function () {
    return async function (tree: Root): Promise<Root> {
      // Transform markdown AST with enhanced Astro features
    };
  };
}

Key Changes

  1. Type Safety Improvements:
    • Added proper TypeScript configurations for module resolution
    • Implemented strict typing for unified plugin chain
    • Enhanced error handling with proper type checks
  2. Unified Pipeline Integration:
    • Integrated remark-parse for initial markdown parsing
    • Added custom remarkAsf plugin for Astro-specific transformations
    • Set up proper plugin composition with unified ecosystem
  3. Component Integration:
    • Connected with OneArticle and OneArticleOnPage components
    • Proper prop typing for content passing
    • Structured error handling for missing entries

Impact

  • Improved markdown processing reliability
  • Better type safety across the rendering pipeline
  • Enhanced maintainability through modular plugin architecture
  • Consistent handling of special markdown formats
  • site/src/pages/more-about/[vocabulary].astro
  • site/src/utils/markdown/remark-asf.ts
  • site/tsconfig.json

Dependencies

  • unified
  • remark-parse
  • remark-rehype
  • mdast-util-to-markdown