Skip to content

Commit 900d55e

Browse files
committed
合并主分支
1 parent af1534c commit 900d55e

7 files changed

Lines changed: 71 additions & 33 deletions

File tree

packages/pure/components/advanced/GithubCard.astro

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const [owner, repoName] = repo.split('/')
2121
>
2222
<div
2323
id='gh-avatar'
24-
class='gh-text me-2 size-7 flex-shrink-0 bg-cover sm:size-8'
24+
class='load-block me-2 size-7 flex-shrink-0 bg-cover sm:size-8'
2525
style='border-radius:999px'
2626
>
2727
</div>
@@ -39,9 +39,9 @@ const [owner, repoName] = repo.split('/')
3939
<Icon name='github' />
4040
</div>
4141
</div>
42-
<p id='gh-description' class='gh-text text-sm sm:text-base'>Waiting for api.github.com...</p>
42+
<p id='gh-description' class='load-block text-sm sm:text-base'>Waiting for api.github.com...</p>
4343
<div class='flex items-center justify-between gap-x-2'>
44-
<div class='gh-text flex flex-wrap items-center gap-x-3 gap-y-1 sm:gap-x-5'>
44+
<div class='load-block flex flex-wrap items-center gap-x-3 gap-y-1 sm:gap-x-5'>
4545
<div class='flex items-center gap-x-1.5 sm:gap-x-2'>
4646
{/* mingcute:star-line */}
4747
<!-- prettier-ignore -->
@@ -63,8 +63,7 @@ const [owner, repoName] = repo.split('/')
6363
<span id='gh-license' class='text-sm leading-tight sm:text-base'>???</span>
6464
</div>
6565
</div>
66-
67-
<span id='gh-language' class='gh-text text-sm leading-tight sm:text-base'>?????</span>
66+
<span id='gh-language' class='load-block text-sm leading-tight sm:text-base'>?????</span>
6867
</div>
6968
</a>
7069
</github-card>
@@ -81,19 +80,22 @@ const [owner, repoName] = repo.split('/')
8180
opacity: 1;
8281
}
8382
}
84-
.loading .gh-text {
83+
.loading .load-block {
8584
color: transparent;
8685
border-radius: calc(var(--radius) - 3px);
8786
background-color: hsl(var(--primary-foreground) / var(--un-bg-opacity, 1));
8887
animation: pulsate 2s infinite linear;
8988
user-select: none;
9089
}
91-
.loading .gh-text:nth-child(2) {
90+
.loading .load-block:nth-child(2) {
9291
animation-delay: 1s;
9392
}
9493
.no-license {
9594
opacity: 0.5;
9695
}
96+
:not(.loading) #gh-avatar {
97+
background-color: hsl(var(--primary-foreground) / var(--un-bg-opacity));
98+
}
9799
</style>
98100

99101
<script>
@@ -134,26 +136,22 @@ const [owner, repoName] = repo.split('/')
134136
try {
135137
const data = await this.fetchGithub(this.dataset.repo)
136138
if (!data) return
137-
;(this.querySelector('#gh-stars') as HTMLElement).textContent = this.numberFormat(
138-
data.stargazers_count
139-
)
140-
;(this.querySelector('#gh-forks') as HTMLElement).textContent = this.numberFormat(
141-
data.forks
142-
)
143-
;(this.querySelector('#gh-language') as HTMLElement).textContent = data.language || 'N/A'
144-
;(this.querySelector('#gh-description') as HTMLElement).textContent =
139+
// Update stats
140+
this.updateElement('#gh-stars', this.numberFormat(data.stargazers_count))
141+
this.updateElement('#gh-forks', this.numberFormat(data.forks))
142+
this.updateElement('#gh-language', data.language || 'N/A')
143+
// Update description
144+
const description =
145145
typeof data.description === 'string'
146146
? data.description.replace(/:[a-zA-Z0-9_]+:/g, '')
147147
: 'Description not set'
148-
148+
this.updateElement('#gh-description', description)
149+
// Update license
150+
const licenseText = data.license?.spdx_id || 'N/A'
149151
const licenseEl = this.querySelector('#gh-license') as HTMLElement
150-
if (data.license?.spdx_id) {
151-
licenseEl.textContent = data.license.spdx_id
152-
} else {
153-
licenseEl.textContent = 'N/A'
154-
licenseEl.classList.add('no-license')
155-
}
156-
152+
licenseEl.textContent = licenseText
153+
licenseEl.classList.toggle('no-license', licenseText === 'N/A')
154+
// Update avatar
157155
const avatarEl = this.querySelector('#gh-avatar') as HTMLElement
158156
if (avatarEl) {
159157
avatarEl.style.backgroundImage = `url(${data.owner.avatar_url})`
@@ -162,7 +160,14 @@ const [owner, repoName] = repo.split('/')
162160
this.classList.remove('loading')
163161
} catch (e) {
164162
console.error('Error setting Github data:', e)
165-
;(this.querySelector('#gh-description') as HTMLElement).textContent = 'Failed to fetch data'
163+
this.updateElement('#gh-description', 'Failed to fetch data')
164+
}
165+
}
166+
167+
private updateElement(selector: string, text: string) {
168+
const element = this.querySelector(selector) as HTMLElement
169+
if (element) {
170+
element.textContent = text
166171
}
167172
}
168173
}

packages/pure/components/advanced/Quote.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const { class: className } = Astro.props
3434

