UNPKG

@mdfriday/foundry

Version:

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

166 lines (165 loc) 4.96 kB
import { Page as ContentPage, PageSource, WalkTaxonomyFunc } from '../content/type'; import { ReadableStream } from 'stream/web'; import { Fs } from '../fs/type'; export interface Services extends ContentService, TranslationService, ResourceService, LanguageService, FsService, URLService, ConfigService, SitemapService { } export interface ConfigService { configParams(): Record<string, any>; siteTitle(): string; menus(): Record<string, Menu[]>; baseUrl(): string; isGoogleAnalyticsEnabled(): boolean; googleAnalyticsID(): string; isGoogleAnalyticsRespectDoNotTrack(): boolean; isDisqusEnabled(): boolean; disqusShortname(): string; isXRespectDoNotTrack(): boolean; isXDisableInlineCSS(): boolean; getConfiguredSocialPlatforms(): string[]; getSocialLink(platformId: string): string; getSocialTitle(platformId: string): string; } export interface ContentService { walkPages(langIndex: number, walker: WalkFunc): Promise<void>; getPageSources(page: ContentPage): Promise<PageSource[]>; walkTaxonomies(langIndex: number, walker: WalkTaxonomyFunc): Promise<void>; globalPages(langIndex: number): Promise<ContentPage[]>; globalRegularPages(): Promise<ContentPage[]>; searchPage(pages: ContentPage[], page: ContentPage): Promise<ContentPage[]>; getPageFromPath(langIndex: number, path: string): Promise<ContentPage | null>; getPageFromPathSync(langIndex: number, path: string): ContentPage | null; getPageRef(context: ContentPage, ref: string, home: ContentPage): Promise<ContentPage | null>; } export interface TranslationService { translate(lang: string, translationID: string): string; } export interface ResourceService { getResource(path: string): Promise<Resource | null>; getResourceWithOpener(path: string, opener: OpenReadSeekCloser): Promise<Resource>; } export interface LanguageService { defaultLanguage(): string; languageKeys(): string[]; getLanguageIndex(lang: string): number; getLanguageName(lang: string): string; } export interface SitemapService { changeFreq(): string; priority(): number; generateSitemap(): Promise<{ urls: any[]; }>; } export type WalkFunc = (page: ContentPage) => Promise<void>; export interface Menu { name(): string; url(): string; weight(): number; } export interface Resource { name(): string; readSeekCloser(): Promise<ReadableStream<Uint8Array>>; targetPath(): string; } export type OpenReadSeekCloser = () => Promise<ReadableStream<Uint8Array>>; export interface FsService { publishFs(): Fs; staticFs(): Fs; copyStaticFiles(from: Fs, to: Fs): Promise<void>; workingDir(): string; } export interface URLService { baseUrl(): string; } export interface Author { name(): string; email(): string; } export interface Organization { name(): string; description(): string; website(): string; } export interface Compiler { version(): string; environment(): string; } export interface Site { currentLanguage: string; baseURL(): string; } export interface RefArgs { path: string; outputFormat: string; } export interface RefSite { home: { page: ContentPage; }; sitePage(target: ContentPage): Promise<SitePage>; } export interface SitePage { relPermalink(): string; permalink(): string; path?(): string; } export interface PageWrapper { unwrapPage(): ContentPage; } export interface Position { isValid(): boolean; toString(): string; } export interface Positioner { position(): Position; } export interface Menus { [key: string]: any; } export interface BaseURL { protocol(): string; host(): string; hostname(): string; port(): string; pathname(): string; toString(): string; getRoot(path: string): string; basePathNoTrailingSlash: string; } export interface URLSite { baseURL(): BaseURL; absURL(input: string): string; relURL(input: string): string; url: any; languagePrefix(): string; isMultipleLanguage(): boolean; } export interface Language { location(): string; collator(): Collator; } export interface Collator { compare(a: string, b: string): number; } export interface URL { base: string; absURL(input: string): string; relURL(input: string): string; urlize(uri: string): string; } export interface Template { lookupLayout(names: string[]): Promise<{ preparer: TemplatePreparer; found: boolean; }>; executeWithContext(preparer: TemplatePreparer, data: any): Promise<string>; } export interface TemplatePreparer { name(): string; execute(data: any): Promise<string>; } export interface ContentSpec { preparePages(): Promise<void>; renderPages(handler: RenderHandler): Promise<void>; } export type RenderHandler = (kind: string, sections: string[], dir: string, name: string, content: string) => Promise<void>;