UNPKG

@stacksjs/stx

Version:

A performant UI Framework. Powered by Bun.

157 lines 4.65 kB
/** * Generate static site */ export declare function generateStaticSite(options?: SSGConfig): Promise<SSGResult>; /** * Create ISR handler for runtime revalidation */ export declare function createISRHandler(options?: SSGConfig): { get: (route: string) => Promise<{ html: string; headers: Record<string, string> } | null> revalidate: (route: string) => Promise<void> invalidate: (route: string | RegExp) => Promise<void> }; /** * Define static paths for dynamic routes (used in templates) */ export declare function defineStaticPaths(pathsFn: () => Promise<StaticPath[]> | StaticPath[]): () => Promise<StaticPathsResult>; /** * Create a markdown content loader */ export declare function createMarkdownLoader(): ContentLoader; // ============================================================================= // Types // ============================================================================= export declare interface SSGConfig { pagesDir?: string outputDir?: string baseUrl?: string domain?: string revalidate?: number | false sitemap?: boolean rss?: boolean | RSSConfig concurrency?: number cache?: boolean cacheDir?: string contentLoaders?: ContentLoader[] hooks?: SSGHooks minify?: boolean generate404?: boolean publicDir?: string trailingSlash?: boolean cleanOutput?: boolean } export declare interface RSSConfig { title: string description: string link: string language?: string copyright?: string getItems?: () => Promise<RSSItem[]> } export declare interface RSSItem { title: string link: string description?: string pubDate?: Date author?: string categories?: string[] guid?: string } export declare interface StaticPath { params: Record<string, string> props?: Record<string, unknown> revalidate?: number | false } export declare interface StaticPathsResult { paths: StaticPath[] fallback?: 'blocking' | 'static' | false } export declare interface ContentLoader { name: string extensions: string[] load: (filePath: string) => Promise<ContentResult> } export declare interface ContentResult { content: string data: Record<string, unknown> toc?: TocItem[] } export declare interface TocItem { id: string text: string level: number children?: TocItem[] } export declare interface SSGHooks { onBuildStart?: () => void | Promise<void> onBuildEnd?: (result: SSGResult) => void | Promise<void> onPageStart?: (route: string) => void | Promise<void> onPageEnd?: (route: string, html: string) => void | Promise<void> onError?: (error: Error, route?: string) => void | Promise<void> } export declare interface SSGResult { totalPages: number successCount: number failedCount: number cachedCount: number buildTime: number sitemapPath?: string rssPath?: string pages: PageResult[] errors: PageError[] } export declare interface PageResult { route: string outputPath: string size: number cached: boolean revalidateAt?: number } export declare interface PageError { route: string error: Error } export declare interface ISRCache { get: (route: string) => Promise<CachedPage | null> set: (route: string, page: CachedPage) => Promise<void> invalidate: (route: string) => Promise<void> invalidatePattern: (pattern: RegExp) => Promise<void> needsRevalidation: (route: string) => Promise<boolean> } export declare interface CachedPage { html: string generatedAt: number revalidateAfter: number etag: string headers?: Record<string, string> } declare class BuildCache { private cacheDir: string; private cache: Map<string, BuildCacheEntry>; private loaded: any; constructor(cacheDir: string); load(): Promise<void>; save(): Promise<void>; getHash(filePath: string, dependencies: string[]): string; get(route: string, filePath: string, dependencies: string[]): string | null; set(route: string, filePath: string, dependencies: string[], html: string): void; } // ============================================================================= // ISR Cache Implementation // ============================================================================= declare class FileISRCache implements ISRCache { private cacheDir: string; constructor(cacheDir: string); private getFilePath(route: string): string; get(route: string): Promise<CachedPage | null>; set(route: string, page: CachedPage): Promise<void>; invalidate(route: string): Promise<void>; invalidatePattern(pattern: RegExp): Promise<void>; needsRevalidation(route: string): Promise<boolean>; } export default { generateStaticSite, createISRHandler, defineStaticPaths, createMarkdownLoader, };