-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be84abb
commit c05e519
Showing
10 changed files
with
159 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 1.1.24 | ||
|
||
- Cleanup | ||
|
||
## 1.1.23 | ||
|
||
- Switches ownership | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import type { AstroIntegration } from "astro"; | ||
import type { Options } from "files-pipeline/dist/options/lib/critters/index.js"; | ||
import type { Options } from "./options/index.js"; | ||
declare const _default: (options?: Options) => AstroIntegration; | ||
export default _default; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,4 @@ | ||
import type { Options as CrittersOptions } from "critters"; | ||
export default interface CRITTERS extends CrittersOptions { | ||
[key: string]: any; | ||
} |
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,8 @@ | ||
import type CRITTERS from "./critters.js"; | ||
import type { Options as OptionsBase } from "files-pipeline/dist/options/index.js"; | ||
export interface Options extends OptionsBase { | ||
[key: string]: any; | ||
critters?: boolean | CRITTERS; | ||
} | ||
declare const _default: Options; | ||
export default _default; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,13 +1,98 @@ | ||
import type { AstroIntegration } from "astro"; | ||
|
||
import { pipeline } from "files-pipeline"; | ||
import type { Options } from "files-pipeline/dist/options/lib/critters/index.js"; | ||
|
||
export default (options: Options = {}): AstroIntegration => ({ | ||
name: "astro-critters", | ||
hooks: { | ||
"astro:build:done": async () => { | ||
await new pipeline(options).critters(); | ||
import type { | ||
executions, | ||
optionPath, | ||
} from "files-pipeline/dist/options/index.js"; | ||
|
||
import type { Options } from "./options/index.js"; | ||
|
||
import defaults from "./options/index.js"; | ||
|
||
import { fileURLToPath } from "url"; | ||
|
||
import applyTo from "files-pipeline/dist/lib/apply-to.js"; | ||
import deepmerge from "files-pipeline/dist/lib/deepmerge.js"; | ||
|
||
import { files } from "files-pipeline"; | ||
|
||
// critters | ||
// @ts-ignore | ||
import Critters from "critters"; | ||
|
||
export default (options: Options = {}): AstroIntegration => { | ||
for (const option in options) { | ||
if ( | ||
Object.prototype.hasOwnProperty.call(options, option) && | ||
options[option] === true | ||
) { | ||
options[option] = defaults[option]; | ||
} | ||
} | ||
|
||
options = deepmerge(defaults, options); | ||
|
||
const paths = new Set<optionPath>(); | ||
|
||
if (typeof options["path"] !== "undefined") { | ||
if ( | ||
options["path"] instanceof Array || | ||
options["path"] instanceof Set | ||
) { | ||
for (const path of options["path"]) { | ||
paths.add(path); | ||
} | ||
} else { | ||
paths.add(options["path"]); | ||
} | ||
} | ||
|
||
return { | ||
name: "astro-critters", | ||
hooks: { | ||
"astro:build:done": async () => { | ||
for (const path of paths) { | ||
const _path = await applyTo(path, (url: URL | string) => | ||
url instanceof URL ? fileURLToPath(url) : url | ||
); | ||
|
||
const critters = new Critters( | ||
deepmerge(options["critters"], { | ||
path: | ||
_path instanceof Map | ||
? _path.keys().next().value | ||
: _path, | ||
logLevel: (() => { | ||
switch (options["logger"]) { | ||
case 0: | ||
return "silent"; | ||
// rome-ignore lint/nursery/noPrecisionLoss: | ||
case 1: | ||
return "silent"; | ||
// rome-ignore lint/nursery/noPrecisionLoss: | ||
case 2: | ||
return "info"; | ||
default: | ||
return "info"; | ||
} | ||
})(), | ||
}) | ||
); | ||
|
||
await ( | ||
await ( | ||
await ( | ||
await new files(options["logger"]).in(path) | ||
).by("**/*.html") | ||
).not(options["exclude"]) | ||
).pipeline( | ||
deepmerge(defaults["pipeline"], { | ||
wrote: async (current) => | ||
critters.process(current.buffer), | ||
} satisfies executions) | ||
); | ||
} | ||
}, | ||
}, | ||
}, | ||
}); | ||
}; | ||
}; |
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,7 @@ | ||
// @ts-ignore | ||
import type { Options as CrittersOptions } from "critters"; | ||
|
||
export default interface CRITTERS extends CrittersOptions { | ||
// rome-ignore lint/suspicious/noExplicitAny: | ||
[key: string]: any; | ||
} |
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 defaults from "files-pipeline/dist/options/index.js"; | ||
import deepmerge from "files-pipeline/dist/lib/deepmerge.js"; | ||
|
||
import type CRITTERS from "./critters.js"; | ||
|
||
import type { Options as OptionsBase } from "files-pipeline/dist/options/index.js"; | ||
|
||
export interface Options extends OptionsBase { | ||
// rome-ignore lint/suspicious/noExplicitAny: | ||
[key: string]: any; | ||
|
||
critters?: boolean | CRITTERS; | ||
} | ||
|
||
export default deepmerge(defaults, { | ||
critters: { | ||
preload: "media", | ||
inlineFonts: true, | ||
compress: true, | ||
pruneSource: true, | ||
}, | ||
pipeline: { | ||
failed: async (current) => | ||
`Error: Cannot inline file ${current.inputPath}!`, | ||
fulfilled: async (pipe) => | ||
pipe.files > 0 | ||
? `Successfully inlined a total of ${pipe.files} HTML ${ | ||
pipe.files === 1 ? "file" : "files" | ||
}.` | ||
: false, | ||
accomplished: false, | ||
}, | ||
} satisfies Options) as Options; |