Skip to content

Commit 8b2435b

Browse files
lino-levanLino Le Van
and
Lino Le Van
authored
feat: make mobile work (#45)
Co-authored-by: Lino Le Van <linolevan@Linos-MacBook-Air.local>
1 parent 0689bfa commit 8b2435b

File tree

11 files changed

+88
-67
lines changed

11 files changed

+88
-67
lines changed

deno.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
},
1313
"compilerOptions": {
1414
"jsx": "react-jsx",
15-
"jsxImportSource": "https://esm.sh/preact@10.17.1"
15+
"jsxImportSource": "https://esm.sh/preact@10.19.3"
1616
}
1717
}

deps.ts

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export type { JSX } from "https://esm.sh/preact@10.17.1";
2-
export { renderToString } from "https://esm.sh/preact-render-to-string@6.2.1";
1+
export type { JSX } from "https://esm.sh/preact@10.19.3";
2+
export { renderToString } from "https://esm.sh/preact-render-to-string@6.3.1";
33

44
export {
55
fromFileUrl,
@@ -8,44 +8,45 @@ export {
88
resolve,
99
toFileUrl,
1010
win32,
11-
} from "https://deno.land/std@0.199.0/path/mod.ts";
12-
export { walkSync } from "https://deno.land/std@0.199.0/fs/walk.ts";
13-
export { parse as parseYaml } from "https://deno.land/std@0.199.0/yaml/mod.ts";
14-
export { parse as parseJsonc } from "https://deno.land/std@0.199.0/jsonc/mod.ts";
15-
export { parse as parseToml } from "https://deno.land/std@0.199.0/toml/mod.ts";
16-
export { copySync } from "https://deno.land/std@0.199.0/fs/copy.ts";
17-
export { serveDir } from "https://deno.land/std@0.199.0/http/file_server.ts";
18-
export { extract } from "https://deno.land/std@0.199.0/front_matter/any.ts";
19-
export { existsSync } from "https://deno.land/std@0.199.0/fs/exists.ts";
11+
} from "https://deno.land/std@0.210.0/path/mod.ts";
12+
export { walkSync } from "https://deno.land/std@0.210.0/fs/walk.ts";
13+
export { parse as parseYaml } from "https://deno.land/std@0.210.0/yaml/mod.ts";
14+
export { parse as parseJsonc } from "https://deno.land/std@0.210.0/jsonc/mod.ts";
15+
export { parse as parseToml } from "https://deno.land/std@0.210.0/toml/mod.ts";
16+
export { copySync } from "https://deno.land/std@0.210.0/fs/copy.ts";
17+
export { serveDir } from "https://deno.land/std@0.210.0/http/file_server.ts";
18+
export { extract } from "https://deno.land/std@0.210.0/front_matter/any.ts";
19+
export { existsSync } from "https://deno.land/std@0.210.0/fs/exists.ts";
2020

21-
export { launch } from "https://deno.land/x/astral@0.2.3/mod.ts";
21+
export { launch } from "https://deno.land/x/astral@0.3.2/mod.ts";
2222

