@@ -56,6 +56,7 @@ export interface StaticBuildOptions {
5656 dryRun ?: boolean
5757 check ?: boolean
5858 ignoredPaths ?: string [ ]
59+ pathRemaps ?: Record < string , string >
5960 baseURL ?: string
6061
6162 logger ?: {
@@ -190,11 +191,20 @@ function getLayouts(inputDirectory: string): Templates {
190191 return templates
191192}
192193
194+ function replaceStart ( text : string , searchValue : string , replaceValue : string ) : string {
195+ if ( text . startsWith ( searchValue ) ) {
196+ return replaceValue + text . slice ( searchValue . length )
197+ }
198+
199+ return text
200+ }
201+
193202function shouldSkipFilePath (
194203 relativeFilePath : string ,
195204 ignoredPaths : string [ ] = [ ] ,
196205) : [ shouldSkip : boolean , reason : string ] {
197206 const filename = path . basename ( relativeFilePath )
207+ if ( filename === "_config.js" ) return [ false , "" ]
198208 if ( filename . startsWith ( "_" ) ) return [ true , "underscore_prefix" ]
199209
200210 for ( const ignoredPath of ignoredPaths || [ ] ) {
@@ -912,13 +922,20 @@ export default async function staticbuild(options: StaticBuildOptions) {
912922
913923 options . logger ?. time ( "Write" )
914924
925+ const pathRemaps : Exclude < StaticBuildOptions [ "pathRemaps" ] , undefined > = options . pathRemaps || { }
926+
915927 for ( const [ _ , file ] of outputFiles ) {
916928 const buffer : Buffer < ArrayBuffer > = isExternalFile ( file )
917929 ? Buffer . from ( fs . readFileSync ( file . inputPath ) )
918930 : file . buffer
919931
932+ for ( const [ from , to ] of Object . entries ( pathRemaps ) ) {
933+ file . outputPath = replaceStart ( file . outputPath , from , to )
934+ }
935+
920936 if ( options . dryRun ) {
921937 options . logger ?. info ( "[fake_file_write]" )
938+
922939 if ( isExternalFile ( file ) ) {
923940 options . logger ?. info ( " in: " + file . inputPath )
924941 } else {
0 commit comments