mirror of
https://github.com/m1ngsama/FUJI.git
synced 2025-12-25 02:56:38 +00:00
fix cover
This commit is contained in:
parent
eae0eb03fa
commit
dfa4d13248
3 changed files with 28 additions and 5 deletions
|
|
@ -1,14 +1,13 @@
|
|||
---
|
||||
import { formatDate } from "../utils"
|
||||
const { title, href, cover, tags, date } = Astro.props
|
||||
|
||||
import { fixImage } from "../utils/image"
|
||||
const dateFormatted = formatDate(date)
|
||||
const type = tags?.[0] ?? "默认"
|
||||
|
||||
let image: string
|
||||
= cover?.url ?? cover ?? "https://oss.nbtca.space/CA-logo.svg"
|
||||
let image = cover?.url ?? cover ?? "https://oss.nbtca.space/CA-logo.svg"
|
||||
if (image.startsWith("./")) {
|
||||
image = `./${href}${image.slice(1)}`
|
||||
image = await fixImage(image, href)
|
||||
}
|
||||
|
||||
const label = `${title} - ${type} - 发表时间 ${dateFormatted}`;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
---
|
||||
import { formatDate } from "../utils"
|
||||
const { title, href, cover, tags, date, level } = Astro.props
|
||||
import { fixImage } from "../utils/image"
|
||||
|
||||
const dateFormatted = formatDate(date)
|
||||
const type = tags[0]
|
||||
const label = `${title} - ${type} - 发表时间 ${dateFormatted}`
|
||||
const image = cover?.url ?? cover ?? "https://oss.nbtca.space/CA-logo.svg";
|
||||
let image = cover?.url ?? cover ?? "https://oss.nbtca.space/CA-logo.svg"
|
||||
if (image.startsWith("./")) {
|
||||
image = await fixImage(image, href)
|
||||
}
|
||||
|
||||
// level 1: hero
|
||||
// level 2: 2up
|
||||
|
|
|
|||
20
src/utils/image.ts
Normal file
20
src/utils/image.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { getImage } from "astro:assets"
|
||||
|
||||
export async function fixImage(image: string, href: string) {
|
||||
try {
|
||||
const sliceHref = href.slice(0, href.lastIndexOf("/") + 1)// get the dir of the current page(remove filename)
|
||||
const imageLocation = await import(
|
||||
/* @vite-ignore */ `/src/pages${sliceHref}${image.slice(1)}`
|
||||
)// static import of the image
|
||||
image = imageLocation.default
|
||||
return (
|
||||
await getImage({ // resolve the images
|
||||
src: image,
|
||||
inferSize: true,
|
||||
})
|
||||
).src
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue