UNPKG

@mdfriday/foundry

Version:

The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.

286 lines 9.33 kB
/** * Path processor interface - main entry point for path processing */ export interface PathProcessor { parse(component: string, path: string): Path; parseIdentity(component: string, path: string): StringIdentity; parseBaseAndBaseNameNoIdentifier(component: string, path: string): [string, string]; } /** * Path represents a parsed path with all its components and metadata */ export interface Path extends PathInfo, PathOperations, PathMetadata { /** * Get the unnormalized version of this path (preserves original case) */ unnormalized(): Path; } /** * PathInfo provides basic path information access */ export interface PathInfo { /** Component returns the component for this path (e.g. "content") */ component(): string; /** Path returns the full path */ path(): string; /** Name returns the last element of path */ name(): string; /** NameNoExt returns the last element of path without any extension */ nameNoExt(): string; /** NameNoLang returns the last element of path without any language identifier */ nameNoLang(): string; /** Dir returns all but the last element of path, typically the path's directory */ dir(): string; /** Ext returns the file extension */ ext(): string; /** Lang returns the language identifier */ lang(): string; /** Section returns the first path element (section) */ section(): string; /** Sections returns all section path elements as an array */ sections(): string[]; /** Container returns the base name of the container directory for this path */ container(): string; /** ContainerDir returns the container directory for this path */ containerDir(): string; } /** * PathOperations provides path manipulation operations */ export interface PathOperations { /** Base returns the path without any identifiers for content files */ base(): string; /** BaseNoLeadingSlash returns the base path without the leading slash */ baseNoLeadingSlash(): string; /** BaseNameNoIdentifier returns the logical base name for a resource without any identifier */ baseNameNoIdentifier(): string; /** NameNoIdentifier returns the last element of path without any identifier */ nameNoIdentifier(): string; /** PathNoLang returns the Path but with any language identifier removed */ pathNoLang(): string; /** PathNoIdentifier returns the Path but with any identifier removed */ pathNoIdentifier(): string; /** PathRel returns the path relative to the given owner */ pathRel(owner: Path): string; /** BaseRel returns the base path relative to the given owner */ baseRel(owner: Path): string; /** TrimLeadingSlash returns a copy of the Path with the leading slash removed */ trimLeadingSlash(): Path; /** Identifier returns the identifier at the given index */ identifier(index: number): string; /** Identifiers returns all identifiers */ identifiers(): string[]; } /** * PathMetadata provides metadata about the path */ export interface PathMetadata { /** BundleType returns the bundle type */ bundleType(): PathType; /** IsContent returns true if the path is a content file */ isContent(): boolean; /** IsBundle returns true if this is a bundle */ isBundle(): boolean; /** IsBranchBundle returns true if this is a branch bundle */ isBranchBundle(): boolean; /** IsLeafBundle returns true if this is a leaf bundle */ isLeafBundle(): boolean; /** IsHTML returns true if the extension indicates HTML content */ isHTML(): boolean; /** Disabled returns true if the path is disabled */ disabled(): boolean; /** ForBundleType returns a copy of the path with the specified bundle type */ forBundleType(type: PathType): Path; } /** * StringIdentity represents a unique string identifier for a path */ export interface StringIdentity { identifierBase(): string; } /** * PathType enum represents different types of paths */ export declare enum PathType { /** A generic resource, e.g. a JSON file */ File = 0, /** A resource of a content type with front matter */ ContentResource = 1, /** E.g. /blog/my-post.md */ ContentSingle = 2, /** Leaf bundles, e.g. /blog/my-post/index.md */ Leaf = 3, /** Branch bundles, e.g. /blog/_index.md */ Branch = 4 } /** * PathParser configuration interface */ export interface PathParserConfig { /** Normalize paths to lowercase */ normalize?: boolean; /** Replace spaces with hyphens */ replaceSpaces?: boolean; /** Custom normalization function */ normalizer?: (path: string) => string; } /** * LowHigh represents a range with low and high positions */ export interface LowHigh { low: number; high: number; } /** * PathComponents represents the parsed components of a path */ export interface PathComponents { /** The original path string */ original: string; /** The normalized path string */ normalized: string; /** Position information for various path parts */ positions: PathPositions; /** Parsed identifiers (extensions, language codes, etc.) */ identifiers: LowHigh[]; /** Bundle type if this is a content path */ bundleType: PathType; /** Whether this path is disabled */ disabled: boolean; /** Component type (content, static, layouts, etc.) */ component?: string | undefined; } /** * PathPositions holds position information for different parts of the path */ export interface PathPositions { /** Container directory positions */ containerLow: number; containerHigh: number; /** Section position */ sectionHigh: number; /** Language identifier position */ identifierLanguage: number; } /** * PathNormalizer interface for custom path normalization strategies */ export interface PathNormalizer { normalize(path: string): string; } /** * BasicPathNormalizer provides Hugo's basic normalization rules */ export interface BasicPathNormalizer extends PathNormalizer { /** Normalize to lowercase */ toLowerCase: boolean; /** Replace spaces with hyphens */ replaceSpaces: boolean; } /** * PathValidator interface for validating paths */ export interface PathValidator { validate(path: string): ValidationResult; } /** * ValidationResult represents the result of path validation */ export interface ValidationResult { valid: boolean; errors: string[]; warnings: string[]; } /** * FileExtensionChecker interface for checking file extensions */ export interface FileExtensionChecker { isContentExt(ext: string): boolean; isHTML(ext: string): boolean; hasExt(path: string): boolean; } /** * PathFactory interface for creating Path instances */ export interface PathFactory { create(component: string, path: string, config?: PathParserConfig): Path; createFromComponents(components: PathComponents): Path; } /** * PathPool interface for object pooling to improve performance */ export interface PathPool { get(): Path; put(path: Path): void; } /** * PathVisitor interface for visitor pattern on paths */ export interface PathVisitor<T> { visit(path: Path): T; } /** * PathFilter interface for filtering paths */ export interface PathFilter { accept(path: Path): boolean; } /** * PathTransformer interface for transforming paths */ export interface PathTransformer { transform(path: Path): Path; } /** * Error types for path processing */ export declare class PathError extends Error { readonly path?: string | undefined; constructor(message: string, path?: string | undefined); } export declare class PathParseError extends PathError { constructor(message: string, path?: string); } export declare class PathValidationError extends PathError { readonly validationErrors?: string[] | undefined; constructor(message: string, path?: string, validationErrors?: string[] | undefined); } /** * Utility type for path processing results */ export type PathResult<T> = { success: true; data: T; } | { success: false; error: PathError; }; /** * Constants for common file extensions and patterns */ export declare const PATH_CONSTANTS: { readonly CONTENT_EXTENSIONS: readonly [".md", ".markdown", ".mdown", ".mkd", ".mkdn", ".html", ".htm", ".xml"]; readonly HTML_EXTENSIONS: readonly [".html", ".htm"]; readonly INDEX_NAMES: readonly ["index", "_index"]; readonly PATH_SEPARATOR: "/"; readonly EXTENSION_SEPARATOR: "."; readonly LANGUAGE_SEPARATOR: "."; readonly SYSTEM_PATH_SEPARATOR: any; readonly COMPONENT_FOLDER_CONTENT: "content"; readonly COMPONENT_FOLDER_STATIC: "static"; readonly COMPONENT_FOLDER_LAYOUTS: "layouts"; readonly COMPONENT_FOLDER_ARCHETYPES: "archetypes"; readonly COMPONENT_FOLDER_DATA: "data"; readonly COMPONENT_FOLDER_ASSETS: "assets"; readonly COMPONENT_FOLDER_I18N: "i18n"; readonly normalizePath: (path: string) => string; }; /** * Helper function type for checking if a path has an extension */ export type HasExtFunction = (path: string) => boolean; /** * Helper function type for normalizing path strings */ export type NormalizePathFunction = (path: string) => string; //# sourceMappingURL=type.d.ts.map