Skip to content

Commit 7213254

Browse files
committed
添加大标题
1 parent df272a9 commit 7213254

5 files changed

Lines changed: 57 additions & 7 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
import ImageWrapper from "./ImageWrapper.astro";
3+
import { siteConfig } from "../../config";
4+
5+
interface Props {
6+
id?: string;
7+
class?: string;
8+
alt?: string;
9+
}
10+
11+
const { id, alt } = Astro.props;
12+
const className = Astro.props.class;
13+
const bannerConfig = siteConfig.banner;
14+
---
15+
16+
<div id={id} class:list={[className, 'relative overflow-hidden']}>
17+
<ImageWrapper
18+
src={bannerConfig.src}
19+
position={bannerConfig.position}
20+
alt={alt || "Banner image of the blog"}
21+
class="w-full h-full"
22+
/>
23+
24+
{bannerConfig.text?.enable && (
25+
<div class="absolute inset-0 flex items-center justify-center z-20">
26+
<div class="text-center text-white px-6 py-4">
27+
{bannerConfig.text.title && (
28+
<h1 class="text-3xl md:text-5xl font-bold mb-2 drop-shadow-lg">
29+
{bannerConfig.text.title}
30+
</h1>
31+
)}
32+
{bannerConfig.text.subtitle && (
33+
<p class="text-lg md:text-xl opacity-90 drop-shadow-md">
34+
{bannerConfig.text.subtitle}
35+
</p>
36+
)}
37+
</div>
38+
</div>
39+
)}
40+
</div>

src/config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AUTO_MODE, DARK_MODE, LIGHT_MODE } from "./constants/constants";
12
import type {
23
CommentConfig,
34
ExpressiveCodeConfig,
@@ -7,7 +8,6 @@ import type {
78
SiteConfig,
89
} from "./types/config";
910
import { LinkPreset } from "./types/config";
10-
import { AUTO_MODE, DARK_MODE, LIGHT_MODE } from "./constants/constants";
1111

1212
export const siteConfig: SiteConfig = {
1313
title: "fishcpy的小破站",
@@ -28,6 +28,11 @@ export const siteConfig: SiteConfig = {
2828
text: "", // 要显示的版权文本
2929
url: "", // (可选) 原作品或艺术家页面的URL链接
3030
},
31+
text: {
32+
enable: true, // 是否在banner中显示文字
33+
title: "非淡泊无以明志,非宁静无以致远", // banner主标题
34+
subtitle: "Welcome to my blog", // banner副标题
35+
},
3136
},
3237
toc: {
3338
enable: true, // 在文章右侧显示目录

src/constants/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export const LIGHT_MODE = "light",
66
export const DEFAULT_THEME = AUTO_MODE;
77

88
// Banner height unit: vh
9-
export const BANNER_HEIGHT = 35;
10-
export const BANNER_HEIGHT_EXTEND = 30;
9+
export const BANNER_HEIGHT = 45;
10+
export const BANNER_HEIGHT_EXTEND = 35;
1111
export const BANNER_HEIGHT_HOME = BANNER_HEIGHT + BANNER_HEIGHT_EXTEND;
1212

1313
// The height the main panel overlaps the banner, unit: rem

src/layouts/MainGridLayout.astro

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Twikoo from "@components/comment/Twikoo.astro";
77
import type { MarkdownHeading } from "astro";
88
import { Icon } from "astro-icon/components";
99
import ImageWrapper from "../components/misc/ImageWrapper.astro";
10+
import BannerWrapper from "../components/misc/BannerWrapper.astro";
1011
import TOC from "../components/widget/TOC.astro";
1112
import { siteConfig } from "../config";
1213
import {
@@ -38,7 +39,7 @@ const hasBannerCredit =
3839
const hasBannerLink = !!siteConfig.banner.credit.url;
3940
4041
const mainPanelTop = siteConfig.banner.enable
41-
? `calc(${BANNER_HEIGHT}vh - ${MAIN_PANEL_OVERLAPS_BANNER_HEIGHT}rem)`
42+
? `calc(${BANNER_HEIGHT}vh - ${MAIN_PANEL_OVERLAPS_BANNER_HEIGHT}rem + 6rem)`
4243
: "5.5rem";
4344
---
4445

@@ -54,10 +55,9 @@ const mainPanelTop = siteConfig.banner.enable
5455

5556
<!-- Banner -->
5657
{siteConfig.banner.enable && <div id="banner-wrapper" class={`absolute z-10 w-full transition duration-700 overflow-hidden`} style={`top: calc(-1 * var(--banner-height-extend))`}>
57-
<ImageWrapper id="banner" alt="Banner image of the blog" class:list={["object-cover h-full transition duration-700 opacity-0 scale-105"]}
58-
src={siteConfig.banner.src} position={siteConfig.banner.position}
58+
<BannerWrapper id="banner" alt="Banner image of the blog" class:list={["object-cover h-full transition duration-700 opacity-0 scale-105"]}
5959
>
60-
</ImageWrapper>
60+
</BannerWrapper>
6161
</div>}
6262

6363
<!-- Main content -->

src/types/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ export type SiteConfig = {
2020
text: string;
2121
url?: string;
2222
};
23+
text?: {
24+
enable: boolean;
25+
title?: string;
26+
subtitle?: string;
27+
};
2328
};
2429
toc: {
2530
enable: boolean;

0 commit comments

Comments
 (0)