import{SourceFile}from"file/classes";import{readFile}from"file";import{Path}from"utils/path";importtype{PageSettings}from"../../types/site";import{File}from"file/classes";import{wrapFile}from"../classes/utils";classHTMLFileextendsSourceFile{staticfiletypes=["html","htm","svg"];/** * Write a file to a path at the provided config location. * When writing the html file, * we also write the non-html file if the file was faked. */write(config: PageSettings){const{ sourceDir, targetDir }=config;consttargetPath=this.path.relativeTo(sourceDir,targetDir);targetPath.writeString(this.text(config));returnthis;}/** * Create an HTML file from path. */staticcreate(filePath: Path,cfg: PageSettings){// If we have the html, just return itif(filePath.exists()){returnnewHTMLFile(filePath,cfg);}// Otherwise, try to get the non-html version of the file.// if the path is a directory, this won't work;// we then get the containing directory if this fails.// NOTE: This is a special case.// To solve this in a systemic way, we'll need toconstpath=filePath.replaceExtension();letprevFile: File;try{prevFile=readFile(path,cfg);}catch(e){constdirectoryPath=filePath.parent;prevFile=readFile(directoryPath,cfg);}returnwrapFile(prevFileasSourceFile,// the function is available on all children of the file// @ts-ignore(f: File)=>f?.asHtml?.(cfg)?.toString()??"",{extension: "html",addExtension: true,mimeType: "text/html",},(file,settings: PageSettings)=>{// @ts-ignorereturnfile?.asHtml?.(settings)?.dependencies()??[];});}/** * Find the dependencies of the HTML file. * * The dependencies of an html file are the internal links * in the file's html. */dependencies(settings: PageSettings){returnthis.asHtml(settings).dependencies();}}exportdefaultHTMLFile;