stropress 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +307 -0
- package/dist/theme-default/package.json +20 -0
- package/dist/theme-default/postcss.config.mjs +5 -0
- package/dist/theme-default/src/components/BaseHead.astro +53 -0
- package/dist/theme-default/src/components/DocToc.astro +111 -0
- package/dist/theme-default/src/components/GithubIcon.astro +35 -0
- package/dist/theme-default/src/components/HomePage.astro +198 -0
- package/dist/theme-default/src/components/Icon.astro +78 -0
- package/dist/theme-default/src/components/LocaleSelect.astro +187 -0
- package/dist/theme-default/src/components/NavBar.astro +231 -0
- package/dist/theme-default/src/components/SearchInput.astro +84 -0
- package/dist/theme-default/src/components/SearchModal.astro +209 -0
- package/dist/theme-default/src/components/Sidebar.astro +101 -0
- package/dist/theme-default/src/content/docs/guide/configuration.mdx +195 -0
- package/dist/theme-default/src/content/docs/guide/getting-started.md +98 -0
- package/dist/theme-default/src/content/docs/guide/search.mdx +41 -0
- package/dist/theme-default/src/content/docs/index.css +0 -0
- package/dist/theme-default/src/content/docs/index.md +6 -0
- package/dist/theme-default/src/content/docs/zh/guide/configuration.mdx +149 -0
- package/dist/theme-default/src/content/docs/zh/guide/getting-started.md +31 -0
- package/dist/theme-default/src/content/docs/zh/guide/search.mdx +23 -0
- package/dist/theme-default/src/content/docs/zh/index.astro +75 -0
- package/dist/theme-default/src/content/docs/zh/index.md +6 -0
- package/dist/theme-default/src/content.config.ts +14 -0
- package/dist/theme-default/src/env.d.ts +15 -0
- package/dist/theme-default/src/layouts/DocsLayout.astro +278 -0
- package/dist/theme-default/src/lib/config.ts +195 -0
- package/dist/theme-default/src/lib/custom-home.ts +40 -0
- package/dist/theme-default/src/lib/custom-style.ts +11 -0
- package/dist/theme-default/src/lib/og.ts +275 -0
- package/dist/theme-default/src/pages/[...slug]/index.astro +83 -0
- package/dist/theme-default/src/pages/index.astro +47 -0
- package/dist/theme-default/src/pages/og/[...slug].png.ts +70 -0
- package/dist/theme-default/src/scripts/code-copy.ts +54 -0
- package/dist/theme-default/src/scripts/doc-toc.ts +109 -0
- package/dist/theme-default/src/scripts/search.ts +329 -0
- package/dist/theme-default/src/styles/global.css +70 -0
- package/dist/theme-default/src/styles/markdown.css +141 -0
- package/dist/theme-default/tsconfig.json +10 -0
- package/package.json +32 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
---
|
|
2
|
+
import Icon from "./Icon.astro";
|
|
3
|
+
import { getResolvedSiteConfig, type HomeAction } from "../lib/config";
|
|
4
|
+
|
|
5
|
+
const resolvedConfig = getResolvedSiteConfig(Astro.url.pathname);
|
|
6
|
+
const homeConfig = resolvedConfig.homeConfig;
|
|
7
|
+
const siteTitle = resolvedConfig.siteTitle;
|
|
8
|
+
const siteDescription = resolvedConfig.siteDescription;
|
|
9
|
+
|
|
10
|
+
const heroTitle = homeConfig.title || siteTitle;
|
|
11
|
+
const heroTagline = homeConfig.tagline || siteDescription;
|
|
12
|
+
const heroDescription = homeConfig.description || siteDescription;
|
|
13
|
+
const actions = homeConfig.actions || [];
|
|
14
|
+
const features = homeConfig.features || [];
|
|
15
|
+
|
|
16
|
+
const getActionClass = (action: HomeAction) =>
|
|
17
|
+
action.theme === "alt" ? "action alt" : "action brand";
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
<section class="hero">
|
|
21
|
+
<p class="eyebrow">Stropress</p>
|
|
22
|
+
<h1>{heroTitle}</h1>
|
|
23
|
+
<p class="tagline">{heroTagline}</p>
|
|
24
|
+
<p class="description">{heroDescription}</p>
|
|
25
|
+
|
|
26
|
+
{
|
|
27
|
+
actions.length > 0 && (
|
|
28
|
+
<div class="actions">
|
|
29
|
+
{actions.map((action) => (
|
|
30
|
+
<a class={getActionClass(action)} href={action.link}>
|
|
31
|
+
{action.text}
|
|
32
|
+
</a>
|
|
33
|
+
))}
|
|
34
|
+
</div>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
</section>
|
|
38
|
+
|
|
39
|
+
{
|
|
40
|
+
features.length > 0 && (
|
|
41
|
+
<section class="features">
|
|
42
|
+
{features.map((feature) => (
|
|
43
|
+
<article class="feature-card">
|
|
44
|
+
<Icon
|
|
45
|
+
name={feature.icon}
|
|
46
|
+
class="feature-icon"
|
|
47
|
+
aria-hidden="true"
|
|
48
|
+
stroke-width={1.8}
|
|
49
|
+
/>
|
|
50
|
+
<h2>{feature.title}</h2>
|
|
51
|
+
<p>{feature.details}</p>
|
|
52
|
+
</article>
|
|
53
|
+
))}
|
|
54
|
+
</section>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
<style>
|
|
59
|
+
.hero {
|
|
60
|
+
padding: 1.5rem;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.eyebrow {
|
|
64
|
+
display: inline-flex;
|
|
65
|
+
margin: 0 0 1rem;
|
|
66
|
+
padding: 0.15rem 0;
|
|
67
|
+
border-radius: 0;
|
|
68
|
+
background: transparent;
|
|
69
|
+
color: rgba(var(--foreground-color) / 1);
|
|
70
|
+
font-size: 0.82rem;
|
|
71
|
+
font-weight: 700;
|
|
72
|
+
letter-spacing: 0.08em;
|
|
73
|
+
text-transform: uppercase;
|
|
74
|
+
border-bottom: 1px solid
|
|
75
|
+
color-mix(in srgb, rgba(var(--foreground-color) / 1) 18%, transparent);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
h1 {
|
|
79
|
+
margin: 0;
|
|
80
|
+
max-width: 10ch;
|
|
81
|
+
font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
|
|
82
|
+
font-size: clamp(3.4rem, 9vw, 6.8rem);
|
|
83
|
+
line-height: 0.95;
|
|
84
|
+
letter-spacing: -0.04em;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.tagline {
|
|
88
|
+
margin: 1.25rem 0 0;
|
|
89
|
+
max-width: 24ch;
|
|
90
|
+
font-size: clamp(1.35rem, 3vw, 2rem);
|
|
91
|
+
color: rgba(var(--foreground-color) / 1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.description {
|
|
95
|
+
margin: 1rem 0 0;
|
|
96
|
+
max-width: 60ch;
|
|
97
|
+
font-size: 1.05rem;
|
|
98
|
+
line-height: 1.8;
|
|
99
|
+
color: rgba(var(--muted-color) / 1);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.actions {
|
|
103
|
+
display: flex;
|
|
104
|
+
flex-wrap: wrap;
|
|
105
|
+
gap: 0.9rem;
|
|
106
|
+
margin-top: 2rem;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.action {
|
|
110
|
+
display: inline-flex;
|
|
111
|
+
align-items: center;
|
|
112
|
+
justify-content: center;
|
|
113
|
+
min-width: 148px;
|
|
114
|
+
padding: 0.9rem 1.2rem;
|
|
115
|
+
border-radius: 0;
|
|
116
|
+
font-weight: 700;
|
|
117
|
+
transition:
|
|
118
|
+
transform 140ms ease,
|
|
119
|
+
background 140ms ease;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.action:hover {
|
|
123
|
+
transform: translateY(-1px);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.action.brand {
|
|
127
|
+
background: rgba(var(--primary-color) / 1);
|
|
128
|
+
color: rgba(var(--primary-foreground-color) / 1);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.action.alt {
|
|
132
|
+
background: rgba(var(--secondary-color) / 1);
|
|
133
|
+
border: 1px solid
|
|
134
|
+
color-mix(in srgb, rgba(var(--foreground-color) / 1) 14%, transparent);
|
|
135
|
+
color: rgba(var(--foreground-color) / 1);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.features {
|
|
139
|
+
display: grid;
|
|
140
|
+
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
141
|
+
gap: 0;
|
|
142
|
+
margin-top: 3rem;
|
|
143
|
+
border-top: 1px solid
|
|
144
|
+
color-mix(in srgb, rgba(var(--foreground-color) / 1) 12%, transparent);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.feature-card {
|
|
148
|
+
padding: 1.5rem;
|
|
149
|
+
border-right: 1px solid
|
|
150
|
+
color-mix(in srgb, rgba(var(--foreground-color) / 1) 12%, transparent);
|
|
151
|
+
background: transparent;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.feature-card:last-child {
|
|
155
|
+
border-right: 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.feature-icon {
|
|
159
|
+
display: inline-flex;
|
|
160
|
+
align-items: center;
|
|
161
|
+
justify-content: center;
|
|
162
|
+
width: 2.4rem;
|
|
163
|
+
height: 2.4rem;
|
|
164
|
+
margin-bottom: 1rem;
|
|
165
|
+
padding: 0;
|
|
166
|
+
border-radius: 0;
|
|
167
|
+
background: transparent;
|
|
168
|
+
color: rgba(var(--foreground-color) / 1);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.feature-card h2 {
|
|
172
|
+
margin: 0;
|
|
173
|
+
font-size: 1.1rem;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.feature-card p {
|
|
177
|
+
margin: 0.75rem 0 0;
|
|
178
|
+
color: rgba(var(--muted-color) / 1);
|
|
179
|
+
line-height: 1.7;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@media (max-width: 900px) {
|
|
183
|
+
.features {
|
|
184
|
+
grid-template-columns: 1fr;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.feature-card {
|
|
188
|
+
padding-right: 0;
|
|
189
|
+
border-right: 0;
|
|
190
|
+
border-bottom: 1px solid
|
|
191
|
+
color-mix(in srgb, rgba(var(--foreground-color) / 1) 12%, transparent);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.feature-card:last-child {
|
|
195
|
+
border-bottom: 0;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
</style>
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
import GithubIcon from "./GithubIcon.astro";
|
|
3
|
+
import { icons as lucideIcons, type LucideIconComponent } from "@lucide/astro";
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
name?: string;
|
|
7
|
+
class?: string;
|
|
8
|
+
color?: string;
|
|
9
|
+
size?: number | string;
|
|
10
|
+
title?: string;
|
|
11
|
+
"stroke-width"?: number | string;
|
|
12
|
+
"aria-hidden"?: "true" | "false";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
name,
|
|
17
|
+
class: className,
|
|
18
|
+
color,
|
|
19
|
+
size,
|
|
20
|
+
title,
|
|
21
|
+
"stroke-width": strokeWidth,
|
|
22
|
+
"aria-hidden": ariaHidden,
|
|
23
|
+
} = Astro.props;
|
|
24
|
+
|
|
25
|
+
const normalizeIconName = (iconName: string) =>
|
|
26
|
+
iconName
|
|
27
|
+
.trim()
|
|
28
|
+
.replace(/(^[a-z])|[-_\s]+([a-zA-Z0-9])/g, (_, first, next) =>
|
|
29
|
+
(first || next).toUpperCase(),
|
|
30
|
+
)
|
|
31
|
+
.replace(/[^a-zA-Z0-9]/g, "");
|
|
32
|
+
|
|
33
|
+
const resolveIconComponent = (iconName?: string) => {
|
|
34
|
+
if (!iconName) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const normalized = normalizeIconName(iconName);
|
|
39
|
+
const icon = lucideIcons[normalized] || lucideIcons[iconName];
|
|
40
|
+
|
|
41
|
+
return typeof icon === "function" ? (icon as LucideIconComponent) : undefined;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const isGithubIcon = (iconName?: string) => {
|
|
45
|
+
if (!iconName) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const normalized = normalizeIconName(iconName);
|
|
50
|
+
return normalized.toLowerCase() === "github";
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const LucideIcon = resolveIconComponent(name);
|
|
54
|
+
const useGithubIcon = isGithubIcon(name);
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
useGithubIcon ? (
|
|
59
|
+
<GithubIcon
|
|
60
|
+
class={className}
|
|
61
|
+
color={color}
|
|
62
|
+
size={size}
|
|
63
|
+
title={title}
|
|
64
|
+
aria-hidden={ariaHidden}
|
|
65
|
+
/>
|
|
66
|
+
) : (
|
|
67
|
+
LucideIcon && (
|
|
68
|
+
<LucideIcon
|
|
69
|
+
class={className}
|
|
70
|
+
color={color}
|
|
71
|
+
size={size}
|
|
72
|
+
title={title}
|
|
73
|
+
stroke-width={strokeWidth}
|
|
74
|
+
aria-hidden={ariaHidden}
|
|
75
|
+
/>
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
---
|
|
2
|
+
import Icon from "./Icon.astro";
|
|
3
|
+
import type { LocaleLink } from "../lib/config";
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
localeLinks: LocaleLink[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const { localeLinks } = Astro.props;
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
{
|
|
13
|
+
localeLinks.length > 1 && (
|
|
14
|
+
<div class="locale-switcher" data-locale-switcher>
|
|
15
|
+
<button
|
|
16
|
+
type="button"
|
|
17
|
+
class="locale-popover-trigger"
|
|
18
|
+
aria-label="Switch language"
|
|
19
|
+
aria-haspopup="menu"
|
|
20
|
+
aria-expanded="false"
|
|
21
|
+
data-locale-trigger
|
|
22
|
+
>
|
|
23
|
+
<Icon name="Languages" class="locale-trigger-icon" aria-hidden="true" />
|
|
24
|
+
<div class="locale-trigger-label">
|
|
25
|
+
{localeLinks.find((locale) => locale.isActive)?.label}
|
|
26
|
+
</div>
|
|
27
|
+
</button>
|
|
28
|
+
<div
|
|
29
|
+
class="locale-popover"
|
|
30
|
+
role="menu"
|
|
31
|
+
data-state="closed"
|
|
32
|
+
data-locale-popover
|
|
33
|
+
>
|
|
34
|
+
{localeLinks.map((locale) => (
|
|
35
|
+
<a
|
|
36
|
+
href={locale.link}
|
|
37
|
+
role="menuitem"
|
|
38
|
+
class="locale-popover-item"
|
|
39
|
+
data-state={locale.isActive ? "active" : "inactive"}
|
|
40
|
+
>
|
|
41
|
+
{locale.label}
|
|
42
|
+
</a>
|
|
43
|
+
))}
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
<script>
|
|
50
|
+
const switcher = document.querySelector<HTMLElement>(
|
|
51
|
+
"[data-locale-switcher]",
|
|
52
|
+
);
|
|
53
|
+
const trigger = switcher?.querySelector<HTMLButtonElement>(
|
|
54
|
+
"[data-locale-trigger]",
|
|
55
|
+
);
|
|
56
|
+
const popover = switcher?.querySelector<HTMLElement>("[data-locale-popover]");
|
|
57
|
+
|
|
58
|
+
const setOpen = (open: boolean) => {
|
|
59
|
+
if (!trigger || !popover) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
popover.dataset.state = open ? "open" : "closed";
|
|
64
|
+
trigger.setAttribute("aria-expanded", open ? "true" : "false");
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
trigger?.addEventListener("click", () => {
|
|
68
|
+
if (!popover) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
setOpen(popover.dataset.state !== "open");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
document.addEventListener("click", (event) => {
|
|
76
|
+
if (!switcher) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!switcher.contains(event.target as Node)) {
|
|
81
|
+
setOpen(false);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
document.addEventListener("keydown", (event) => {
|
|
86
|
+
if (event.key === "Escape") {
|
|
87
|
+
setOpen(false);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
<style is:global>
|
|
93
|
+
.locale-switcher {
|
|
94
|
+
position: relative;
|
|
95
|
+
display: flex;
|
|
96
|
+
align-items: center;
|
|
97
|
+
margin-left: 0.25rem;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.locale-popover-trigger {
|
|
101
|
+
display: inline-flex;
|
|
102
|
+
align-items: center;
|
|
103
|
+
justify-content: center;
|
|
104
|
+
border: 1px solid rgba(var(--border-color) / 1);
|
|
105
|
+
border-radius: 0.5rem;
|
|
106
|
+
background: rgba(var(--background-color) / 0.95);
|
|
107
|
+
color: rgba(var(--foreground-color) / 1);
|
|
108
|
+
width: 2rem;
|
|
109
|
+
height: 2rem;
|
|
110
|
+
cursor: pointer;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.locale-trigger-label {
|
|
114
|
+
display: none;
|
|
115
|
+
margin-left: 0.25rem;
|
|
116
|
+
}
|
|
117
|
+
.locale-trigger-icon {
|
|
118
|
+
width: 1rem;
|
|
119
|
+
height: 1rem;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.locale-popover-trigger:focus-visible {
|
|
123
|
+
outline: 2px solid rgba(var(--foreground-color) / 0.2);
|
|
124
|
+
outline-offset: 2px;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.locale-popover {
|
|
128
|
+
position: absolute;
|
|
129
|
+
right: 0;
|
|
130
|
+
top: calc(100% + 0.35rem);
|
|
131
|
+
min-width: 8rem;
|
|
132
|
+
padding: 0.35rem;
|
|
133
|
+
border: 1px solid rgba(var(--border-color) / 1);
|
|
134
|
+
border-radius: 0.5rem;
|
|
135
|
+
background: rgba(var(--background-color) / 1);
|
|
136
|
+
box-shadow: 0 10px 28px rgba(0 0 0 / 0.14);
|
|
137
|
+
display: none;
|
|
138
|
+
z-index: 30;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.locale-popover[data-state="open"] {
|
|
142
|
+
display: grid;
|
|
143
|
+
gap: 0.15rem;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.locale-popover-item {
|
|
147
|
+
display: block;
|
|
148
|
+
padding: 0.45rem 0.55rem;
|
|
149
|
+
border-radius: 0.35rem;
|
|
150
|
+
font-size: 0.82rem;
|
|
151
|
+
line-height: 1.2;
|
|
152
|
+
color: rgba(var(--muted-color) / 1);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.locale-popover-item:hover,
|
|
156
|
+
.locale-popover-item[data-state="active"] {
|
|
157
|
+
background: rgba(var(--accent-color) / 1);
|
|
158
|
+
color: rgba(var(--foreground-color) / 1);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
@media (max-width: 900px) {
|
|
162
|
+
.locale-switcher {
|
|
163
|
+
width: 100%;
|
|
164
|
+
flex-direction: column;
|
|
165
|
+
align-items: flex-start;
|
|
166
|
+
order: 4;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.locale-popover {
|
|
170
|
+
position: static;
|
|
171
|
+
right: auto;
|
|
172
|
+
top: auto;
|
|
173
|
+
margin-top: 0.4rem;
|
|
174
|
+
min-width: 0;
|
|
175
|
+
width: 100%;
|
|
176
|
+
box-shadow: none;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.locale-popover-trigger {
|
|
180
|
+
width: unset;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.locale-trigger-label {
|
|
184
|
+
display: inline-block;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
</style>
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
---
|
|
2
|
+
import Icon from "./Icon.astro";
|
|
3
|
+
import SearchInput from "./SearchInput.astro";
|
|
4
|
+
import SearchModal from "./SearchModal.astro";
|
|
5
|
+
import LocaleSelect from "./LocaleSelect.astro";
|
|
6
|
+
import { getCollection } from "astro:content";
|
|
7
|
+
import type { SearchDocument } from "../scripts/search";
|
|
8
|
+
import { getResolvedSiteConfig } from "../lib/config";
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
showSidebarToggle?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { showSidebarToggle = false } = Astro.props;
|
|
15
|
+
|
|
16
|
+
const pathname = Astro.url.pathname;
|
|
17
|
+
const resolvedConfig = getResolvedSiteConfig(pathname);
|
|
18
|
+
const navItems = resolvedConfig.nav;
|
|
19
|
+
const socialItems = resolvedConfig.socialLinks;
|
|
20
|
+
const localePrefixes = resolvedConfig.localeLinks
|
|
21
|
+
.map((locale) => locale.key)
|
|
22
|
+
.filter((key) => key !== "/")
|
|
23
|
+
.map((key) => key.slice(1, -1));
|
|
24
|
+
const currentLocalePrefix =
|
|
25
|
+
resolvedConfig.localeKey === "/" ? "" : resolvedConfig.localeKey.slice(1, -1);
|
|
26
|
+
const docs = await getCollection("docs");
|
|
27
|
+
const searchDocuments: SearchDocument[] = docs
|
|
28
|
+
.filter((entry) => {
|
|
29
|
+
if (resolvedConfig.localeKey === "/") {
|
|
30
|
+
return !localePrefixes.some((prefix) =>
|
|
31
|
+
entry.id.startsWith(`${prefix}/`),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
entry.id === currentLocalePrefix ||
|
|
37
|
+
entry.id.startsWith(`${currentLocalePrefix}/`)
|
|
38
|
+
);
|
|
39
|
+
})
|
|
40
|
+
.map((entry) => {
|
|
41
|
+
const normalizedId = entry.id.endsWith("/index")
|
|
42
|
+
? entry.id.slice(0, -"/index".length)
|
|
43
|
+
: entry.id;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
id: entry.id,
|
|
47
|
+
title: entry.data.title,
|
|
48
|
+
description: entry.data.description || "",
|
|
49
|
+
body: entry.body || "",
|
|
50
|
+
url: normalizedId === "index" ? "/" : `/${normalizedId}`,
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
<header class="header">
|
|
56
|
+
<div class="header-wrapper">
|
|
57
|
+
{
|
|
58
|
+
showSidebarToggle && (
|
|
59
|
+
<button
|
|
60
|
+
type="button"
|
|
61
|
+
class="header-menu-toggle"
|
|
62
|
+
aria-label="Toggle navigation menu"
|
|
63
|
+
aria-controls="sidebar-drawer"
|
|
64
|
+
aria-expanded="false"
|
|
65
|
+
data-sidebar-toggle
|
|
66
|
+
>
|
|
67
|
+
<Icon name="Menu" class="header-menu-icon" aria-hidden="true" />
|
|
68
|
+
</button>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
<div class="logo">
|
|
72
|
+
<a
|
|
73
|
+
href={resolvedConfig.localeKey === "/" ? "/" : resolvedConfig.localeKey}
|
|
74
|
+
>
|
|
75
|
+
{resolvedConfig.siteTitle}
|
|
76
|
+
</a>
|
|
77
|
+
</div>
|
|
78
|
+
<SearchInput />
|
|
79
|
+
{
|
|
80
|
+
navItems.length > 0 && (
|
|
81
|
+
<ul class="header-nav-list">
|
|
82
|
+
{navItems.map((item) => (
|
|
83
|
+
<li>
|
|
84
|
+
<a href={item.link} class="nav-link nav-link-text">
|
|
85
|
+
{item.icon && (
|
|
86
|
+
<Icon name={item.icon} class="nav-icon" aria-hidden="true" />
|
|
87
|
+
)}
|
|
88
|
+
<span>{item.label}</span>
|
|
89
|
+
</a>
|
|
90
|
+
</li>
|
|
91
|
+
))}
|
|
92
|
+
</ul>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
<LocaleSelect localeLinks={resolvedConfig.localeLinks} />
|
|
96
|
+
<ul class="social-links-list">
|
|
97
|
+
{
|
|
98
|
+
socialItems.map((item) => (
|
|
99
|
+
<li>
|
|
100
|
+
<a
|
|
101
|
+
href={item.link}
|
|
102
|
+
class="nav-link"
|
|
103
|
+
aria-label={item.label}
|
|
104
|
+
title={item.label}
|
|
105
|
+
>
|
|
106
|
+
{item.icon ? (
|
|
107
|
+
<Icon name={item.icon} class="nav-icon" aria-hidden="true" />
|
|
108
|
+
) : (
|
|
109
|
+
<span>{item.label}</span>
|
|
110
|
+
)}
|
|
111
|
+
</a>
|
|
112
|
+
</li>
|
|
113
|
+
))
|
|
114
|
+
}
|
|
115
|
+
</ul>
|
|
116
|
+
</div>
|
|
117
|
+
<SearchModal documents={searchDocuments} />
|
|
118
|
+
</header>
|
|
119
|
+
|
|
120
|
+
<style is:global>
|
|
121
|
+
.header {
|
|
122
|
+
position: sticky;
|
|
123
|
+
top: 0;
|
|
124
|
+
z-index: 10;
|
|
125
|
+
display: flex;
|
|
126
|
+
align-items: center;
|
|
127
|
+
padding: 1rem 1.5rem;
|
|
128
|
+
backdrop-filter: blur(8px);
|
|
129
|
+
background: rgba(var(--background-color) / 0.85);
|
|
130
|
+
border-bottom: 1px solid rgba(var(--border-color) / 1);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.header-wrapper {
|
|
134
|
+
display: flex;
|
|
135
|
+
align-items: center;
|
|
136
|
+
gap: 1rem;
|
|
137
|
+
width: 100%;
|
|
138
|
+
max-width: 80rem;
|
|
139
|
+
margin: 0 auto;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.logo a {
|
|
143
|
+
font-weight: 700;
|
|
144
|
+
white-space: nowrap;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.header-nav-list,
|
|
148
|
+
.social-links-list {
|
|
149
|
+
list-style: none;
|
|
150
|
+
padding: 0;
|
|
151
|
+
margin: 0;
|
|
152
|
+
display: flex;
|
|
153
|
+
gap: 1rem;
|
|
154
|
+
align-items: center;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.header-nav-list {
|
|
158
|
+
margin-left: auto;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.social-links-list {
|
|
162
|
+
margin-left: 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.nav-link {
|
|
166
|
+
display: inline-flex;
|
|
167
|
+
align-items: center;
|
|
168
|
+
gap: 0.45rem;
|
|
169
|
+
padding: 0.35rem 0;
|
|
170
|
+
font-size: 0.875rem;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.nav-link-text {
|
|
174
|
+
white-space: nowrap;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.nav-icon {
|
|
178
|
+
width: 1rem;
|
|
179
|
+
height: 1rem;
|
|
180
|
+
flex: none;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.header-menu-toggle {
|
|
184
|
+
display: none;
|
|
185
|
+
align-items: center;
|
|
186
|
+
justify-content: center;
|
|
187
|
+
width: 2rem;
|
|
188
|
+
height: 2rem;
|
|
189
|
+
border: 1px solid rgba(var(--border-color) / 1);
|
|
190
|
+
border-radius: 0.5rem;
|
|
191
|
+
background: rgba(var(--background-color) / 1);
|
|
192
|
+
color: rgba(var(--foreground-color) / 1);
|
|
193
|
+
cursor: pointer;
|
|
194
|
+
flex: none;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.header-menu-icon {
|
|
198
|
+
width: 1rem;
|
|
199
|
+
height: 1rem;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
@media (max-width: 900px) {
|
|
203
|
+
.header {
|
|
204
|
+
padding: 0.85rem 1rem;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.header-menu-toggle {
|
|
208
|
+
display: inline-flex;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.header-wrapper {
|
|
212
|
+
flex-wrap: wrap;
|
|
213
|
+
gap: 0.7rem;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.header-nav-list {
|
|
217
|
+
order: 10;
|
|
218
|
+
width: 100%;
|
|
219
|
+
margin-right: 0;
|
|
220
|
+
flex-wrap: wrap;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.social-links-list {
|
|
224
|
+
order: 11;
|
|
225
|
+
flex-wrap: wrap;
|
|
226
|
+
width: auto;
|
|
227
|
+
justify-content: flex-end;
|
|
228
|
+
margin-left: auto;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
</style>
|