1- import { createReadStream } from 'fs' ;
1+ import { createReadStream } from 'fs'
22import { resolve , join } from 'path'
3- import { config } from " @/config" ;
3+ import { config } from ' @/config'
44import { load_json_abs } from '@/libs/utils.js'
5- import { exists , file_mime } from '@/libs/assets.js'
5+ import { file_mime } from '@/libs/assets.js'
66import { remove_base } from '@/libs/assets.js'
77
8- export async function GET ( { params} ) {
8+ export async function GET ( { params, props } ) {
99 if ( config . copy_assets ) {
1010 return new Response ( 'Not supported and not needed with copy_assets = true' , { status : 404 } ) ;
1111 }
12+ console . log ( `\nassets> props.asset.path '${ props . asset . path } '` )
1213 let imagePath = resolve ( join ( config . content_path , params . path ) ) ;
13- if ( params . path . startsWith ( "/" ) ) {
14- imagePath = resolve ( join ( config . rootdir , "public" , params . path ) ) ;
15- }
1614 imagePath = remove_base ( imagePath )
17- //due to a markdown limitation, abs assets are stripped of starting '/' in linux
18- //workaround : if the file does not exist, then try the public
19- if ( ! await exists ( imagePath ) ) {
20- imagePath = resolve ( join ( config . rootdir , "public" , params . path ) ) ;
21- }
22- if ( ! await exists ( imagePath ) ) {
23- console . log ( `\nassets> * NOT FOUND ${ params . path } ` )
24- } else {
25- console . log ( `\nassets> serving '${ imagePath } '` )
15+ if ( props . asset . path . startsWith ( "/" ) ) {
16+ const asset = props . asset
17+ if ( asset . exists ) {
18+ imagePath = asset . abs_path
19+ }
2620 }
21+ console . log ( `assets> serving '${ imagePath } '` )
2722 try {
2823 const stream = createReadStream ( imagePath ) ;
2924 const contentType = file_mime ( imagePath )
@@ -42,10 +37,13 @@ export async function getStaticPaths(){
4237 }
4338
4439 const asset_list = await load_json_abs ( join ( config . collect_content . outdir , 'asset_list.json' ) )
45- const paths = asset_list . filter ( ( asset ) => (
40+ const assets = asset_list . filter ( ( asset ) => (
4641 ( ( asset . type != "link" ) && ( Object . hasOwn ( asset , "path" ) ) ) ||
4742 ( ( asset . type == "link" ) && ( ! asset . external ) && asset . filter_ext ) )
48- ) . map ( ( entry ) => ( entry . path ) )
49- console . log ( `serving API endpoit ${ paths . length } assets` )
50- return paths . map ( ( path ) => ( { params :{ path :path } } ) )
43+ ) . map ( ( entry ) => ( entry ) )
44+ console . log ( `serving API endpoit ${ assets . length } assets` )
45+ return assets . map ( ( asset ) => ( {
46+ params :{ path :asset . path } ,
47+ props :{ asset}
48+ } ) )
5149}
0 commit comments