Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
865 changes: 433 additions & 432 deletions packages/cli/cmd/openknowledge/viewer_assets/viewer.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/web/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_PUBLIC_POSTHOG_KEY=phc_DdrSDBCkEZqVKPSeTdgAFPjj2xhJrbWWoLJfGW8Wkp39
VITE_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.com
2 changes: 2 additions & 0 deletions packages/web/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_PUBLIC_POSTHOG_KEY=phc_your_project_token
VITE_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.com
3 changes: 2 additions & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"node": ">=18"
},
"dependencies": {
"mermaid": "11.15.0"
"mermaid": "11.15.0",
"posthog-js": "^1.409.5"
},
"devDependencies": {
"@types/node": "^20.19.43",
Expand Down
3 changes: 3 additions & 0 deletions packages/web/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { posthog } from "./posthog";

const copyButtons = Array.from(document.querySelectorAll<HTMLButtonElement>(".copy-command"));
const copiedTimers = new WeakMap<HTMLButtonElement, ReturnType<typeof setTimeout>>();
const releaseBadge = document.querySelector<HTMLElement>("[data-release-badge]");
Expand Down Expand Up @@ -39,6 +41,7 @@ for (const copy of copyButtons) {
label.textContent = "Copied";
clearTimeout(copiedTimers.get(copy));
await copyText(text);
posthog.capture("command_copied");
copiedTimers.set(
copy,
setTimeout(() => {
Expand Down
29 changes: 29 additions & 0 deletions packages/web/src/posthog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import posthog from "posthog-js";

const token = import.meta.env.VITE_PUBLIC_POSTHOG_KEY;
const host = import.meta.env.VITE_PUBLIC_POSTHOG_HOST;

if (!token) {
if (import.meta.env.DEV) {
throw new Error(
"VITE_PUBLIC_POSTHOG_KEY variable required by PostHog is missing or un-configured, this causes events to be silently missed. This error stops appearing once VITE_PUBLIC_POSTHOG_KEY is configured",
);
}
} else if (!host) {
if (import.meta.env.DEV) {
throw new Error(
"VITE_PUBLIC_POSTHOG_HOST variable required by PostHog is missing or un-configured, this causes events to be silently missed. This error stops appearing once VITE_PUBLIC_POSTHOG_HOST is configured",
);
}
} else {
posthog.init(token, {
api_host: host,
capture_exceptions: {
capture_unhandled_errors: true,
capture_unhandled_rejections: true,
capture_console_errors: false,
},
});
}

export { posthog };
7 changes: 7 additions & 0 deletions packages/web/src/viewer/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import { posthog } from "../posthog";

(function () {
const workspace = document.querySelector("[data-note-workspace]");
const stackEl = document.querySelector("[data-note-stack]");
Expand Down Expand Up @@ -3531,6 +3533,9 @@

async function openTarget(targetPath, pushHistory, openBeside, highlightText, sourcePanel) {
const source = sourcePanel || activePanel();
posthog.capture("note_opened", {
open_mode: openBeside ? "beside" : "replace",
});
if (!source) {
await openInitialNote(targetPath, pushHistory, highlightText);
return;
Expand Down Expand Up @@ -3568,6 +3573,7 @@
}

async function closePanel(panel, pushHistory) {
posthog.capture("note_closed");
const before = panels();
const index = before.indexOf(panel);
let nextPanel;
Expand Down Expand Up @@ -4195,6 +4201,7 @@
const shiftOverride = event.shiftKey || searchResult.dataset.openBeside === "true";
const openBeside = shouldOpenBeside(shiftOverride);
delete searchResult.dataset.openBeside;
posthog.capture("search_result_opened");
closeSearchResults(searchResult);
openTarget(targetPath, true, openBeside, highlightFromHref(searchResult.getAttribute("href") || searchResult.href), activePanel());
return;
Expand Down
70 changes: 70 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
packages:
- "packages/*"

allowBuilds:
core-js: set this to true or false
esbuild: set this to true or false

onlyBuiltDependencies:
- esbuild
Loading