@@ -22,6 +22,7 @@ const cacheHeader = {
22
22
23
23
type MetadataRouteLoaderOptions = {
24
24
page : string
25
+ filePath : string
25
26
isDynamic : '1' | '0'
26
27
}
27
28
@@ -46,7 +47,6 @@ function getContentType(resourcePath: string) {
46
47
return 'text/plain'
47
48
}
48
49
49
- // Strip metadata resource query string from `import.meta.url` to make sure the fs.readFileSync get the right path.
50
50
async function getStaticAssetRouteCode (
51
51
resourcePath : string ,
52
52
fileBaseName : string
@@ -236,33 +236,25 @@ ${staticGenerationCode}
236
236
`
237
237
return code
238
238
}
239
- // `import.meta.url` is the resource name of the current module.
239
+
240
240
// When it's static route, it could be favicon.ico, sitemap.xml, robots.txt etc.
241
241
// TODO-METADATA: improve the cache control strategy
242
242
const nextMetadataRouterLoader : webpack . LoaderDefinitionFunction < MetadataRouteLoaderOptions > =
243
243
async function ( ) {
244
- const { resourcePath } = this
245
-
246
- const { page, isDynamic } = this . getOptions ( )
247
- const { name : fileBaseName } = getFilenameAndExtension ( resourcePath )
244
+ const { page, isDynamic, filePath } = this . getOptions ( )
245
+ const { name : fileBaseName } = getFilenameAndExtension ( filePath )
248
246
249
247
let code = ''
250
248
if ( isDynamic === '1' ) {
251
249
if ( fileBaseName === 'robots' || fileBaseName === 'manifest' ) {
252
- code = getDynamicTextRouteCode ( resourcePath )
250
+ code = getDynamicTextRouteCode ( filePath )
253
251
} else if ( fileBaseName === 'sitemap' ) {
254
- code = await getDynamicSiteMapRouteCode ( resourcePath , page , this )
252
+ code = await getDynamicSiteMapRouteCode ( filePath , page , this )
255
253
} else {
256
- code = getDynamicImageRouteCode ( resourcePath )
254
+ code = getDynamicImageRouteCode ( filePath )
257
255
}
258
256
} else {
259
- console . log (
260
- 'getStaticAssetRouteCode page' ,
261
- page ,
262
- 'this.resourcePath' ,
263
- this . resourcePath
264
- )
265
- code = await getStaticAssetRouteCode ( resourcePath , fileBaseName )
257
+ code = await getStaticAssetRouteCode ( filePath , fileBaseName )
266
258
}
267
259
268
260
return code
0 commit comments