File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed
Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @cesarlai/picgo-plugin-filename-format" ,
3- "version" : " 0.1.1 " ,
3+ "version" : " 0.1.2 " ,
44 "author" : " Cesar Lai" ,
55 "description" : " A picgo plugin to format filename by your setting." ,
66 "main" : " dist/index.js" ,
Original file line number Diff line number Diff line change @@ -12,13 +12,18 @@ const createUploader = (): IPlugin => {
1212 const fullConfig = parsePluginSetting ( config )
1313 ctx . output = ctx . output . map ( ( img ) => {
1414 const imgOutputPath = path . resolve ( fullConfig . public , img . fileName )
15- fs . writeFileSync ( imgOutputPath , img . buffer , {
16- flag : 'r'
17- } )
15+ if ( ! fs . existsSync ( path . dirname ( imgOutputPath ) ) )
16+ fs . mkdirSync ( path . dirname ( imgOutputPath ) )
1817
19- const imgUrl = path . resolve ( '/' , img . fileName )
18+ fs . writeFileSync ( imgOutputPath , img . buffer )
19+
20+ const imgUrl = [
21+ '/' ,
22+ img . fileName . replace ( / ^ (?: \\ | \/ ) | (?: \\ | \/ ) $ / g, '' )
23+ ] . join ( '' )
2024 img . imgUrl = imgUrl
2125 img . url = imgUrl
26+
2227 return img
2328 } )
2429
Original file line number Diff line number Diff line change @@ -12,7 +12,10 @@ const DefaultPluginSetting: Readonly<PluginSetting> = {
1212export const parsePluginSetting = (
1313 setting : PluginSetting | undefined
1414) : PluginSetting => {
15- return setting ?. format ? setting : DefaultPluginSetting
15+ return {
16+ ...DefaultPluginSetting ,
17+ ...setting
18+ }
1619}
1720
1821export const getExt = ( fileName : string ) => {
You can’t perform that action at this time.
0 commit comments