Skip to content

Commit f5bb59e

Browse files
committed
chore: update
1 parent 77c13e1 commit f5bb59e

8 files changed

Lines changed: 184 additions & 148 deletions

File tree

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,17 @@
5454
"types": "./dist/blog-avatar/index.d.ts",
5555
"import": "./dist/blog-avatar/index.js"
5656
},
57+
"./blog-back-button": {
58+
"types": "./dist/blog-back-button/index.d.ts",
59+
"import": "./dist/blog-back-button/index.js"
60+
},
5761
"./blog-list": {
5862
"types": "./dist/blog-list/index.d.ts",
5963
"import": "./dist/blog-list/index.js"
64+
},
65+
"./blog-background": {
66+
"types": "./dist/blog-background/index.d.ts",
67+
"import": "./dist/blog-background/index.js"
6068
}
6169
},
6270
"repository": {

rslib.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export default defineConfig({
2626
'nav-icon': './src/nav-icon/index.tsx',
2727
benchmark: './src/benchmark/index.tsx',
2828
'blog-avatar': './src/blog-avatar/index.tsx',
29+
'blog-back-button': './src/blog-back-button/index.tsx',
2930
'blog-list': './src/blog-list/index.tsx',
31+
'blog-background': './src/blog-background/index.tsx',
3032
'tool-stack': './src/tool-stack/index.tsx',
3133
hero: './src/hero/index.tsx',
3234
'section-style': './src/section-style/index.tsx',
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.blog-back-button {
2+
margin-bottom: 1rem;
3+
color: var(--rp-c-text-2);
4+
transition: color 0.2s ease-out;
5+
6+
.link {
7+
font-size: 14px;
8+
text-decoration: none;
9+
}
10+
11+
&::before {
12+
content: '';
13+
margin-right: 0.5rem;
14+
}
15+
16+
&:hover,
17+
&:focus-visible {
18+
color: var(--rp-c-brand);
19+
}
20+
}

src/blog-back-button/index.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { ALink, type LinkComp } from '../shared';
2+
import styles from './index.module.scss';
3+
4+
export type BlogBackButtonProps = {
5+
pathname: string;
6+
lang?: string;
7+
className?: string;
8+
LinkComp?: LinkComp;
9+
};
10+
11+
const getClassName = (...classNames: Array<string | undefined>) => {
12+
return classNames.filter(Boolean).join(' ');
13+
};
14+
15+
const getBlogPrefix = (lang?: string) => {
16+
return !lang || lang === 'en' ? '/blog' : `/${lang}/blog`;
17+
};
18+
19+
const getLabel = (lang?: string) => {
20+
return lang === 'zh' ? '返回博客' : 'Back to blog';
21+
};
22+
23+
export function BlogBackButton({
24+
pathname,
25+
lang,
26+
className,
27+
LinkComp,
28+
}: BlogBackButtonProps) {
29+
const blogPrefix = getBlogPrefix(lang);
30+
const normalizedPathname = pathname.replace(/\/+$/, '') || '/';
31+
const blogIndexPath = `${blogPrefix}/`;
32+
const isBlogSubpage =
33+
normalizedPathname.startsWith(blogPrefix) &&
34+
normalizedPathname !== blogPrefix;
35+
36+
if (!isBlogSubpage) {
37+
return null;
38+
}
39+
40+
const Link = LinkComp ?? ALink;
41+
42+
return (
43+
<div className={getClassName(styles.blogBackButton, className)}>
44+
<Link href={blogIndexPath} className={styles.link}>
45+
{getLabel(lang)}
46+
</Link>
47+
</div>
48+
);
49+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
:global {
2+
html:not(.dark) {
3+
--rs-blog-list-frame-bg:
4+
linear-gradient(180deg, rgba(15, 23, 42, 0.02), transparent 72%),
5+
linear-gradient(90deg, rgba(15, 23, 42, 0.025) 1px, transparent 1px),
6+
linear-gradient(rgba(15, 23, 42, 0.025) 1px, transparent 1px);
7+
}
8+
9+
html.dark {
10+
--rs-blog-list-frame-bg:
11+
linear-gradient(180deg, rgba(148, 163, 184, 0.04), transparent 72%),
12+
linear-gradient(90deg, rgba(148, 163, 184, 0.05) 1px, transparent 1px),
13+
linear-gradient(rgba(148, 163, 184, 0.05) 1px, transparent 1px);
14+
}
15+
}
16+
17+
.blogBackground {
18+
position: absolute;
19+
inset: 0;
20+
pointer-events: none;
21+
z-index: -1;
22+
}
23+
24+
.blogFrame {
25+
position: absolute;
26+
inset: 0;
27+
background: var(--rs-blog-list-frame-bg);
28+
background-size: 1200px;
29+
opacity: 0.45;
30+
}
31+
32+
:global(.dark) .blogFrame {
33+
opacity: 0.35;
34+
}

src/blog-background/index.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { MeteorsBackground } from '../blog-list/MeteorsBackground';
2+
import styles from './index.module.scss';
3+
4+
export type BlogBackgroundProps = {
5+
showBackground?: boolean;
6+
backgroundGridSize?: number;
7+
backgroundMeteorCount?: number;
8+
};
9+
10+
export function BlogBackground({
11+
showBackground = true,
12+
backgroundGridSize = 120,
13+
backgroundMeteorCount = 3,
14+
}: BlogBackgroundProps) {
15+
if (!showBackground) {
16+
return null;
17+
}
18+
19+
return (
20+
<div className={styles.blogBackground}>
21+
<div className={styles.blogFrame} />
22+
<MeteorsBackground
23+
gridSize={backgroundGridSize}
24+
meteorCount={backgroundMeteorCount}
25+
/>
26+
</div>
27+
);
28+
}

0 commit comments

Comments
 (0)