@abraca/junis 2.86.0 → 2.88.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.d.mts +4 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +82 -8
- package/dist/runtime/assets/css/jun.css +2 -2
- package/dist/runtime/components/JunDocSurface.d.vue.ts +20 -2
- package/dist/runtime/components/JunDocSurface.vue +30 -2
- package/dist/runtime/components/JunDocSurface.vue.d.ts +20 -2
- package/dist/runtime/components/JunHead.vue +16 -4
- package/dist/runtime/components/JunNavDock.d.vue.ts +15 -0
- package/dist/runtime/components/JunNavDock.vue +94 -0
- package/dist/runtime/components/JunNavDock.vue.d.ts +15 -0
- package/dist/runtime/components/JunNavMenu.client.d.vue.ts +15 -0
- package/dist/runtime/components/JunNavMenu.client.vue +478 -0
- package/dist/runtime/components/JunNavMenu.client.vue.d.ts +15 -0
- package/dist/runtime/components/JunNavPreview.d.vue.ts +17 -0
- package/dist/runtime/components/JunNavPreview.vue +169 -0
- package/dist/runtime/components/JunNavPreview.vue.d.ts +17 -0
- package/dist/runtime/components/JunNavigation.d.vue.ts +4 -11
- package/dist/runtime/components/JunNavigation.vue +813 -138
- package/dist/runtime/components/JunNavigation.vue.d.ts +4 -11
- package/dist/runtime/components/JunNoteLinks.vue +1 -1
- package/dist/runtime/components/JunPageHero.vue +3 -3
- package/dist/runtime/components/JunSectionBar.d.vue.ts +41 -0
- package/dist/runtime/components/JunSectionBar.vue +144 -0
- package/dist/runtime/components/JunSectionBar.vue.d.ts +41 -0
- package/dist/runtime/components/renderers/JunConfigRenderer.vue +486 -6
- package/dist/runtime/components/renderers/JunEntryRenderer.vue +48 -0
- package/dist/runtime/components/renderers/JunGlobeRenderer.vue +43 -26
- package/dist/runtime/composables/useJunCreatePage.js +7 -1
- package/dist/runtime/composables/useJunDocPage.d.ts +28 -0
- package/dist/runtime/composables/useJunDocPage.js +111 -20
- package/dist/runtime/composables/useJunGarden.d.ts +1 -1
- package/dist/runtime/composables/useJunGarden.js +3 -2
- package/dist/runtime/composables/useJunGestures.d.ts +53 -0
- package/dist/runtime/composables/useJunGestures.js +89 -0
- package/dist/runtime/composables/useJunMenuState.d.ts +4 -0
- package/dist/runtime/composables/useJunMenuState.js +5 -0
- package/dist/runtime/composables/useJunNavItems.d.ts +50 -0
- package/dist/runtime/composables/useJunNavItems.js +188 -0
- package/dist/runtime/composables/useJunNavSettings.d.ts +58 -1
- package/dist/runtime/composables/useJunNavSettings.js +110 -8
- package/dist/runtime/composables/useJunOptions.d.ts +1 -0
- package/dist/runtime/composables/useJunSiblings.d.ts +30 -0
- package/dist/runtime/composables/useJunSiblings.js +38 -0
- package/dist/runtime/composables/useJunSiteConfig.d.ts +51 -3
- package/dist/runtime/composables/useJunTheme.js +4 -1
- package/dist/runtime/composables/useJunViewingAccent.js +10 -0
- package/dist/runtime/layouts/jun.vue +21 -1
- package/dist/runtime/pages/doc.vue +41 -35
- package/dist/runtime/pages/index.vue +63 -35
- package/dist/runtime/plugins/jun-doc-tree.d.ts +2 -0
- package/dist/runtime/plugins/jun-doc-tree.js +26 -0
- package/dist/runtime/server/api/health.get.d.ts +15 -0
- package/dist/runtime/server/api/health.get.js +7 -2
- package/dist/runtime/server/api/links.get.js +27 -3
- package/dist/runtime/server/api/resolve/[...slug].get.d.ts +20 -0
- package/dist/runtime/server/api/resolve/[...slug].get.js +33 -2
- package/dist/runtime/server/api/search.get.d.ts +1 -1
- package/dist/runtime/server/api/search.get.js +42 -39
- package/dist/runtime/server/api/tree.get.d.ts +9 -0
- package/dist/runtime/server/api/tree.get.js +25 -0
- package/dist/runtime/server/janitor/junJanitorActor.d.ts +13 -0
- package/dist/runtime/server/janitor/junJanitorActor.js +36 -5
- package/dist/runtime/server/janitor/junJanitorChores.d.ts +14 -7
- package/dist/runtime/server/janitor/junJanitorChores.js +21 -3
- package/dist/runtime/server/janitor/junJanitorMachine.js +36 -4
- package/dist/runtime/server/janitor/junJanitorPerform.d.ts +15 -1
- package/dist/runtime/server/janitor/junJanitorPerform.js +13 -5
- package/dist/runtime/server/janitor/junJanitorYText.d.ts +40 -3
- package/dist/runtime/server/janitor/junJanitorYText.js +60 -14
- package/dist/runtime/server/plugins/jun-janitor.js +132 -81
- package/dist/runtime/server/routes/jun-card.png.get.d.ts +2 -0
- package/dist/runtime/server/routes/jun-card.png.get.js +40 -0
- package/dist/runtime/server/utils/junCard.d.ts +39 -0
- package/dist/runtime/server/utils/junCard.js +159 -0
- package/dist/runtime/server/utils/junIcon.d.ts +27 -2
- package/dist/runtime/server/utils/junIcon.js +5 -5
- package/dist/runtime/server/utils/junJanitorStatus.d.ts +59 -0
- package/dist/runtime/server/utils/junJanitorStatus.js +27 -0
- package/dist/runtime/types.d.ts +225 -0
- package/dist/runtime/utils/junAdopt.d.ts +43 -0
- package/dist/runtime/utils/junAdopt.js +7 -0
- package/dist/runtime/utils/junGesture.d.ts +84 -0
- package/dist/runtime/utils/junGesture.js +40 -0
- package/dist/runtime/utils/junLetters.d.ts +86 -0
- package/dist/runtime/utils/junLetters.js +173 -0
- package/dist/runtime/utils/junNavValue.d.ts +56 -0
- package/dist/runtime/utils/junNavValue.js +36 -0
- package/dist/runtime/utils/junSearchRank.d.ts +79 -0
- package/dist/runtime/utils/junSearchRank.js +73 -0
- package/dist/runtime/utils/junSocial.d.ts +59 -0
- package/dist/runtime/utils/junSocial.js +56 -0
- package/dist/runtime/utils/junViewSpecs.d.ts +38 -0
- package/dist/runtime/utils/junViewSpecs.js +92 -1
- package/package.json +10 -8
- /package/dist/runtime/components/{JunSectionPresence.client.d.vue.ts → JunSectionPresence.d.vue.ts} +0 -0
- /package/dist/runtime/components/{JunSectionPresence.client.vue → JunSectionPresence.vue} +0 -0
- /package/dist/runtime/components/{JunSectionPresence.client.vue.d.ts → JunSectionPresence.vue.d.ts} +0 -0
|
@@ -107,42 +107,48 @@ const cachedHtml = computed(() => hidden.value ? "" : resolved.value?.html ?? ""
|
|
|
107
107
|
above it made every page log the very warning the wrapper exists to
|
|
108
108
|
prevent — "does not have a single root node and will cause errors when
|
|
109
109
|
navigating between routes" — while navigation was in fact fine. A
|
|
110
|
-
warning that cries wolf on every page load is worse than no warning.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
/>
|
|
126
|
-
</div>
|
|
127
|
-
</div>
|
|
128
|
-
</template>
|
|
110
|
+
warning that cries wolf on every page load is worse than no warning.
|
|
111
|
+
|
|
112
|
+
**There is no `<ClientOnly>` here any more, and that is the point.**
|
|
113
|
+
It used to wrap everything below, with the cached body in its
|
|
114
|
+
`#fallback` — so the SERVER rendered a page's prose and nothing else,
|
|
115
|
+
and the renderer that draws the actual page (a poll's options, a
|
|
116
|
+
cinema's films, a collection's children) only ever existed in the
|
|
117
|
+
browser. `jun-doc-tree` now seeds the whole tree into the payload and
|
|
118
|
+
`<ADocRenderer>` draws from it, so the real renderer runs here on the
|
|
119
|
+
server. `:html` is still handed down for the renderer's own `#loading`
|
|
120
|
+
slot, which covers the window before a child document's body arrives. -->
|
|
121
|
+
<JunNotFound
|
|
122
|
+
v-if="notFound || hidden"
|
|
123
|
+
:path="route.path"
|
|
124
|
+
/>
|
|
129
125
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
126
|
+
<JunDocSurface
|
|
127
|
+
v-else-if="docId"
|
|
128
|
+
:doc-id="docId"
|
|
129
|
+
:bucket="bucket"
|
|
130
|
+
:flow-max-w="flowMaxW"
|
|
131
|
+
:render-key="renderKey"
|
|
132
|
+
:editable="editing"
|
|
133
|
+
:entry="cachedEntry"
|
|
134
|
+
:html="cachedHtml"
|
|
135
|
+
:section="resolved?.section ?? null"
|
|
136
|
+
:trail="resolved?.trail"
|
|
137
|
+
breadcrumbs
|
|
138
|
+
/>
|
|
134
139
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
140
|
+
<!-- Nothing resolved yet: the cached body is still the best thing to show,
|
|
141
|
+
and it is what a crawler gets on a document the tree has not reached. -->
|
|
142
|
+
<div
|
|
143
|
+
v-else-if="cachedHtml"
|
|
144
|
+
class="min-h-screen pt-24"
|
|
145
|
+
>
|
|
146
|
+
<div :class="['mx-auto w-full', flowMaxW]">
|
|
147
|
+
<div
|
|
148
|
+
class="prose dark:prose-invert max-w-none"
|
|
149
|
+
v-html="cachedHtml"
|
|
150
|
+
/>
|
|
151
|
+
</div>
|
|
152
|
+
</div>
|
|
147
153
|
</div>
|
|
148
154
|
</template>
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed } from "vue";
|
|
3
3
|
import { useRouter } from "vue-router";
|
|
4
|
+
import { useFetch } from "#app";
|
|
4
5
|
import {
|
|
5
6
|
definePageMeta,
|
|
6
7
|
useAbracadabra,
|
|
7
8
|
useChildTree,
|
|
8
9
|
useDocSlugs,
|
|
9
|
-
useJunDocPage
|
|
10
|
+
useJunDocPage,
|
|
11
|
+
useJunOptions
|
|
10
12
|
} from "#imports";
|
|
11
13
|
definePageMeta({ layout: "jun" });
|
|
14
|
+
const { apiBase } = useJunOptions();
|
|
15
|
+
const request = useFetch(() => `${apiBase}/resolve`, {
|
|
16
|
+
ignoreResponseError: true
|
|
17
|
+
});
|
|
18
|
+
const resolved = request.data;
|
|
19
|
+
if (import.meta.server) await request;
|
|
12
20
|
const abra = useAbracadabra();
|
|
13
|
-
const docId = computed(() => abra.spaceDocId.value ?? null);
|
|
14
|
-
const { bucket, flowMaxW, renderKey, cachedEntry, editing } = useJunDocPage(docId);
|
|
21
|
+
const docId = computed(() => abra.spaceDocId.value ?? resolved.value?.docId ?? null);
|
|
22
|
+
const { bucket, flowMaxW, renderKey, cachedEntry, editing } = useJunDocPage(docId, { resolved });
|
|
23
|
+
const cachedHtml = computed(() => resolved.value?.html ?? "");
|
|
15
24
|
const childTree = useChildTree(abra.doc, "jun-index-child-create");
|
|
16
25
|
const { getDocUrl } = useDocSlugs();
|
|
17
26
|
const router = useRouter();
|
|
@@ -38,37 +47,56 @@ function addChild() {
|
|
|
38
47
|
standing warning about the exact failure you are guarding against is
|
|
39
48
|
worse than no warning: it is the one you stop reading.
|
|
40
49
|
|
|
41
|
-
The root doc resolves from the live CRDT connection
|
|
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
|
-
|
|
50
|
+
The root doc resolves from the live CRDT connection on the client, and
|
|
51
|
+
from the doc cache on the server — so unlike the note that used to sit
|
|
52
|
+
here, there IS cached HTML to emit, and the `#fallback` below is what
|
|
53
|
+
a crawler indexes and what a cold visitor reads before the socket is
|
|
54
|
+
up. Without it this page was blank until the CRDT synced, which is why
|
|
55
|
+
a slow or failed sync showed the front page as an empty column while
|
|
56
|
+
every other page still carried its prose.
|
|
57
|
+
|
|
58
|
+
**No `<ClientOnly>`, same as `doc.vue`.** The tree is in the payload
|
|
59
|
+
(`jun-doc-tree`), so the home renderer and its sections run on the
|
|
60
|
+
server. -->
|
|
61
|
+
<JunDocSurface
|
|
62
|
+
v-if="docId"
|
|
63
|
+
:doc-id="docId"
|
|
64
|
+
:bucket="bucket"
|
|
65
|
+
:flow-max-w="flowMaxW"
|
|
66
|
+
:render-key="renderKey"
|
|
67
|
+
:editable="editing"
|
|
68
|
+
:entry="cachedEntry"
|
|
69
|
+
:html="cachedHtml"
|
|
70
|
+
:section="resolved?.section ?? null"
|
|
71
|
+
:trail="resolved?.trail"
|
|
72
|
+
>
|
|
73
|
+
<template #footer>
|
|
74
|
+
<div
|
|
75
|
+
v-if="editing"
|
|
76
|
+
class="px-4 py-4 sm:px-8"
|
|
77
|
+
>
|
|
78
|
+
<UButton
|
|
79
|
+
icon="i-lucide-plus"
|
|
80
|
+
size="sm"
|
|
81
|
+
color="neutral"
|
|
82
|
+
variant="soft"
|
|
83
|
+
label="New page"
|
|
84
|
+
@click="addChild"
|
|
85
|
+
/>
|
|
86
|
+
</div>
|
|
87
|
+
</template>
|
|
88
|
+
</JunDocSurface>
|
|
89
|
+
|
|
90
|
+
<div
|
|
91
|
+
v-else-if="cachedHtml"
|
|
92
|
+
class="min-h-screen pt-24"
|
|
93
|
+
>
|
|
94
|
+
<div :class="['mx-auto w-full', flowMaxW]">
|
|
95
|
+
<div
|
|
96
|
+
class="prose dark:prose-invert max-w-none"
|
|
97
|
+
v-html="cachedHtml"
|
|
98
|
+
/>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
73
101
|
</div>
|
|
74
102
|
</template>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
|
|
2
|
+
import { useDocTreeSnapshot } from "#imports";
|
|
3
|
+
const KEY = "jun-doc-tree";
|
|
4
|
+
export default defineNuxtPlugin({
|
|
5
|
+
name: "jun:doc-tree",
|
|
6
|
+
enforce: "pre",
|
|
7
|
+
async setup(nuxtApp) {
|
|
8
|
+
const state = useDocTreeSnapshot();
|
|
9
|
+
if (nuxtApp.payload.data[KEY] !== void 0) {
|
|
10
|
+
state.value = nuxtApp.payload.data[KEY] ?? null;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const pub = useRuntimeConfig().public;
|
|
14
|
+
const apiBase = pub?.jun?.apiBase || "/api/_jun";
|
|
15
|
+
let value = null;
|
|
16
|
+
try {
|
|
17
|
+
const res = await $fetch(`${apiBase}/tree`);
|
|
18
|
+
if (res && typeof res === "object" && !Array.isArray(res) && typeof res.entries === "object" && res.entries !== null) {
|
|
19
|
+
value = res;
|
|
20
|
+
}
|
|
21
|
+
} catch {
|
|
22
|
+
}
|
|
23
|
+
nuxtApp.payload.data[KEY] = value;
|
|
24
|
+
state.value = value;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type JunJanitorStatus } from '../utils/junJanitorStatus.js';
|
|
1
2
|
import { type JunReadinessState } from '../../utils/junReadiness.js';
|
|
2
3
|
export interface JunHealthReport {
|
|
3
4
|
state: JunReadinessState;
|
|
@@ -14,6 +15,20 @@ export interface JunHealthReport {
|
|
|
14
15
|
sweptMsAgo: number | null;
|
|
15
16
|
rootDocId: string;
|
|
16
17
|
ageMs: number;
|
|
18
|
+
/**
|
|
19
|
+
* The `@abraca/junis` version this image was BUILT from — the answer to "is
|
|
20
|
+
* the fix actually deployed", which is not a question the source tree can be
|
|
21
|
+
* asked. See `JunRuntimeOptions.version`.
|
|
22
|
+
*/
|
|
23
|
+
version: string;
|
|
24
|
+
/** When this image was built, epoch ms — see `JunRuntimeOptions.builtAt`. */
|
|
25
|
+
builtAt: number | null;
|
|
26
|
+
/**
|
|
27
|
+
* What the janitor runner is doing. Reported even when the feature is off, so
|
|
28
|
+
* "there is no janitor" is always distinguishable from "there is no janitor
|
|
29
|
+
* IN THIS BUILD" — the two states that cost jun.is weeks.
|
|
30
|
+
*/
|
|
31
|
+
janitor: JunJanitorStatus;
|
|
17
32
|
}
|
|
18
33
|
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<JunHealthReport>>;
|
|
19
34
|
export default _default;
|
|
@@ -2,6 +2,7 @@ import { defineEventHandler, setResponseStatus } from "h3";
|
|
|
2
2
|
import { useRuntimeConfig, useStorage } from "nitropack/runtime";
|
|
3
3
|
import { junDocTree, junHeartbeat, junRootDocId, junSlugMap } from "../utils/junCache.js";
|
|
4
4
|
import { junBootedAt } from "../utils/junBoot.js";
|
|
5
|
+
import { junJanitorStatus } from "../utils/junJanitorStatus.js";
|
|
5
6
|
import { junReadiness } from "../../utils/junReadiness.js";
|
|
6
7
|
export default defineEventHandler(async (event) => {
|
|
7
8
|
const storage = useStorage();
|
|
@@ -13,7 +14,8 @@ export default defineEventHandler(async (event) => {
|
|
|
13
14
|
]);
|
|
14
15
|
const ageMs = Date.now() - junBootedAt();
|
|
15
16
|
const sweptMsAgo = beat && beat.at >= junBootedAt() ? Date.now() - beat.at : null;
|
|
16
|
-
const
|
|
17
|
+
const jun = useRuntimeConfig().public.jun ?? {};
|
|
18
|
+
const features = jun.features ?? {};
|
|
17
19
|
const verdict = junReadiness({
|
|
18
20
|
treeSize: Object.keys(tree).length,
|
|
19
21
|
slugCount: Object.keys(slugs).length,
|
|
@@ -35,6 +37,9 @@ export default defineEventHandler(async (event) => {
|
|
|
35
37
|
},
|
|
36
38
|
sweptMsAgo,
|
|
37
39
|
rootDocId: junRootDocId(),
|
|
38
|
-
ageMs
|
|
40
|
+
ageMs,
|
|
41
|
+
version: jun.version ?? "unknown",
|
|
42
|
+
builtAt: jun.builtAt ?? null,
|
|
43
|
+
janitor: junJanitorStatus()
|
|
39
44
|
};
|
|
40
45
|
});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { getQuery } from "h3";
|
|
1
2
|
import { defineCachedEventHandler } from "nitropack/runtime";
|
|
2
3
|
import { junDocHtml, junDocTree, junRootDocId, junSlugMap } from "../utils/junCache.js";
|
|
3
4
|
import { isJunOwnerOnlyDoc } from "../utils/junVisibility.js";
|
|
4
5
|
import { junGardenEdges, junMaturityOf } from "../../utils/junGarden.js";
|
|
5
|
-
export default defineCachedEventHandler(async () => {
|
|
6
|
+
export default defineCachedEventHandler(async (event) => {
|
|
6
7
|
const rootDocId = junRootDocId();
|
|
7
8
|
const [tree, idToSlug] = await Promise.all([junDocTree(), junSlugMap()]);
|
|
9
|
+
const doc = String(getQuery(event).doc ?? "").trim();
|
|
8
10
|
const nodes = [];
|
|
9
11
|
const slugToId = {};
|
|
10
12
|
const knownIds = /* @__PURE__ */ new Set();
|
|
@@ -28,10 +30,32 @@ export default defineCachedEventHandler(async () => {
|
|
|
28
30
|
nodes.map(async (node) => ({ id: node.id, html: await junDocHtml(node.id) }))
|
|
29
31
|
);
|
|
30
32
|
const scanned = bodies.filter((b) => b.html).length;
|
|
33
|
+
const edges = junGardenEdges(bodies, slugToId, knownIds);
|
|
34
|
+
if (doc) {
|
|
35
|
+
const mine = edges.filter((edge) => edge.source === doc || edge.target === doc);
|
|
36
|
+
const wanted = /* @__PURE__ */ new Set([doc]);
|
|
37
|
+
for (const edge of mine) {
|
|
38
|
+
wanted.add(edge.source);
|
|
39
|
+
wanted.add(edge.target);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
nodes: nodes.filter((node) => wanted.has(node.id)),
|
|
43
|
+
edges: mine,
|
|
44
|
+
scanned,
|
|
45
|
+
generatedAt: Date.now()
|
|
46
|
+
};
|
|
47
|
+
}
|
|
31
48
|
return {
|
|
32
49
|
nodes,
|
|
33
|
-
edges
|
|
50
|
+
edges,
|
|
34
51
|
scanned,
|
|
35
52
|
generatedAt: Date.now()
|
|
36
53
|
};
|
|
37
|
-
}, {
|
|
54
|
+
}, {
|
|
55
|
+
maxAge: 60,
|
|
56
|
+
swr: true,
|
|
57
|
+
name: "jun-links",
|
|
58
|
+
// The doc is PART OF THE KEY. Without it the first caller's answer — whole
|
|
59
|
+
// graph or one document's — would be served to the other for a minute.
|
|
60
|
+
getKey: (event) => `graph:${String(getQuery(event).doc ?? "")}`
|
|
61
|
+
});
|
|
@@ -11,6 +11,8 @@ declare const _default: import("h3").EventHandler<import("h3").EventHandlerReque
|
|
|
11
11
|
parentId?: undefined;
|
|
12
12
|
parentType?: undefined;
|
|
13
13
|
parentTitle?: undefined;
|
|
14
|
+
trail?: undefined;
|
|
15
|
+
section?: undefined;
|
|
14
16
|
} | {
|
|
15
17
|
found: true;
|
|
16
18
|
cacheReady: boolean;
|
|
@@ -24,6 +26,8 @@ declare const _default: import("h3").EventHandler<import("h3").EventHandlerReque
|
|
|
24
26
|
parentId?: undefined;
|
|
25
27
|
parentType?: undefined;
|
|
26
28
|
parentTitle?: undefined;
|
|
29
|
+
trail?: undefined;
|
|
30
|
+
section?: undefined;
|
|
27
31
|
} | {
|
|
28
32
|
found: true;
|
|
29
33
|
cacheReady: boolean;
|
|
@@ -35,6 +39,22 @@ declare const _default: import("h3").EventHandler<import("h3").EventHandlerReque
|
|
|
35
39
|
parentId: string | null;
|
|
36
40
|
parentType: string | null;
|
|
37
41
|
parentTitle: string | null;
|
|
42
|
+
trail: {
|
|
43
|
+
id: string;
|
|
44
|
+
title: string;
|
|
45
|
+
slug: string | null;
|
|
46
|
+
}[];
|
|
47
|
+
section: {
|
|
48
|
+
parentId: string;
|
|
49
|
+
parentTitle: string;
|
|
50
|
+
parentSlug: string | null;
|
|
51
|
+
items: {
|
|
52
|
+
id: string;
|
|
53
|
+
title: string;
|
|
54
|
+
slug: string | null;
|
|
55
|
+
icon: string | undefined;
|
|
56
|
+
}[];
|
|
57
|
+
} | null;
|
|
38
58
|
html: string | null;
|
|
39
59
|
ownerOnly?: undefined;
|
|
40
60
|
}>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineEventHandler, getRouterParam } from "h3";
|
|
2
|
-
import { junDocHtml, junDocTree, junSlugMap } from "../../utils/junCache.js";
|
|
2
|
+
import { junDocHtml, junDocTree, junRootDocId, junSlugMap } from "../../utils/junCache.js";
|
|
3
3
|
import { junDocIdForAlias } from "../../utils/junSlugAlias.js";
|
|
4
4
|
import { isJunOwnerOnlyDoc } from "../../utils/junVisibility.js";
|
|
5
5
|
export default defineEventHandler(async (event) => {
|
|
@@ -7,7 +7,7 @@ export default defineEventHandler(async (event) => {
|
|
|
7
7
|
const slug = raw.replace(/^\/+|\/+$/g, "");
|
|
8
8
|
const [tree, idToSlug] = await Promise.all([junDocTree(), junSlugMap()]);
|
|
9
9
|
const cacheReady = Object.keys(tree).length > 0;
|
|
10
|
-
let docId = Object.entries(idToSlug).find(([, s]) => s === slug)?.[0];
|
|
10
|
+
let docId = slug ? Object.entries(idToSlug).find(([, s]) => s === slug)?.[0] : junRootDocId();
|
|
11
11
|
let canonical = null;
|
|
12
12
|
if (!docId) {
|
|
13
13
|
const aliasId = junDocIdForAlias(tree, slug);
|
|
@@ -31,6 +31,35 @@ export default defineEventHandler(async (event) => {
|
|
|
31
31
|
}
|
|
32
32
|
const parentId = entry?.parentId ?? null;
|
|
33
33
|
const parent = parentId ? tree[parentId] : void 0;
|
|
34
|
+
const trail = [];
|
|
35
|
+
{
|
|
36
|
+
const seen = /* @__PURE__ */ new Set([docId]);
|
|
37
|
+
let cursor = parentId;
|
|
38
|
+
while (cursor && trail.length < 12 && !seen.has(cursor)) {
|
|
39
|
+
seen.add(cursor);
|
|
40
|
+
const node = tree[cursor];
|
|
41
|
+
if (!node || node.trashed || isJunOwnerOnlyDoc(node)) break;
|
|
42
|
+
trail.unshift({ id: cursor, title: node.label ?? "", slug: idToSlug[cursor] ?? null });
|
|
43
|
+
cursor = node.parentId ?? null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const rootId = junRootDocId();
|
|
47
|
+
const branch = trail.find((step) => step.id !== rootId);
|
|
48
|
+
const sectionParentId = branch?.id ?? (docId !== rootId && (!parentId || parentId === rootId) ? docId : null);
|
|
49
|
+
const sectionParent = sectionParentId ? tree[sectionParentId] : void 0;
|
|
50
|
+
const section = sectionParentId && sectionParent ? {
|
|
51
|
+
parentId: sectionParentId,
|
|
52
|
+
parentTitle: sectionParent.label ?? "",
|
|
53
|
+
parentSlug: idToSlug[sectionParentId] ?? null,
|
|
54
|
+
items: Object.entries(tree).filter(
|
|
55
|
+
([id, e]) => !!e && e.parentId === sectionParentId && id !== sectionParentId && !e.trashed && e.meta?.hidden !== true && e.meta?.draft !== true && !isJunOwnerOnlyDoc(e) && !e.meta?.signerId && e.meta?.replyTo == null && e.meta?.t == null
|
|
56
|
+
).sort(([, a], [, b]) => (a.order ?? 0) - (b.order ?? 0)).map(([id, e]) => ({
|
|
57
|
+
id,
|
|
58
|
+
title: e.label ?? "",
|
|
59
|
+
slug: idToSlug[id] ?? null,
|
|
60
|
+
icon: typeof e.meta?.icon === "string" ? e.meta.icon : void 0
|
|
61
|
+
})).slice(0, 40)
|
|
62
|
+
} : null;
|
|
34
63
|
return {
|
|
35
64
|
found: true,
|
|
36
65
|
cacheReady,
|
|
@@ -42,6 +71,8 @@ export default defineEventHandler(async (event) => {
|
|
|
42
71
|
parentId,
|
|
43
72
|
parentType: parent?.type ?? null,
|
|
44
73
|
parentTitle: parent?.label ?? null,
|
|
74
|
+
trail,
|
|
75
|
+
section,
|
|
45
76
|
html: await junDocHtml(docId)
|
|
46
77
|
};
|
|
47
78
|
});
|
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery } from "h3";
|
|
2
2
|
import { junDocHtml, junDocTree, junRootDocId, junSlugMap } from "../utils/junCache.js";
|
|
3
3
|
import { isJunOwnerOnlyDoc } from "../utils/junVisibility.js";
|
|
4
|
+
import { junSearchScore, junSearchSnippet, junSearchTerms } from "../../utils/junSearchRank.js";
|
|
4
5
|
const escapeHtml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
5
6
|
function toText(html) {
|
|
6
7
|
return html.replace(/<script[\s\S]*?<\/script>/gi, " ").replace(/<style[\s\S]*?<\/style>/gi, " ").replace(/<[^>]+>/g, " ").replace(/ /g, " ").replace(/\s+/g, " ").trim();
|
|
7
8
|
}
|
|
8
|
-
function markSnippet(text,
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
function markSnippet(text, terms) {
|
|
10
|
+
const { start, end, marks } = junSearchSnippet(text, terms);
|
|
11
|
+
let out = start > 0 ? "\u2026" : "";
|
|
12
|
+
let at = start;
|
|
13
|
+
for (const range of marks) {
|
|
14
|
+
if (range.start < at) continue;
|
|
15
|
+
out += escapeHtml(text.slice(at, range.start));
|
|
16
|
+
out += `<mark>${escapeHtml(text.slice(range.start, range.end))}</mark>`;
|
|
17
|
+
at = range.end;
|
|
18
|
+
}
|
|
19
|
+
out += escapeHtml(text.slice(at, end));
|
|
20
|
+
if (end < text.length) out += "\u2026";
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
function typeFilter(raw) {
|
|
24
|
+
const values = (Array.isArray(raw) ? raw : [raw]).flatMap((v) => String(v ?? "").split(",")).map((v) => v.trim()).filter(Boolean);
|
|
25
|
+
return values.length ? new Set(values) : null;
|
|
17
26
|
}
|
|
18
27
|
export default defineEventHandler(async (event) => {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
28
|
+
const query = getQuery(event);
|
|
29
|
+
const q = String(query.q ?? "").trim();
|
|
30
|
+
const limit = Math.min(Number(query.limit ?? 20) || 20, 50);
|
|
21
31
|
if (q.length < 2) return [];
|
|
22
|
-
const
|
|
32
|
+
const terms = junSearchTerms(q);
|
|
33
|
+
const types = typeFilter(query.type);
|
|
23
34
|
const rootId = junRootDocId();
|
|
24
35
|
const [tree, idToSlug] = await Promise.all([junDocTree(), junSlugMap()]);
|
|
25
36
|
const hits = [];
|
|
@@ -27,46 +38,38 @@ export default defineEventHandler(async (event) => {
|
|
|
27
38
|
if (!entry || entry.trashed) continue;
|
|
28
39
|
if (id === rootId) continue;
|
|
29
40
|
if (isJunOwnerOnlyDoc(entry)) continue;
|
|
41
|
+
if (types && !types.has(entry.type ?? "doc")) continue;
|
|
30
42
|
const label = entry.label ?? "";
|
|
31
43
|
const meta = entry.meta ?? {};
|
|
32
44
|
const excerpt = [meta.excerpt, meta.description].filter((v) => typeof v === "string" && !!v).join(" \u2014 ");
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
let
|
|
36
|
-
|
|
37
|
-
if (labelIdx === 0) rank = 100;
|
|
38
|
-
else if (labelIdx > 0) rank = 80;
|
|
39
|
-
if (excerptIdx >= 0 && rank < 60) {
|
|
40
|
-
rank = 60;
|
|
41
|
-
snippet = markSnippet(excerpt, q);
|
|
42
|
-
}
|
|
43
|
-
if (!rank) {
|
|
44
|
-
const body = typeof meta.body === "string" ? meta.body : "";
|
|
45
|
-
if (body && body.toLowerCase().includes(ql)) {
|
|
46
|
-
rank = 45;
|
|
47
|
-
snippet = markSnippet(body, q);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (!rank) {
|
|
45
|
+
const body = typeof meta.body === "string" ? meta.body : "";
|
|
46
|
+
let score = junSearchScore(terms, { label, excerpt, body });
|
|
47
|
+
let searchedBody = body;
|
|
48
|
+
if (!score) {
|
|
51
49
|
const html = await junDocHtml(id);
|
|
52
50
|
if (html) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
rank = 40;
|
|
56
|
-
snippet = markSnippet(text, q);
|
|
57
|
-
}
|
|
51
|
+
searchedBody = `${body} ${toText(html)}`.trim();
|
|
52
|
+
score = junSearchScore(terms, { label, excerpt, body: searchedBody });
|
|
58
53
|
}
|
|
59
54
|
}
|
|
60
|
-
if (!
|
|
55
|
+
if (!score) continue;
|
|
56
|
+
const haystack = [excerpt, searchedBody].find(
|
|
57
|
+
(text) => text && terms.every((t) => text.toLowerCase().includes(t))
|
|
58
|
+
) ?? excerpt ?? searchedBody;
|
|
61
59
|
hits.push({
|
|
62
60
|
id,
|
|
63
61
|
title: label || "Untitled",
|
|
64
62
|
href: `/${idToSlug[id] ?? id}`,
|
|
65
63
|
type: entry.type ?? "doc",
|
|
66
64
|
parentId: entry.parentId ?? null,
|
|
67
|
-
snippet,
|
|
68
|
-
rank
|
|
65
|
+
snippet: haystack ? markSnippet(haystack, terms) : void 0,
|
|
66
|
+
rank: Math.round(score),
|
|
67
|
+
updatedAt: typeof entry.updatedAt === "number" ? entry.updatedAt : 0
|
|
69
68
|
});
|
|
70
69
|
}
|
|
71
|
-
|
|
70
|
+
hits.sort((a, b) => b.rank - a.rank || b.updatedAt - a.updatedAt);
|
|
71
|
+
return hits.slice(0, limit).map(({ updatedAt, ...hit }) => {
|
|
72
|
+
void updatedAt;
|
|
73
|
+
return hit;
|
|
74
|
+
});
|
|
72
75
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface JunTreeSnapshot {
|
|
2
|
+
/** The space document's id — what `topLevelDocs` measures "top level" against. */
|
|
3
|
+
rootId: string;
|
|
4
|
+
/** Whether the cache holds anything at all; `false` means "not synced yet". */
|
|
5
|
+
ready: boolean;
|
|
6
|
+
entries: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<JunTreeSnapshot>>;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineEventHandler } from "h3";
|
|
2
|
+
import { junDocTree, junRootDocId } from "../utils/junCache.js";
|
|
3
|
+
import { isJunOwnerOnlyDoc } from "../utils/junVisibility.js";
|
|
4
|
+
const META_OMIT = /* @__PURE__ */ new Set(["routeGeo", "junSite"]);
|
|
5
|
+
export default defineEventHandler(async () => {
|
|
6
|
+
const rootId = junRootDocId();
|
|
7
|
+
const tree = await junDocTree();
|
|
8
|
+
const entries = {};
|
|
9
|
+
for (const [id, entry] of Object.entries(tree)) {
|
|
10
|
+
if (!entry) continue;
|
|
11
|
+
if (isJunOwnerOnlyDoc(entry)) continue;
|
|
12
|
+
let meta = entry.meta;
|
|
13
|
+
if (meta) {
|
|
14
|
+
const kept = {};
|
|
15
|
+
for (const [k, v] of Object.entries(meta)) {
|
|
16
|
+
if (META_OMIT.has(k)) continue;
|
|
17
|
+
if (k === "body" && meta.bodyIsMirror === true) continue;
|
|
18
|
+
kept[k] = v;
|
|
19
|
+
}
|
|
20
|
+
meta = kept;
|
|
21
|
+
}
|
|
22
|
+
entries[id] = meta ? { ...entry, meta } : entry;
|
|
23
|
+
}
|
|
24
|
+
return { rootId, ready: Object.keys(tree).length > 0, entries };
|
|
25
|
+
});
|
|
@@ -83,6 +83,19 @@ export declare class JunJanitorActor {
|
|
|
83
83
|
/** The root doc-tree, live. Read-only as far as the janitor is concerned. */
|
|
84
84
|
get tree(): Y.Map<unknown> | null;
|
|
85
85
|
get openDocId(): string | null;
|
|
86
|
+
/**
|
|
87
|
+
* `loginOrRegisterWithKey`, with the service runner's retry policy around it.
|
|
88
|
+
*
|
|
89
|
+
* Registration stays INSIDE the retried call rather than beside it: the
|
|
90
|
+
* "not registered" branch lives in `loginOrRegisterWithKey`, and a first boot
|
|
91
|
+
* that hits a 410 on its post-registration login has to be able to register
|
|
92
|
+
* (a no-op the second time — the server answers an already-registered key
|
|
93
|
+
* without creating anything) and try again.
|
|
94
|
+
*
|
|
95
|
+
* The last failure is rethrown unchanged, so a genuine credential error still
|
|
96
|
+
* surfaces with its own message rather than as "gave up after N attempts".
|
|
97
|
+
*/
|
|
98
|
+
private loginRetrying;
|
|
86
99
|
connect(): Promise<void>;
|
|
87
100
|
/**
|
|
88
101
|
* Where the janitor is. `docId` + `page` are the wire contract every presence
|