-
Notifications
You must be signed in to change notification settings - Fork 38
/
Layout.astro
224 lines (207 loc) · 5.09 KB
/
Layout.astro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
---
import { SEO, type Props as SEOProps } from "astro-seo";
import { GoogleAnalytics } from "@astrolib/analytics";
import Header from "./Header/index.astro";
import Footer from "./Footer/index.astro";
import Toc from "./Toc.astro";
import "@styles/layout.scss";
import type { MDXLayoutProps, MarkdownHeading } from "astro";
import Author, { type Author as AuthorProps } from "./Author.astro";
import Breadcrumb from "./Breadcrumb.astro";
import type { Breadcrumb as BreadcrumbProps } from "./resolve-breadcrumb";
import Markdown from "@components/utils/Markdown.astro";
import type { Lang } from "@components/types";
import { parse as parsePath } from "path";
import "@fontsource/material-icons";
import "@fontsource-variable/open-sans";
import resolveBreadcrumb from "./resolve-breadcrumb";
import Emergency from "./Emergency.astro";
interface Props extends MDXLayoutProps<Frontmatter> {}
export interface Frontmatter {
title: string;
description?: string;
lang: Lang;
toc?: boolean;
h1?: string;
top?: boolean;
support?: boolean;
layout?: boolean;
sitemap?: boolean;
redirect_to?: string;
author?: AuthorProps;
breadcrumb?: BreadcrumbProps;
}
function createDefaultDescription(
lang: Lang,
headings: MarkdownHeading[],
): string {
return (
(
{
ja: "目次: ",
en: "Table of Contents: ",
}[lang] +
headings
.filter(({ depth }) => depth === 2)
.map(({ text }) => text)
.join("; ")
).slice(0, 97) + "..."
);
}
const { frontmatter, headings, file } = Astro.props;
const {
title,
description = createDefaultDescription(frontmatter.lang, headings),
lang,
h1,
top,
support,
author,
breadcrumb,
} = frontmatter;
const displayToc = !top && (frontmatter.toc ?? true) && headings.length > 0;
const htmlAttributes = {
en: {
lang: "en",
class: "en",
},
ja: {
lang: "ja",
},
}[lang];
const locale = {
en: "en_US",
ja: "ja_JP",
}[lang];
const gaid = "G-ZM6H96EWBD";
const canonicalUrl = new URL(Astro.url);
if (parsePath(file).name !== "index") {
canonicalUrl.pathname = canonicalUrl.pathname.replace(/\/$/, "");
}
const seoProps: SEOProps = {
title,
titleTemplate: "%s | utelecon",
titleDefault: "utelecon",
description,
charset: "UTF-8",
canonical: canonicalUrl.href,
};
if (title) {
seoProps.openGraph = {
basic: {
title,
type: "website",
url: canonicalUrl.href,
image: new URL("/assets/images/ogp.png", Astro.site).href,
},
optional: {
description,
locale,
siteName: "utelecon",
},
image: {
alt: "utelecon",
},
};
seoProps.twitter = {
title,
description,
};
}
const resolvedBreadcrumb =
breadcrumb && (await resolveBreadcrumb(Astro.url, breadcrumb));
---
<!doctype html>
<html {...htmlAttributes}>
<head>
<SEO {...seoProps} />
<GoogleAnalytics id={gaid} partytown />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#157878" />
<meta
name="apple-mobile-web-app-status-bar-style"
content="black-translucent"
/>
<meta name="generator" content={Astro.generator} />
<link rel="icon" href="/assets/images/favicon.png" />
<script
async
src="https://cse.google.com/cse.js?cx=000989064976317806194:6h5uropjuyu"
></script>
</head>
<body>
<Header lang={lang} top={top} canonicalUrl={canonicalUrl} />
<main data-toc={displayToc} class="mark-external-link">
{
resolvedBreadcrumb && resolvedBreadcrumb.length > 1 && (
<Breadcrumb breadcrumb={resolvedBreadcrumb} />
)
}
{
!top && (
<h1 class="title">
<Markdown content={h1 ?? title} />
</h1>
)
}
<div id="article">
{displayToc && <Toc headings={headings} lang={lang} />}
<div id="content">
<Emergency />
<slot />
{
author && (
<>
<hr />
<Author lang={lang} author={author} />
</>
)
}
</div>
</div>
</main>
<Footer lang={lang} support={support} />
<style lang="scss">
@import "../styles/color.scss";
.title {
margin-bottom: 2rem;
padding-bottom: 1rem;
border-bottom: 1px solid $white-gray-dark;
font-size: 2rem;
font-weight: bold;
color: black;
}
</style>
</body>
</html>
<style lang="scss">
@import "@styles/color.scss";
@import "@styles/toc.scss";
.title {
margin-bottom: 2rem;
padding-bottom: 1rem;
border-bottom: 1px solid $white-gray-dark;
font-size: 2rem;
font-weight: bold;
color: black;
}
main[data-toc] {
#article {
display: flex;
flex-direction: row-reverse;
gap: $article-gap;
}
#content {
/* so that the content does not overflow the viewport */
min-width: 0;
flex-grow: 1;
}
}
@media screen and (max-width: calc(768px + $toc-width + $article-gap)) {
main[data-toc] {
#article {
flex-direction: column;
}
}
}
</style>