fix: default backlinks search to site-wide scope for root URLs (#96)

* fix: default backlinks search to site-wide scope for root URLs

URLs with an explicit protocol but no path (e.g. https://example.com/)
were incorrectly auto-selecting "Exact page" scope. Now only URLs with
an actual path beyond "/" trigger page scope auto-selection.

* test: update backlinks scope tests for root URL behavior change
This commit is contained in:
Ben Senescu 2026-04-07 23:51:39 -04:00 committed by Ben Senescu
parent 93c95dc8f7
commit fd3d9838fe
2 changed files with 9 additions and 3 deletions

View File

@ -16,12 +16,18 @@ describe("inferBacklinksSearchScopeFromTarget", () => {
);
});
it("treats explicit urls as page lookups", () => {
it("treats root urls with explicit protocol as domain lookups", () => {
expect(inferBacklinksSearchScopeFromTarget("https://example.com/")).toBe(
"page",
"domain",
);
});
it("treats explicit urls with a path as page lookups", () => {
expect(
inferBacklinksSearchScopeFromTarget("https://example.com/pricing"),
).toBe("page");
});
it("uses inferred scope until the user overrides it", () => {
expect(
resolveBacklinksSearchScope({

View File

@ -14,7 +14,7 @@ export function inferBacklinksSearchScopeFromTarget(
const parsed = new URL(
hasExplicitProtocol ? trimmed : `https://${trimmed}`,
);
return hasExplicitProtocol || parsed.pathname !== "/" ? "page" : "domain";
return parsed.pathname !== "/" ? "page" : "domain";
} catch {
return "domain";
}