@analogjs/vite-plugin-nitro
Version:
A Vite plugin for adding a nitro API server
57 lines (56 loc) • 2.32 kB
TypeScript
import { PrerenderContentFile } from '../options';
/**
* Discovers content files with front matter and extracts metadata for prerendering.
*
* This function:
* 1. Discovers all content files matching the specified glob pattern
* 2. Reads each file and parses front matter metadata
* 3. Extracts file name, extension, and path information
* 4. Returns structured data for prerendering content pages
*
* @param workspaceRoot The workspace root directory path
* @param rootDir The project root directory relative to workspace
* @param glob The glob pattern to match content files (e.g., 'content/blog')
* @returns Array of PrerenderContentFile objects with metadata and front matter
*
* Example usage:
* const contentFiles = getMatchingContentFilesWithFrontMatter(
* '/workspace',
* 'apps/my-app',
* 'content/blog'
* );
*
* Sample discovered file paths:
* - /workspace/apps/my-app/content/blog/first-post.md
* - /workspace/apps/my-app/content/blog/2024/01/hello-world.md
* - /workspace/apps/my-app/content/blog/tech/angular-v17.mdx
* - /workspace/apps/my-app/content/blog/about/index.md
*
* Sample output structure:
* {
* name: 'first-post',
* extension: 'md',
* path: 'content/blog',
* attributes: { title: 'My First Post', date: '2024-01-01', tags: ['intro'] }
* }
*
* tinyglobby vs fast-glob comparison:
* - Both support the same glob patterns for file discovery
* - Both are efficient for finding content files
* - tinyglobby is now used instead of fast-glob
* - tinyglobby provides similar functionality with smaller bundle size
* - tinyglobby's globSync returns absolute paths when absolute: true is set
*
* Front matter parsing:
* - Uses front-matter library to parse YAML/TOML front matter
* - Extracts metadata like title, date, tags, author, etc.
* - Supports both YAML (---) and TOML (+++) delimiters
* - Returns structured attributes for prerendering
*
* File path processing:
* - Normalizes paths for cross-platform compatibility
* - Extracts file name without extension
* - Determines file extension for content type handling
* - Maintains relative path structure for routing
*/
export declare function getMatchingContentFilesWithFrontMatter(workspaceRoot: string, rootDir: string, glob: string, recursive?: boolean): PrerenderContentFile[];