-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
03e24ef
commit 99c1a76
Showing
19 changed files
with
6,889 additions
and
1,409 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 |
---|---|---|
|
@@ -40,3 +40,7 @@ | |
## `netlify_cms` Plugin | ||
|
||
- Renamed to `decap_cms`. | ||
|
||
## `windi_css` Plugin | ||
|
||
- Replaced with `unocss`. |
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,4 @@ | ||
export { createGenerator, type UserConfig } from "npm:@unocss/[email protected]"; | ||
export { presetUno } from "npm:@unocss/[email protected]"; | ||
|
||
export const resetUrl = "https://unpkg.com/@unocss/[email protected]"; |
This file was deleted.
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,106 @@ | ||
import type { DeepPartial, Site } from "../core.ts"; | ||
import { merge, read } from "../core/utils.ts"; | ||
import { Page } from "../core/filesystem.ts"; | ||
import { createGenerator, presetUno, resetUrl } from "../deps/unocss.ts"; | ||
|
||
import type { UserConfig } from "../deps/unocss.ts"; | ||
|
||
export interface Options { | ||
/** | ||
* Configurations for UnoCSS. | ||
* @see {@link https://unocss.dev/guide/config-file} | ||
*/ | ||
config?: UserConfig; | ||
/** | ||
* Set the css filename for all generated styles, | ||
* Set to `false` to insert a <style> tag per page. | ||
* @defaultValue `false` | ||
*/ | ||
cssFile: false | string; | ||
/** | ||
* Supported CSS reset options. | ||
* @see {@link https://github.com/unocss/unocss/tree/main/packages/reset} | ||
* @defaultValue `tailwind` | ||
*/ | ||
reset: false | "tailwind" | "tailwind-compat" | "eric-meyer"; | ||
} | ||
|
||
export const defaults: Options = { | ||
config: { | ||
presets: [presetUno()], | ||
}, | ||
cssFile: false, | ||
reset: "tailwind", | ||
}; | ||
|
||
export default function (userOptions: DeepPartial<Options> = {}) { | ||
const options = merge(defaults, userOptions) as Options; | ||
|
||
return (site: Site) => { | ||
const uno = createGenerator(options.config); | ||
|
||
if (options.cssFile === false) { | ||
// Insert a <style> tag for each page | ||
site.processAll([".html"], async (pages) => { | ||
const reset = await getResetCss(options); | ||
|
||
Promise.all(pages.map(async (page) => { | ||
const document = page.document!; | ||
const result = await uno.generate( | ||
document.documentElement?.innerHTML ?? "", | ||
); | ||
const css = reset ? `${reset}\n${result.css}` : result.css; | ||
|
||
if (css) { | ||
const style = document.createElement("style"); | ||
style.innerText = css; | ||
page.document?.head?.appendChild(style); | ||
} | ||
})); | ||
}); | ||
return; | ||
} | ||
|
||
// Generate the stylesheets for all pages | ||
site.processAll([".html"], async (pages) => { | ||
const classes = new Set<string>(); | ||
|
||
await Promise.all( | ||
pages.map(async (page) => | ||
await uno.generate( | ||
page.document?.documentElement?.innerHTML ?? "", | ||
) | ||
.then((res) => res.matched) | ||
.then((matched) => matched.forEach((match) => classes.add(match))) | ||
), | ||
); | ||
|
||
// Create & merge stylesheets for all pages | ||
const reset = await getResetCss(options); | ||
const result = await uno.generate(classes); | ||
const css = reset ? `${reset}\n${result.css}` : result.css; | ||
|
||
// output css as a page | ||
const exists = site.pages.find((page) => | ||
page.outputPath === options.cssFile | ||
); | ||
|
||
if (exists) { | ||
exists.content += `\n${css}`; | ||
} else { | ||
site.pages.push(Page.create(options.cssFile as string, css)); | ||
} | ||
}); | ||
}; | ||
} | ||
|
||
/** | ||
* TODO: Replace with CSS Modules Import | ||
* @remarks Deno does not currently support CSS Modules. | ||
* @see {@link https://github.com/denoland/deno/issues/11961} | ||
*/ | ||
async function getResetCss(options: Options) { | ||
return options.reset === false | ||
? "" | ||
: await read(`${resetUrl}/${options.reset}.css`, false); | ||
} |
Oops, something went wrong.