mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
Clean up plugin
This commit is contained in:
@@ -39,22 +39,10 @@ async function loadImageAndConvertToRgba(path: string) {
|
|||||||
let image;
|
let image;
|
||||||
// console.log(path, extname(path))
|
// console.log(path, extname(path))
|
||||||
if (extname(path) === ".svg") {
|
if (extname(path) === ".svg") {
|
||||||
|
const svg = await readFile(imgPath);
|
||||||
if (await exists(imgPath)) {
|
const resvg = new Resvg(svg)
|
||||||
const svg = await readFile(imgPath);
|
const render = resvg.render()
|
||||||
const resvg = new Resvg(svg)
|
image = await loadImage(render.asPng())
|
||||||
const render = resvg.render()
|
|
||||||
image = await loadImage(render.asPng())
|
|
||||||
} else {
|
|
||||||
throw new TypeError("Could not resolve image source!")
|
|
||||||
// Try URI decode path?
|
|
||||||
// console.log(decodeURIComponent(imgPath))
|
|
||||||
// const svg = await readFile(decodeURIComponent(imgPath));
|
|
||||||
// const resvg = new Resvg(svg)
|
|
||||||
// const render = resvg.render()
|
|
||||||
// image = await loadImage(render.asPng())
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// canvas handles all file loading for us
|
// canvas handles all file loading for us
|
||||||
image = await loadImage(imgPath)
|
image = await loadImage(imgPath)
|
||||||
@@ -116,11 +104,12 @@ const extToMimeTypeMap: Record<OutputExtension, MimeType> = {
|
|||||||
webp: 'image/webp',
|
webp: 'image/webp',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const blurRE = /(?:\?|&)th(umb)?(?:&|$)/
|
||||||
const isThumbHash = (id: string) => {
|
const isThumbHash = (id: string) => {
|
||||||
return id.endsWith('?th') || id.endsWith('?thumb')
|
return !!id.match(blurRE)
|
||||||
}
|
}
|
||||||
|
|
||||||
const cleanId = (id: string) => decodeURIComponent(id.replace('?thumb', '').replace('?th', ''))
|
const cleanId = (id: string) => id.replace(blurRE, '')
|
||||||
|
|
||||||
const buildViteAsset = (referenceId: string) => `__VITE_ASSET__${referenceId}__`
|
const buildViteAsset = (referenceId: string) => `__VITE_ASSET__${referenceId}__`
|
||||||
|
|
||||||
@@ -167,14 +156,9 @@ const thumbHash = (options: Options = {}): Plugin => {
|
|||||||
if (!filter(id)) {
|
if (!filter(id)) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id.includes("Design")) {
|
|
||||||
console.log('raw', id)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isThumbHash(id)) {
|
if (isThumbHash(id)) {
|
||||||
const cleanedId = cleanId(id)
|
const cleanedId = cleanId(id)
|
||||||
console.log('clean', cleanedId)
|
|
||||||
|
|
||||||
if (config.command === 'serve') {
|
if (config.command === 'serve') {
|
||||||
if (devCache.has(id)) {
|
if (devCache.has(id)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user