-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(generate): generate local file on static generation
- Loading branch information
Showing
6 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { IPX } from 'ipx' | ||
|
||
async function IPXReqHandler (ipx: any, url: string) { | ||
const urlArgs = url.substr(1).split('/') | ||
const format = decodeURIComponent(urlArgs.shift() || '') | ||
const operations = decodeURIComponent(urlArgs.shift() || '') | ||
const src = urlArgs.map(c => decodeURIComponent(c)).join('/') | ||
|
||
|
||
|
||
// Get basic info about request | ||
const info = await ipx.getInfo({ format, operations, src }) | ||
|
||
|
||
|
||
// Process request to get image | ||
const data = await ipx.getData(info) | ||
|
||
// Send image | ||
return data | ||
} | ||
|
||
export default function IPXMiddleware (options: any) { | ||
const ipx = new IPX({ | ||
input: { | ||
adapter: 'fs', | ||
dir: options.dir | ||
}, | ||
}); | ||
return async function IPXMiddleware (url: string) { | ||
return IPXReqHandler(ipx, url) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import consola from 'consola' | ||
|
||
export const logger = consola.withScope('@nuxt/image') |