Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(extension): fall back to rendered GitHub repository metadata

tianma-if65e946effb2b
diff --git a/apps/extension/github-repo.test.mjs b/apps/extension/github-repo.test.mjs
index a27beda4..1a4ba619 100644
--- a/apps/extension/github-repo.test.mjs
+++ b/apps/extension/github-repo.test.mjs
@@ -1,4 +1,7 @@
import { describe, expect, test } from "bun:test";
+import { createWindow } from "@mixmark-io/domino";
+import { createContext, runInContext } from "node:vm";
+import { bundleTestScripts } from "./bundle-test-scripts.mjs";
import {
cleanRepoDescription,
githubRepoFactsFromSource,
@@ -71,6 +74,38 @@ describe("github repository addresses", () => {
});
describe("github repository card", () => {
+ test("captures rendered repository facts when initial JSON is missing or too large", () => {
+ const [script] = bundleTestScripts(["capture-github"]);
+ for (const json of ["", JSON.stringify({ ownerLogin: "tianma-if", readme: "x".repeat(500_000) })]) {
+ const window = createWindow(`
+ <meta name="octolytics-dimension-repository_nwo" content="tianma-if/edgeever">
+ <script type="application/json">${json}</script>
+ <div class="sidebarSection__oqw6Y8">
+ <h2>About</h2><p class="description__ej4leF">A portable notes workspace.</p>
+ <div class="websiteRow__c4vvco"><a href="https://edgeever.org">edgeever.org</a></div>
+ <a href="/topics/notes">notes</a>
+ <a href="#license"><svg class="octicon-law"></svg>AGPL-3.0 license</a>
+ </div>`, "https://github.com/tianma-if/edgeever/tree/main");
+ Object.getPrototypeOf(window.document.querySelectorAll("span"))[Symbol.iterator] ??= Array.prototype[Symbol.iterator];
+ let result;
+ runInContext(script, createContext({
+ document: window.document,
+ location: window.location,
+ __edgeeverGithubClipPayload: { requestId: "regression" },
+ chrome: { runtime: { sendMessage: (message) => { result = message.result; } } },
+ }));
+ expect(result?.ok).toBe(true);
+ expect(result.source.embeddedJsonChunks).toEqual([]);
+ expect(githubRepoFactsFromSource(result.source)).toMatchObject({
+ owner: "tianma-if", name: "edgeever", intro: "A portable notes workspace.",
+ homepage: "https://edgeever.org/", topics: ["notes"], license: "AGPL-3.0",
+ });
+ expect(githubRepoFactsFromSource({ ...result.source, repositoryNwo: "other/repo" })).toBeNull();
+ expect(githubRepoFactsFromSource({ ...result.source, repositoryNwo: undefined })).toBeNull();
+ expect(githubRepoFactsFromSource({ ...result.source, pageUrl: "https://github.com/features/copilot" })).toBeNull();
+ }
+ });
+
test("drops GitHub's generated description and the repository suffix", () => {
expect(cleanRepoDescription(
"Open-source notes. - tianma-if/edgeever",
diff --git a/apps/extension/src/background.ts b/apps/extension/src/background.ts
index e9ff0c88..9bc75dff 100644
--- a/apps/extension/src/background.ts
+++ b/apps/extension/src/background.ts
@@ -1213,6 +1213,7 @@ const isGithubRepoSource = (value: unknown): value is GithubRepoPageSource => {
const strings = (items: unknown): items is string[] =>
Array.isArray(items) && items.every((item) => typeof item === "string");
return typeof record.pageUrl === "string"
+ && (record.repositoryNwo === undefined || typeof record.repositoryNwo === "string")
&& typeof record.openGraphDescription === "string"
&& strings(record.embeddedJsonChunks)
&& typeof record.aboutText === "string"
diff --git a/apps/extension/src/capture-github.ts b/apps/extension/src/capture-github.ts
index 167ac8ac..3bbc42ee 100644
--- a/apps/extension/src/capture-github.ts
+++ b/apps/extension/src/capture-github.ts
@@ -28,7 +28,7 @@
if (chunks.length >= 4) break;
}
- const about = document.querySelector('[class*="SidebarAbout-module__description"]');
+ const about = document.querySelector('[class*="SidebarAbout-module__description"], [class*="sidebarSection"] p[class*="description"], .repository-content .BorderGrid-cell p.f4');
const website = document.querySelector('[class*="website"] a[href^="http"], a[class*="website"][href^="http"]');
const topics: string[] = [];
for (const link of document.querySelectorAll('a[class*="TopicTag"], a[href^="/topics/"]')) {
@@ -83,6 +83,7 @@
ok: true,
source: {
pageUrl: location.href,
+ repositoryNwo: metaContent('meta[name="octolytics-dimension-repository_nwo"]'),
openGraphDescription: metaContent('meta[property="og:description"]'),
embeddedJsonChunks: chunks,
aboutText: text(about),
diff --git a/apps/extension/src/github-repo.ts b/apps/extension/src/github-repo.ts
index 9a6756da..a887d8b3 100644
--- a/apps/extension/src/github-repo.ts
+++ b/apps/extension/src/github-repo.ts
@@ -9,6 +9,7 @@ export type GithubRepoTarget = {
export type GithubRepoPageSource = {
pageUrl: string;
+ repositoryNwo?: string;
openGraphDescription: string;
embeddedJsonChunks: string[];
aboutText: string;
@@ -217,11 +218,14 @@ export const githubRepoFactsFromSource = (source: GithubRepoPageSource): GithubR
}
}
const matched = records.filter((record) => sameName(record.owner, target.owner) && sameName(record.name, target.name));
- if (matched.length === 0) return null;
+ // Client-side navigation can omit the initial JSON, and large READMEs can
+ // exceed the snapshot's JSON limit. GitHub's repository metadata provides
+ // an independent identity check before falling back to rendered content.
+ const metadataMatches = sameName(source.repositoryNwo?.trim() ?? "", `${target.owner}/${target.name}`);
+ if (matched.length === 0 && !metadataMatches) return null;
const richest = matched.find((record) => record.description || record.topics.length || record.homepage) ?? matched[0];
- if (!richest) return null;
- const owner = richest.owner;
- const name = richest.name;
+ const owner = richest?.owner ?? target.owner;
+ const name = richest?.name ?? target.name;
const description = [
...matched.map((record) => record.description),
source.aboutText,