3535
connectedCallback() {
3636
// Because virtual:config can only be accessed using json string, function cannot work, so we need to use new Function
37-
const targetFunction = new Function('return ' + quote.target)()
37+
const targetFunction = new Function('data', 'return (' + quote.target + ')(data)')
3838
fetch(quote.server)
3939
.then((response) => response.json())
4040
.then((data) => this.render(targetFunction(data)))
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
---
2+
import type { HTMLTag, Polymorphic } from 'astro/types'
3+
24
import { cn } from '../../utils'
35
6+
type Props<Tag extends HTMLTag> = Polymorphic<{ as: Tag }> & {
7+
class?: string
8+
}
9+
410
const { as: Tag = 'span', class: className } = Astro.props
511
---
612

713
<Tag
814
class={cn(
9-
'bg-muted rounded text-transparent hover:text-inherit px-1 transition-colors',
15+
'spoiler bg-muted rounded text-transparent hover:text-inherit px-1 transition-colors',
1016
className
1117
)}
1218
>
1319
<slot />
1420
</Tag>
21+
22+
<style>
23+
.spoiler:not(:hover) :global(*) {
24+
color: inherit !important;
25+
background-color: transparent !important;
26+
}
27+
</style>

src/components/home/ProjectCard.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ const {
1414
altText
1515
} = Astro.props
1616
const images = import.meta.glob<{ default: ImageMetadata }>(
17-
'/src/assets/projects/*.{jpeg,jpg,png,gif,avif.webp}'
17+
'/src/assets/projects/*.{jpeg,jpg,png,gif,avif,webp}'
1818
)
1919
if (!images[imagePath])
2020
throw new Error(
21-
`"${imagePath}" does not exist in glob: "src/assets/projects/*.{jpeg,jpg,png,gif,avif.webp}"`
21+
`"${imagePath}" does not exist in glob: "src/assets/projects/*.{jpeg,jpg,png,gif,avif,webp}"`
2222
)
2323
---
2424

src/pages/docs/rss.xml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { getBlogCollection, sortMDByDate } from 'astro-pure/server'
1414

1515
// Get dynamic import of images as a map collection
1616
const imagesGlob = import.meta.glob<{ default: ImageMetadata }>(
17-
'/src/content/docs/**/*.{jpeg,jpg,png,gif,avif.webp}' // add more image formats if needed
17+
'/src/content/docs/**/*.{jpeg,jpg,png,gif,avif,webp}' // add more image formats if needed
1818
)
1919

2020
const renderContent = async (post: CollectionEntry<'docs'>, site: URL) => {

src/pages/index.astro

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,20 @@ const highlightColor = getHighlightColor()
122122
{
123123
allPostsByDate.map((post, index) => (
124124
<a href={`/blog/${post.data.slug}`} class='block no-underline group relative z-10'>
125-
<article class='grid grid-cols-[32px_1fr] gap-3 md:grid-cols-[40px_1fr] md:gap-5 py-2.5 md:py-3 border-b border-border last:border-b-0 transition-colors hover:bg-muted/50 cursor-pointer'>
126-
<div class='text-sm md:text-xl font-light text-muted-foreground/90 tabular-nums self-start leading-none'>
125+
<article class='relative grid grid-cols-[32px_1fr] gap-3 md:grid-cols-[40px_1fr] md:gap-5 py-2.5 md:py-3 border-b border-border last:border-b-0 transition-colors hover:bg-muted/50 cursor-pointer'>
126+
{/* Hero Image - 桌面端右侧渐变显示 */}
127+
{'heroImage' in post.data && post.data.heroImage && (
128+
<Image
129+
alt={post.data.heroImage.alt || post.data.title}
130+
class='cover-image-home hidden md:block absolute end-0 top-0 z-0 h-full w-3/5 object-cover opacity-50 transition-opacity duration-300 group-hover:opacity-70'
131+
loading='lazy'
132+
{...post.data.heroImage}
133+
/>
134+
)}
135+
<div class='text-sm md:text-xl font-light text-muted-foreground/90 tabular-nums self-start leading-none relative z-10'>
127136
{String(index + 1).padStart(2, '0')}
128137
</div>
129-
<div class='flex flex-col gap-1 md:gap-1.5'>
138+
<div class='flex flex-col gap-1 md:gap-1.5 relative z-10 md:me-[40%]'>
130139
<div class='flex flex-col gap-0.5 md:gap-1'>
131140
<time class='text-xs text-muted-foreground tabular-nums'>
132141
{new Date(
@@ -378,5 +387,16 @@ const highlightColor = getHighlightColor()
378387
min-height: 1.1em;
379388
}
380389
}
390+
391+
/* Hero Image 渐变遮罩 - 桌面端右侧渐变 */
392+
.cover-image-home {
393+
mask-image: linear-gradient(to right, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) 100%);
394+
-ms-mask-image: -ms-linear-gradient(to right, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) 100%);
395+
-webkit-mask-image: -webkit-linear-gradient(
396+
to right,
397+
rgba(0, 0, 0, 0) 0%,
398+
rgba(0, 0, 0, 1) 100%
399+
);
400+
}
381401
</style>
382402
</PageLayout>

src/pages/rss.xml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { getBlogCollection, sortMDByDate } from 'astro-pure/server'
1414

1515
// Get dynamic import of images as a map collection
1616
const imagesGlob = import.meta.glob<{ default: ImageMetadata }>(
17-
'/src/content/blog/**/*.{jpeg,jpg,png,gif,avif.webp}' // add more image formats if needed
17+
'/src/content/blog/**/*.{jpeg,jpg,png,gif,avif,webp}' // add more image formats if needed
1818
)
1919

2020
const renderContent = async (post: CollectionEntry<'blog'>, site: URL) => {

0 commit comments

Comments
 (0)