This repository has been archived by the owner on Jun 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 625
/
Copy pathmain.ts
64 lines (56 loc) · 1.55 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
57
58
59
60
61
62
63
64
// 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 { 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,
namespace?: string,
property?: string,
) {
const url = new URL(current);
if (symbol) {
let s = symbol;
if (namespace) {
s = `${namespace}.${s}`;
}
url.searchParams.set("s", s);
} 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 = ctx.handler();
serve(handler);