From bd17ed0102ca6a80f0c8db5c4c6f999e16447c01 Mon Sep 17 00:00:00 2001 From: LazuliKao Date: Sun, 22 Sep 2024 19:52:29 +0800 Subject: [PATCH 1/3] fix cover --- astro.config.mts | 2 +- src/layouts/MoreTile.astro | 50 +++++++++++++++-------------- src/layouts/Tile.astro | 64 +++++++++++++++++++++++++------------- src/pages/index.astro | 9 +++--- 4 files changed, 76 insertions(+), 49 deletions(-) diff --git a/astro.config.mts b/astro.config.mts index dba5f0e..8b842f5 100644 --- a/astro.config.mts +++ b/astro.config.mts @@ -182,7 +182,7 @@ export default defineConfig({ markdown: { rehypePlugins: pipeline(), syntaxHighlight: "prism", - }, + }, integrations: [ vue(), tailwind(), diff --git a/src/layouts/MoreTile.astro b/src/layouts/MoreTile.astro index 7d2aad2..6a95970 100644 --- a/src/layouts/MoreTile.astro +++ b/src/layouts/MoreTile.astro @@ -5,32 +5,36 @@ const { title, href, cover, tags, date } = Astro.props const dateFormatted = formatDate(date) const type = tags?.[0] ?? "默认" -const image = cover ? cover : "https://oss.nbtca.space/CA-logo.svg" +let image: string + = cover?.url ?? cover ?? "https://oss.nbtca.space/CA-logo.svg" +if (image.startsWith("./")) { + image = `./${href}${image.slice(1)}` +} -const label = `${title} - ${type} - 发表时间 ${dateFormatted}` +const label = `${title} - ${type} - 发表时间 ${dateFormatted}`; --- -
  • + - -
  • + + + diff --git a/src/layouts/Tile.astro b/src/layouts/Tile.astro index 78904f0..ef6daeb 100644 --- a/src/layouts/Tile.astro +++ b/src/layouts/Tile.astro @@ -4,32 +4,54 @@ const { title, href, cover, tags, date, level } = Astro.props const dateFormatted = formatDate(date) const type = tags[0] -const label = `${title} - ${type} - 发表时间 ${dateFormatted}`; +const label = `${title} - ${type} - 发表时间 ${dateFormatted}` +const image = cover?.url ?? cover ?? "https://oss.nbtca.space/CA-logo.svg"; + // level 1: hero // level 2: 2up // level 3: 3up --- -
  • + - - + -
  • +
    + {dateFormatted} +
    + + + diff --git a/src/pages/index.astro b/src/pages/index.astro index 4f1905c..52c3bf0 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -28,7 +28,7 @@ Blogs.sort( href={post.url} date={post.frontmatter.pubDate} tags={post.frontmatter.tags} - cover={post.frontmatter.cover.url} + cover={post.frontmatter.cover} level="1" /> ) @@ -44,7 +44,7 @@ Blogs.sort( href={post.url} date={post.frontmatter.pubDate} tags={post.frontmatter.tags} - cover={post.frontmatter.cover.url} + cover={post.frontmatter.cover} level="2" /> ) @@ -60,7 +60,7 @@ Blogs.sort( href={post.url} date={post.frontmatter.pubDate} tags={post.frontmatter.tags} - cover={post.frontmatter.cover.url} + cover={post.frontmatter.cover} level="3" /> ) @@ -84,7 +84,7 @@ Blogs.sort( href={post.url} date={post.frontmatter.pubDate} tags={post.frontmatter.tags} - cover={post.frontmatter.cover.url} + cover={post.frontmatter.cover} /> ) }) @@ -97,6 +97,7 @@ Blogs.sort( href={post.url} date={post.frontmatter.pubDate} tags={post.frontmatter.tags} + cover={post.frontmatter.cover} /> ) }) From 596d3721593cfc0d6056685f41db3f60965a5792 Mon Sep 17 00:00:00 2001 From: ClasWen Date: Sun, 22 Sep 2024 20:20:58 +0800 Subject: [PATCH 2/3] update action --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 099312f..5dc4909 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,7 @@ name: build-deploy on: push: - branches: ["main", "feature-*"] + branches: ["main", "dev", "feature-*"] paths-ignore: # 忽略的文件 - "README.md" - "LICENSE" From dfa4d132486e3d123819390131905dbd79d92d4b Mon Sep 17 00:00:00 2001 From: LazuliKao Date: Sun, 22 Sep 2024 20:41:33 +0800 Subject: [PATCH 3/3] fix cover --- src/layouts/MoreTile.astro | 7 +++---- src/layouts/Tile.astro | 6 +++++- src/utils/image.ts | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 src/utils/image.ts diff --git a/src/layouts/MoreTile.astro b/src/layouts/MoreTile.astro index 6a95970..638a5ec 100644 --- a/src/layouts/MoreTile.astro +++ b/src/layouts/MoreTile.astro @@ -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}`; diff --git a/src/layouts/Tile.astro b/src/layouts/Tile.astro index ef6daeb..e0af35c 100644 --- a/src/layouts/Tile.astro +++ b/src/layouts/Tile.astro @@ -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 diff --git a/src/utils/image.ts b/src/utils/image.ts new file mode 100644 index 0000000..4226821 --- /dev/null +++ b/src/utils/image.ts @@ -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) + } +}