Merge branch 'dev' into feature-nextui

This commit is contained in:
ClasWen 2024-09-22 21:00:55 +08:00
commit 1de0298e6c
6 changed files with 101 additions and 51 deletions

View file

@ -2,7 +2,7 @@ name: build-deploy
on:
push:
branches: ["main", "feature-*"]
branches: ["main", "dev", "feature-*"]
paths-ignore: # 忽略的文件
- "README.md"
- "LICENSE"

View file

@ -182,7 +182,7 @@ export default defineConfig({
markdown: {
rehypePlugins: pipeline(),
syntaxHighlight: "prism",
},
},
integrations: [
vue(),
tailwind(),

View file

@ -1,36 +1,39 @@
---
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] ?? "默认"
const image = cover ? 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)
}
const label = `${title} - ${type} - 发表时间 ${dateFormatted}`
const label = `${title} - ${type} - 发表时间 ${dateFormatted}`;
---
<li
role="listitem"
class="tile-item item-list nr-scroll-animation"
style="--nr-animation-transform-y:20%;"
<li
role="listitem"
class="tile-item item-list nr-scroll-animation"
style="--nr-animation-transform-y:20%;"
>
<a
href={href}
class="tile tile-list medium-load small-load large-load"
aria-label={label}
>
<a
href={href}
class="tile tile-list medium-load small-load large-load"
aria-label={label}
>
<div class="tile__media" aria-hidden="true">
<img class="cover image" src={image} alt="lt" />
<div class="tile__media" aria-hidden="true">
<img class="cover image" src={image} alt="lt" />
</div>
<div class="tile__description" aria-hidden="true">
<div class="tile__head">
<div class="tile__category">{type}</div>
<div class="tile__headline">{title}</div>
</div>
<div class="tile__description" aria-hidden="true">
<div class="tile__head">
<div class="tile__category">{type}</div>
<div class="tile__headline">{title}</div>
</div>
<div class="tile__timestamp icon-hide icon icon-before icon-clock">
{dateFormatted}
</div>
<div class="tile__timestamp icon-hide icon icon-before icon-clock">
{dateFormatted}
</div>
</a>
</li>
</div>
</a>
</li>

View file

@ -1,35 +1,61 @@
---
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 label = `${title} - ${type} - 发表时间 ${dateFormatted}`
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
// level 3: 3up
---
<li
role="listitem"
class:list={["tile-item", "nr-scroll-animation", { "item-hero": level === "1", "item-2up": level === "2", "item-3up": level === "3" }]}
style="--nr-animation-transform-y:20%;"
<li
role="listitem"
class:list={[
"tile-item",
"nr-scroll-animation",
{
"item-hero": level === "1",
"item-2up": level === "2",
"item-3up": level === "3",
},
]}
style="--nr-animation-transform-y:20%;"
>
<a
href={href}
class:list={[
"tile",
"large-load",
"medium-load",
"small-load",
{
"tile-hero": level === "1",
"tile-2up": level === "2",
"tile-3up": level === "3",
},
]}
aria-label={label}
>
<a
href={href}
class:list={["tile", "large-load", "medium-load", "small-load", { "tile-hero": level === "1", "tile-2up": level === "2", "tile-3up": level === "3" }]}
aria-label={label}
>
<div class="tile__media" aria-hidden="true">
<img class="cover image" src={cover} alt="lt" />
</div>
<div class="tile__media" aria-hidden="true">
<img class="cover image" src={image} alt="lt" />
</div>
<div class="tile__description" aria-hidden="true">
<div class="tile__head">
<div class="tile__category">{type}</div>
<div class="tile__headline">{title}</div>
</div>
<div class="tile__timestamp icon-hide icon icon-before icon-clock">{dateFormatted}</div>
<div class="tile__description" aria-hidden="true">
<div class="tile__head">
<div class="tile__category">{type}</div>
<div class="tile__headline">{title}</div>
</div>
</a>
</li>
<div class="tile__timestamp icon-hide icon icon-before icon-clock">
{dateFormatted}
</div>
</div>
</a>
</li>

View file

@ -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}
/>
)
})

20
src/utils/image.ts Normal file
View 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)
}
}