Skip to content

Commit a7b054e

Browse files
committed
-
1 parent 0517859 commit a7b054e

File tree

11 files changed

+355
-79
lines changed

11 files changed

+355
-79
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"eslint-plugin-prettier": "^4.0.0",
2828
"eslint-plugin-react": "^7.28.0",
2929
"prettier": "2.7.1",
30+
"prettier-plugin-astro": "^0.7.0",
3031
"prettier-plugin-tailwindcss": "^0.1.3"
3132
}
3233
}

website-v3/package-lock.json

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website-v3/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"@astrojs/node": "^3.1.0",
1515
"@astrojs/tailwind": "^2.1.3",
1616
"astro": "^1.6.14",
17+
"color": "^4.2.3",
1718
"lodash.get": "^4.4.2",
19+
"nanostores": "^0.7.1",
1820
"querystring": "^0.2.1",
1921
"tailwindcss": "^3.2.4",
2022
"zod": "^3.19.1"

website-v3/src/bundle.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const $GetBundleResponseSuccess = z.object({
6464
}),
6565
)
6666
.nullable(),
67-
baseBranch: z.string().nullable(),
67+
baseBranch: z.string(),
6868
path: z.string().nullable(),
6969
repositoryFound: z.boolean(),
7070
source: z.object({
@@ -75,7 +75,10 @@ const $GetBundleResponseSuccess = z.object({
7575
}),
7676
});
7777

78-
const $GetBundleResponse = z.union([$GetBundleResponseError, $GetBundleResponseSuccess]);
78+
const $GetBundleResponse = z.object({
79+
status: z.number(),
80+
bundle: z.union([$GetBundleResponseError, $GetBundleResponseSuccess]),
81+
});
7982

8083
export type GetBundleRequest = z.infer<typeof $GetBundleRequest>;
8184
export type GetBundleResponse = z.infer<typeof $GetBundleResponse>;
@@ -103,7 +106,10 @@ export async function getBundle(options: GetBundleRequest): Promise<GetBundleRes
103106

104107
// These are valid JSON responses from the server.
105108
if ([200, 404, 400].includes(response.status)) {
106-
return $GetBundleResponse.parse(await response.json());
109+
return $GetBundleResponse.parse({
110+
status: response.status,
111+
bundle: await response.json(),
112+
});
107113
}
108114

109115
throw new Error(`Failed to fetch bundle for "${endpoint}". HTTP Status: "${response.status}".`);

website-v3/src/components/Theme.astro

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
import Color from 'color';
3+
import context from 'src/context';
4+
5+
type Props = {
6+
fallback: string;
7+
};
8+
9+
let color: Color;
10+
try {
11+
color = Color(context.get().config.theme);
12+
} catch {
13+
color = Color(Astro.props.fallback);
14+
}
15+
---
16+
17+
<script
18+
is:inline
19+
data-base={color.hex().toString()}
20+
data-light={color.lighten(0.2).hex().toString()}
21+
data-dark={color.darken(0.2).hex().toString()}
22+
>
23+
const root = document.documentElement;
24+
root.style.setProperty('--theme-color', document.currentScript.getAttribute('data-base'));
25+
root.style.setProperty('--theme-color-light', document.currentScript.getAttribute('data-light'));
26+
root.style.setProperty('--theme-color-dark', document.currentScript.getAttribute('data-dark'));
27+
root.style.setProperty('--docsearch-primary-color', document.currentScript.getAttribute('data-base'));
28+
</script>

website-v3/src/context.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { map } from 'nanostores';
2+
import type { BundleConfig, GetBundleResponseSuccess } from './bundle';
3+
4+
export type Context = {
5+
owner: string;
6+
repository: string;
7+
config: BundleConfig;
8+
frontmatter: GetBundleResponseSuccess['frontmatter'];
9+
code: string;
10+
headings: GetBundleResponseSuccess['headings'];
11+
domain: string | undefined;
12+
baseBranch: GetBundleResponseSuccess['baseBranch'];
13+
source: GetBundleResponseSuccess['source'];
14+
};
15+
16+
const store = map<Context>();
17+
18+
export default store;

website-v3/src/layouts/Root.astro

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,37 @@ export interface Props {
55
// Sets the <meta name="description" content="..."> tag of the page, and any social tags (e.g. og:description)
66
description?: string;
77
// Adds a social preview image to the page (e.g. twitter:image)
8-
image?: string;
8+
image?: string;
99
}
1010
11-
// TODO
12-
const {
13-
title = '',
14-
description = '',
15-
image = '',
16-
author = '',
17-
} = Astro.props;
11+
const { title = '', description = '', image = '', author = '' } = Astro.props;
1812
---
13+
1914
<html>
2015
<head>
2116
<meta charset="utf-8" />
2217
<meta name="viewport" content="width=device-width, initial-scale=1" />
23-
18+
<!--
2419
<link rel="apple-touch-icon" sizes="180x180" href="/favicons/apple-touch-icon.png" />
2520
<link rel="icon" type="image/png" sizes="32x32" href="/favicons/favicon-32x32.png" />
2621
<link rel="icon" type="image/png" sizes="16x16" href="/favicons/favicon-16x16.png" />
2722
<link rel="manifest" href="/favicons/site.webmanifest" />
28-
<link rel="mask-icon" href="/favicons/safari-pinned-tab.svg" color="#333333" />
23+
<link rel="mask-icon" href="/favicons/safari-pinned-tab.svg" color="#333333" /> -->
2924

30-
<link rel="preconnect" href="https://fonts.googleapis.com">
31-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous">
32-
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Anton&display=block">
33-
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@500&display=block">
34-
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=block">
25+
<link rel="preconnect" href="https://fonts.googleapis.com" />
26+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous" />
27+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Anton&display=block" />
28+
<link
29+
rel="stylesheet"
30+
href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@500&display=block"
31+
/>
32+
<link
33+
rel="stylesheet"
34+
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=block"
35+
/>
3536

3637
<slot name="head" />
3738

38-
<link rel="shortcut icon" href="/favicons/favicon.ico" />
3939
<meta name="msapplication-TileColor" content="#333333" />
4040
<meta name="msapplication-config" content="/favicons/browserconfig.xml" />
4141
<meta name="theme-color" content="#333333" />

0 commit comments

Comments
 (0)