23-
export * as esbuild from "https://deno.land/x/esbuild@v0.17.19/mod.js";
24-
export { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.8.1/mod.ts";
23+
export * as esbuild from "https://deno.land/x/esbuild@v0.19.2/mod.js";
24+
export { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.8.2/mod.ts";
2525

26-
export { createGenerator } from "https://esm.sh/@unocss/core@0.55.2";
27-
export { presetUno } from "https://esm.sh/@unocss/preset-uno@0.55.2";
26+
export { createGenerator } from "https://esm.sh/@unocss/core@0.58.0";
27+
export { presetUno } from "https://esm.sh/@unocss/preset-uno@0.58.0";
2828

2929
export { decode } from "https://deno.land/x/pngs@0.1.1/mod.ts";
3030

31-
export { default as Github } from "https://deno.land/x/tabler_icons_tsx@0.0.4/tsx/brand-github.tsx";
32-
export { default as ExternalLink } from "https://deno.land/x/tabler_icons_tsx@0.0.4/tsx/external-link.tsx";
33-
export { default as ChevronDown } from "https://deno.land/x/tabler_icons_tsx@0.0.4/tsx/chevron-down.tsx";
31+
export { default as Github } from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/brand-github.tsx";
32+
export { default as ExternalLink } from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/external-link.tsx";
33+
export { default as ChevronDown } from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/chevron-down.tsx";
34+
export { default as IconMenu2 } from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/menu-2.tsx";
3435

3536
export { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.3/command/mod.ts";
3637

37-
export { type Plugin, unified } from "https://esm.sh/unified@11.0.0";
38-
export { default as remarkParse } from "https://esm.sh/remark-parse@10.0.2";
39-
export { default as remarkGfm } from "https://esm.sh/remark-gfm@3.0.1";
40-
export { default as remarkRehype } from "https://esm.sh/remark-rehype@10.1.0";
41-
export { default as rehypeStringify } from "https://esm.sh/rehype-stringify@9.0.3";
38+
export { type Plugin, unified } from "https://esm.sh/unified@11.0.4";
39+
export { default as remarkParse } from "https://esm.sh/remark-parse@11.0.0";
40+
export { default as remarkGfm } from "https://esm.sh/remark-gfm@4.0.0";
41+
export { default as remarkRehype } from "https://esm.sh/remark-rehype@11.0.0";
42+
export { default as rehypeStringify } from "https://esm.sh/rehype-stringify@10.0.0";
4243

4344
export {
4445
all,
4546
createStarryNight,
4647
type Grammar,
47-
} from "https://esm.sh/@wooorm/starry-night@2.1.1";
48-
export { toString } from "https://esm.sh/hast-util-to-string@2.0.0";
48+
} from "https://esm.sh/@wooorm/starry-night@3.2.0";
49+
export { toString } from "https://esm.sh/hast-util-to-string@3.0.0";
4950
export { visit } from "https://esm.sh/unist-util-visit@5.0.0";
5051
export {
5152
type Element,

src/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export async function build() {
110110
Deno.mkdirSync(resolve("build", folder), { recursive: true });
111111
Deno.writeTextFileSync(
112112
resolve("build", folder, "index.html"),
113-
await render(config, magic, folder, plugins),
113+
await render(magic, folder, plugins),
114114
);
115115
}
116116

src/dev.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ export async function dev(hostname = "0.0.0.0", port = 8000) {
9292

9393
return new Response(
9494
await render(
95-
config,
9695
getMagic(),
9796
resolve("pages", pathname.slice(1)),
9897
plugins,

src/lib/page.tsx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Config, FileTypes, JSX, Magic, RouteMap } from "./types.ts";
2-
import { ExternalLink, Github, posix } from "../../deps.ts";
2+
import { ExternalLink, Github, IconMenu2, posix } from "../../deps.ts";
33
import { renderMD } from "../utils.tsx";
44
import { Sidebar } from "./sidebar.tsx";
55

@@ -13,9 +13,20 @@ export function Header(props: {
1313
}) {
1414
return (
1515
<header class="w-full h-16 shadow-sm flex gap-4 items-center px-4 bg-white dark:bg-black text-gray-800 dark:text-gray-200 z-10">
16+
<details class="sm:hidden">
17+
<summary class="text-black dark:text-white hover:text-gray-800 dark:hover:text-gray-300">
18+
<IconMenu2 />
19+
</summary>
20+
<div class="bg-white dark:bg-black absolute top-0 left-0 h-screen">
21+
<Sidebar
22+
class="w-64 p-2 border-r border-gray-200 dark:border-gray-700 pt-4 flex flex-col gap-2"
23+
route="TOP"
24+
/>
25+
</div>
26+
</details>
1627
<a href="/">
1728
<h1 class="font-semibold text-lg text-gray-800 flex items-center gap-2 dark:text-gray-200 mr-4">
18-
<image src="/icon.png" class="w-8 h-8" />
29+
<img src="/icon.png" class="w-8 h-8" />
1930
{props.title}
2031
</h1>
2132
</a>
@@ -25,7 +36,7 @@ export function Header(props: {
2536
{props.github && (
2637
<a
2738
target="_blank"
28-
class="text-black dark:text-white"
39+
class="text-black dark:text-white hover:text-gray-800 dark:hover:text-gray-300"
2940
href={props.github}
3041
>
3142
<Github />
@@ -45,12 +56,12 @@ export function Footer(
4556
) {
4657
return (
4758
<footer class="px-4 py-12 w-full flex justify-center text-gray-800 dark:text-gray-200 border-t dark:border-gray-700 bg-white dark:bg-black">
48-
<div class="max-w-screen-lg w-full flex flex-wrap justify-around">
59+
<div class="max-w-screen-lg w-full flex flex-col sm:flex-row flex-wrap justify-around">
4960
<image src="/icon.png" class="w-8 h-8" />
5061
{Object.entries(props.footer).map((
5162
[name, value],
5263
) => (
53-
<div>
64+
<div class="py-4 sm:py-0">
5465
<p class="font-bold pb-4">{name}</p>
5566
<ul class="flex flex-col gap-2">
5667
{value.map((value) => (
@@ -69,7 +80,7 @@ export function Footer(
6980
</ul>
7081
</div>
7182
))}
72-
<div class="h-full flex flex-col justify-around">
83+
<div class="py-4 sm:h-full flex flex-row-reverse sm:flex-col justify-around">
7384
{props.copyright && (
7485
<p class="whitespace-pre text-gray-500 dark:text-gray-400 text-sm">
7586
{props.copyright}
@@ -82,7 +93,7 @@ export function Footer(
8293
class="w-min"
8394
href={props.github}
8495
>
85-
<Github class="text-gray-500 hover:text-gray-900" />
96+
<Github class="text-gray-500 hover:text-gray-900 dark:hover:text-gray-300" />
8697
</a>
8798
)}
8899
</div>
@@ -100,7 +111,6 @@ export async function page(props: {
100111
};
101112
options: {
102113
markdown: string;
103-
route_map: RouteMap[];
104114
route: string;
105115
config: Config;
106116
magic: Magic;
@@ -171,12 +181,11 @@ export async function page(props: {
171181
>
172182
{!hide_navbar && (
173183
<Sidebar
174-
class="w-64 p-2 border-r border-gray-200 dark:border-gray-700 pt-4 flex flex-col gap-2"
175-
route_map={props.options.route_map}
184+
class="w-64 p-2 border-r border-gray-200 dark:border-gray-700 pt-4 hidden sm:flex flex-col gap-2"
176185
route={props.options.route}
177186
/>
178187
)}
179-
<div class="flex-grow max-w-screen-lg flex flex-col gap-8 py-4 overflow-hidden">
188+
<div class="flex-grow max-w-screen-lg flex flex-col gap-8 py-4 px-4 overflow-hidden">
180189
<h1 class="text-5xl font-bold text-gray-800 dark:text-gray-100">
181190
{props.page.title}
182191
</h1>

src/lib/render.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010

1111
import { Footer, Header, page } from "./page.tsx";
1212
import { get_route_map, resolve_file } from "./route_map.ts";
13-
import type { Config, Magic, PluginResult } from "./types.ts";
14-
import { getHeaderElements, importBuild } from "../utils.tsx";
13+
import type { Magic, PluginResult } from "./types.ts";
14+
import { getHeaderElements, importBuild, readConfig } from "../utils.tsx";
1515

1616
const unoConfig = existsSync("./uno.config.ts")
1717
? (await importBuild("./uno.config.ts")).default
@@ -36,12 +36,12 @@ async function applyUno(html: string) {
3636
}
3737

3838
export async function render(
39-
config: Config,
4039
magic: Magic,
4140
path: string,
4241
plugins: PluginResult[],
4342
dev = false,
4443
) {
44+
const config = readConfig();
4545
const base_path = resolve("pages", path);
4646
const [file_type, markdown] = resolve_file(base_path);
4747

@@ -85,7 +85,7 @@ export async function render(
8585
}
8686

8787
const frontmatter = extract(markdown);
88-
const route_map = get_route_map(resolve("pages"), true);
88+
get_route_map(resolve("pages"), true);
8989

9090
const title = frontmatter.attrs.title as string ?? "No Title";
9191
const description = frontmatter.attrs.description as string ??
@@ -99,7 +99,6 @@ export async function render(
9999
page: { title, description, hide_navbar },
100100
options: {
101101
markdown,
102-
route_map,
103102
route: "/" + path,
104103
config,
105104
magic,

src/lib/route_map.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export function resolve_file(path: string) {
1111
);
1212
}
1313

14+
export let global_route_map: RouteMap[] = [];
15+
1416
export function get_route_map(directory: string, top_level = false) {
15-
const route_map: RouteMap[] = [];
17+
const route_map = [];
1618

1719
for (const entry of Deno.readDirSync(directory)) {
1820
if (entry.name.startsWith("_")) continue;
@@ -51,5 +53,9 @@ export function get_route_map(directory: string, top_level = false) {
5153

5254
route_map.sort((a, b) => a.index - b.index);
5355

56+
if (top_level) {
57+
global_route_map = route_map;
58+
}
59+
5460
return route_map;
5561
}

src/lib/sidebar.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
import { ChevronDown } from "../../deps.ts";
22
import type { RouteMap } from "./types.ts";
3+
import { global_route_map } from "./route_map.ts";
4+
import { readConfig } from "../utils.tsx";
35

46
function simplify(url: string) {
57
return url.replaceAll("/", "").replaceAll("-", "");
68
}
79

810
export function Sidebar(
9-
props: { route_map: RouteMap[]; class: string; route: string },
11+
props: { route_map?: RouteMap[]; class: string; route: string },
1012
) {
13+
const config = readConfig();
14+
const route_map = props.route_map ?? global_route_map;
1115
return (
1216
<div class={props.class}>
13-
{props.route_map.map((route) => (
17+
{!props.route_map && (
18+
<a href="/">
19+
<h1 class="font-semibold text-lg text-gray-800 dark:text-gray-200 flex items-center gap-2 mr-4">
20+
<img src="/icon.png" class="w-8 h-8" />
21+
{config.title}
22+
</h1>
23+
</a>
24+
)}
25+
{route_map.map((route) => (
1426
<>
1527
{route.sub_route_map
1628
? (

src/utils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export async function importBuild(entrypoint: string) {
149149
bundle: true,
150150
write: false,
151151
format: "esm",
152-
jsxImportSource: "https://esm.sh/preact@10.17.0",
152+
jsxImportSource: "https://esm.sh/preact@10.19.3",
153153
jsx: "automatic",
154154
});
155155
const file = new TextDecoder().decode(result.outputFiles[0].contents);

tests/end_to_end/unocss/uno.config.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import {
2-
defineConfig,
3-
presetTypography,
4-
presetUno,
5-
} from "https://esm.sh/unocss@0.55.2";
1+
import { presetUno } from "https://esm.sh/@unocss/preset-uno@0.58.0";
2+
import { presetTypography } from "https://esm.sh/@unocss/preset-typography@0.58.0";
63

7-
export default defineConfig({
4+
export default {
85
presets: [
96
presetUno({
107
dark: "media",
118
}),
129
presetTypography(),
1310
],
14-
});
11+
};

www/pages/core-concepts/unocss.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,34 @@ Pyro uses UnoCSS for styling, both internally and for user code. By default, the
88
configuration that Pyro uses for UnoCSS looks something like:
99

1010
```ts
11-
import { defineConfig, presetUno } from "https://esm.sh/unocss@0.55.2";
11+
import { presetUno } from "https://esm.sh/@unocss/preset-uno@0.58.0";
1212

13-
export default defineConfig({
13+
export default {
1414
presets: [
1515
presetUno({
1616
dark: "media",
1717
}),
1818
],
19-
});
19+
};
2020
```
2121

2222
Some users would prefer to have more UnoCSS features. This is supported with
2323
zero extra configuration outside of just making the file! At the top level of
2424
your site, just add a `uno.config.ts` file. Below is an example of configuring
25-
UnoCSS to add the `presetTypography` plugin.
25+
UnoCSS to add the `presetTypography` plugin. Make sure not to import from the
26+
main `uno` package, as that is unsupported.
2627

2728
```ts
2829
// uno.config.ts
29-
import {
30-
defineConfig,
31-
presetTypography,
32-
presetUno,
33-
} from "https://esm.sh/unocss@0.55.2";
30+
import { presetUno } from "https://esm.sh/@unocss/preset-uno@0.58.0";
31+
import { presetTypography } from "https://esm.sh/@unocss/preset-typography@0.58.0";
3432

35-
export default defineConfig({
33+
export default {
3634
presets: [
3735
presetUno({
3836
dark: "media",
3937
}),
4038
presetTypography(),
4139
],
42-
});
40+
};
4341
```

0 commit comments

Comments
 (0)