forked from denoland/dotland
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
56 lines (48 loc) · 1.48 KB
/
main.ts
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
// Copyright 2022-2023 the Deno authors. All rights reserved. MIT license.
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
import { ServerContext } from "$fresh/server.ts";
import { serve } from "$std/http/server.ts";
import { lookupSymbol } from "./utils/doc_utils.ts";
import { withLog } from "./utils/ga_utils.ts";
import { setup } from "$doc_components/services.ts";
import twindPlugin from "$fresh/plugins/twind.ts";
import twindConfig from "./twind.config.ts";
import manifest from "./fresh.gen.ts";
await setup({
resolveHref(current: URL, symbol?: string, property?: string) {
const url = new URL(current);
if (symbol) {
url.searchParams.set("s", symbol);
} else {
url.searchParams.delete("s");
}
if (property) {
url.searchParams.set("p", property);
} else {
url.searchParams.delete("p");
}
return url.href;
},
lookupHref(
current: URL,
namespace: string | undefined,
symbol: string,
): string | undefined {
return lookupSymbol(current, namespace, symbol);
},
resolveSourceHref(url, line) {
if (!url.startsWith("https://deno.land")) {
return url;
}
return line ? `${url}?source#L${line}` : `${url}?source`;
},
});
const ctx = await ServerContext.fromManifest(manifest, {
plugins: [twindPlugin(twindConfig)],
});
const handler = withLog(ctx.handler());
serve(handler);