UNPKG

markugen

Version:

Markdown to HTML/PDF static site generation tool

218 lines (217 loc) 6.07 kB
import Markugen, { MarkugenOptions } from './markugen'; import { HtmlOptions } from './htmloptions'; import Generator from './generator'; export * from './themes'; export * from './preprocessor'; export * from './page'; export * from './htmloptions'; export default class HtmlGenerator extends Generator { /** * The name of the markugen generated files */ static readonly markugenFiles: { js: { out: string; template: string; }; css: { out: string; template: string; }; }; /** * Regular expression used for Markugen commands */ static readonly cmdRegex: RegExp; /** * Used to generate ids the same each time */ static globalId: number; /** * Contains the options that were given on construction */ readonly options: Required<HtmlOptions>; /** * Path to the templates */ readonly templates: string; /** * Generated sitemap */ private sitemap; /** * The html files that were generated */ private generated; /** * JavaScript to embed in each page */ private script; /** * CSS to embed in each page */ private style; /** * Assets to copy over */ private assets; /** * The preprocessor to use for template expansion */ private preprocessor; /** * Constructs a new generator with the given markugen options */ constructor(mark: Markugen, options: HtmlOptions & MarkugenOptions); /** * Generates the documentation. * @returns the paths to all generated pages, the html if format === 'string', or * undefined if an error occurred */ generate(): string | string[] | undefined; /** * Clears all assets from the last run */ clearAssets(): void; /** * @returns true if the input given is a single file */ get isInputFile(): boolean; /** * @returns true if the input given is a string */ get isInputString(): boolean; /** * @returns true if the input is a string or file */ get isInputSolo(): boolean; /** * @returns the path to the input or the string input */ get input(): string; /** * @returns the path to the input directory */ get inputDir(): string; /** * @returns the path to the output directory */ get output(): string; /** * @returns true if hidden files and folders should be included */ get includeHidden(): boolean; /** * @returns true if the output should be cleared first */ get clearOutput(): boolean; /** * Checks to see if the path is excluded. * @param file the path to check for exclusion * @returns true if the path is excluded, false otherwise */ isExcluded(file: string): boolean; /** * Validates the options and makes changes where necessary */ protected validate(): void; /** * Checks that the files are relative to the input directory and filters * out the ones that are not. Also resolves each path. * @param paths the file(s) to check for relativeness * @param file if true, checks that the input is a file * @returns the file(s) with non-existing removed and fully resolved paths */ private filterInput; /** * Checks the validity of the excluded files */ private checkExcluded; /** * Checks the validity of the assets */ private checkAssets; /** * Resolves the paths and stats on assets * @param assets the assets to filter * @param where where to place the resolved assets * @param copy whether these assets should be copied */ private resolveAssets; /** * Sets the appropriate themes based on the given values * @param themes the provided themes */ private setTheme; /** * Prepares the generator */ private prepare; /** * Copies the assets to the output directory */ private writeAssets; /** * Copies a single asset to the output directory * @param asset the asset to copy */ private writeAsset; /** * Writes and sets the styles */ private writeScripts; /** * Writes and sets the styles */ private writeStyles; /** * Removes the input key from the given page * @param page the page to update * @returns the page with the key removed */ private removeInput; /** * Adds the children for the given page in the given directory * @param dir the directory to add children from * @param parent the parent page */ private addChildren; /** * Adds a child to the given parent * @param parent the parent to add the child to * @param entry the entry details for the child * @param config the config if it has one * @returns the page that was added or already there and the entry name */ private addChild; /** * Returns true if the given file matches the provided extensions * @param file the file to check * @returns true if the given file matches the provided extensions */ private isMarkdown; /** * Looks for a file matching the given name in the given directory * @param dir the parent directory to look in * @param name the name of the file to look for * @returns details about the file if found */ private entry; /** * Creates the html for the children of the given page * @param parent the parent page * @returns the html or file path for the first child */ private writeChildren; /** * Creates the html file for the given page * @param page the page for the markdown file * @returns the file path or the html as a string, undefined * if nothing was created */ private writeHtml; /** * @returns the title for the given file or directory */ private title; }