@mdfriday/foundry
Version:
The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.
303 lines (302 loc) • 8.68 kB
TypeScript
import { Path } from '@internal/domain/paths';
import { Fs, FileMetaInfo, WalkCallback, WalkwayConfig } from '@internal/domain/fs';
import { Result as MarkdownResult, RenderContext, DocumentContext, ParsedContentResult, ContentResult, ParseAndRenderOptions, RenderableDocument, MarkdownRenderer } from '@internal/domain/markdown';
import { Scratch } from '@pkg/maps/scratch';
export interface ComponentPath {
component(): string;
path(): string;
}
export interface Services extends URLService, LangService, FsService, TaxonomyService, MDService {
markdown(): MarkdownRenderer | undefined;
}
export interface MDService {
useInternalRenderer(): boolean;
isWikilinkEnabled(): boolean;
isTagEnabled(): boolean;
isCalloutEnabled(): boolean;
isLatexEnabled(): boolean;
isMermaidEnabled(): boolean;
}
export interface URLService {
baseUrl(): string;
}
export interface FsService {
newFileMetaInfo(filename: string): FileMetaInfo;
newFileMetaInfoWithContent(content: string): FileMetaInfo;
contentFs(): Fs[];
walkContent(fs: Fs, start: string, cb: WalkCallback, conf: WalkwayConfig): Promise<void>;
walkI18n(start: string, cb: WalkCallback, conf: WalkwayConfig): Promise<void>;
}
export interface LangService {
isLanguageValid(lang: string): boolean;
getSourceLang(source: string): [string, boolean];
getLanguageIndex(lang: string): number;
getLanguageByIndex(idx: number): string;
defaultLanguage(): string;
languageIndexes(): number[];
}
export interface TaxonomyService {
views(): TaxonomyView[];
}
export interface TaxonomyView {
singular(): string;
plural(): string;
}
export interface Converter {
convert(dc: DocumentContext, rc: RenderContext): Promise<MarkdownResult>;
parseContent(source: Uint8Array): Promise<ParsedContentResult>;
parseAndRenderContent(source: Uint8Array, options?: ParseAndRenderOptions): Promise<ContentResult>;
prepareRender(source: Uint8Array): Promise<RenderableDocument>;
}
export interface PageIdentity {
identifierBase(): string;
pageLanguage(): string;
pageLanguageIndex(): number;
markStale(): void;
isStale(): boolean;
clearStale(): void;
}
export interface PageSource {
pageIdentity(): PageIdentity;
pageFile(): File;
staleVersions(): number[];
section(): string;
paths(): Path;
path(): string;
slug(): string;
}
export interface FileProvider {
file(): File;
}
export interface Keyword {
toString(): string;
}
export interface IndicesConfig extends Array<IndexConfig> {
}
export interface IndexConfig {
name(): string;
type(): string;
applyFilter(): boolean;
pattern(): string;
weight(): number;
cardinalityThreshold(): number;
toLower(): boolean;
toKeywords(v: any): Promise<Keyword[]>;
}
export interface PageMeta {
description(): string;
params(): Record<string, any>;
pageBaseUrl(): string;
pageWeight(): number;
pageDate(): Date;
publishDate(): Date;
relatedKeywords(cfg: IndexConfig): Promise<Keyword[]>;
shouldList(global: boolean): boolean;
shouldListAny(): boolean;
noLink(): boolean;
organization(): Organization | undefined;
author(): Author | undefined;
menu(): Menu | undefined;
}
export interface PageOutput {
targetFileBase(): string;
targetFilePath(): string;
targetSubResourceDir(): string;
targetPrefix(): string;
content(): Promise<any>;
summary(): Promise<string>;
tableOfContents(): string;
result(): MarkdownResult;
readingTime(): Promise<number>;
wordCount(): Promise<number>;
}
export interface RawContentProvider {
rawContent(): string;
}
export interface PagerManager {
current(): Promise<Pager>;
setCurrent(current: Pager): void;
paginator(): Promise<Pager>;
paginate(groups: PageGroups): Promise<Pager>;
paginate(pages: Pages): Promise<Pager>;
}
export interface Pagers extends Array<Pager> {
}
export interface Pager {
pageNumber(): number;
totalPages(): number;
url(): string;
pages(): Pages;
allPages(): Pages;
pagers(): Pagers;
first(): Pager;
last(): Pager;
hasPrev(): boolean;
prev(): Pager | null;
hasNext(): boolean;
next(): Pager | null;
}
export interface PageGroups extends Array<PageGroup> {
len(): number;
}
export interface PageGroup {
key(): string;
pages(): Pages;
append(page: Page): Pages;
}
export type Pages = Page[];
export interface PageContext {
posOffset(offset: number): Promise<Position>;
}
export interface Page extends RawContentProvider, PageSource, PageMeta, PagerManager, FileProvider, PageContext {
name(): string;
title(): string;
kind(): string;
isHome(): boolean;
isPage(): boolean;
isSection(): boolean;
isAncestor(other: Page): boolean;
eq(other: Page): boolean;
layouts(): string[];
output(): PageOutput;
truncated(): boolean;
parent(): Page | null;
pages(): Promise<Pages>;
prevInSection(): Page | null;
nextInSection(): Page | null;
sections(langIndex: number): Pages;
regularPages(): Promise<Pages>;
regularPagesRecursive(): Pages;
terms(langIndex: number, taxonomy: string): Promise<Pages | null>;
isTranslated(): Promise<boolean>;
translations(): Promise<Pages>;
paths(): Path;
isBundled(): boolean;
scratch(): Scratch;
}
export declare const PageKind: {
readonly PAGE: "page";
readonly HOME: "home";
readonly SECTION: "section";
readonly TAXONOMY: "taxonomy";
readonly TERM: "term";
readonly RSS: "rss";
readonly SITEMAP: "sitemap";
readonly SITEMAP_INDEX: "sitemapindex";
readonly ROBOTS_TXT: "robotstxt";
readonly STATUS_404: "404";
};
export type PageKindType = typeof PageKind[keyof typeof PageKind];
export interface File extends FileOverlap, FileWithoutOverlap {
open(): Promise<any>;
paths(): any;
isBranchBundle(): boolean;
baseFileName(): string;
root(): string;
type(): string;
}
export interface FileOverlap {
relPath(): string;
section(): string;
isZero(): boolean;
}
export interface FileWithoutOverlap {
filename(): string;
dir(): string;
ext(): string;
logicalName(): string;
originalBaseFileName(): string;
baseFileName(): string;
translationBaseName(): string;
contentBaseName(): string;
uniqueID(): string;
fileInfo(): FileMetaInfo;
}
export interface Position {
filename: string;
lineNumber: number;
columnNumber: number;
offset: number;
}
export interface Contact {
email?: string;
address?: string;
phone?: string;
}
export interface Social {
github?: string;
twitter?: string;
linkedin?: string;
[key: string]: string | undefined;
}
export interface OrganizationContact extends Contact {
}
export interface OrganizationSocial extends Social {
}
export interface Organization {
name?: string;
description?: string;
vision?: string;
website?: string;
logo?: string;
contact?: Contact;
social?: Social;
}
export interface Author {
name?: string;
description?: string;
website?: string;
avatar?: string;
contact?: Contact;
social?: Social;
}
export interface MenuItem {
title: string;
url: string;
weight?: number;
children?: MenuItem[];
}
export interface MenuSection {
[sectionName: string]: MenuItem[] | false;
}
export interface Menu {
nav?: MenuItem[] | false;
footer?: MenuSection;
[menuName: string]: MenuItem[] | MenuSection | false | undefined;
}
export interface FrontMatter {
path: string;
lang: string;
kind: string;
title: string;
description: string;
weight: number;
date?: Date;
terms: Record<string, string[]>;
params?: Record<string, any> | undefined;
organization?: Organization;
author?: Author;
menu?: Menu;
}
export interface FrontMatterParser {
params: Record<string, any> | undefined;
langSvc: LangService;
taxonomySvc: TaxonomyService;
}
export interface Template {
execute(templateName: string, data: any): Promise<string>;
}
export type PageBy = (p1: Page, p2: Page) => boolean;
export interface PageSorter {
len(): number;
swap(i: number, j: number): void;
less(i: number, j: number): boolean;
}
export type CollatorStringCompare = (getString: (page: Page) => string, p1: Page, p2: Page) => number;
export interface OrdinalWeightPage {
weight(): number;
ordinal(): number;
page(): Page;
owner(): Page;
}
export type WalkTaxonomyFunc = (taxonomy: string, term: string, page: OrdinalWeightPage) => Promise<void>;