feat(plugins): polish plugin marketplace listing display
This commit is contained in:
3 files changed
+63
-13
No files matched your search
+6
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildMarketplacePluginListings, filterMarketplacePluginListings, selectMarketplaceArtifact } from "./pluginMarketplace";
|
||||
import { buildMarketplacePluginListings, filterMarketplacePluginListings, marketplaceHomepageUrl, selectMarketplaceArtifact } from "./pluginMarketplace";
|
||||
import type { InstalledPlugin, PluginRepositoryCatalogResult } from "@/types/database";
|
||||
|
||||
const result: PluginRepositoryCatalogResult = {
|
||||
@@ -81,4 +81,9 @@ describe("plugin marketplace listings", () => {
|
||||
|
||||
expect(selectMarketplaceArtifact(artifacts, "darwin-arm64")?.target).toBe("darwin-arm64");
|
||||
});
|
||||
|
||||
it("treats a repository URL and its homepage URL as one link", () => {
|
||||
expect(marketplaceHomepageUrl("https://github.com/dbxio/example/", "https://github.com/dbxio/example#readme")).toBeUndefined();
|
||||
expect(marketplaceHomepageUrl("https://github.com/dbxio/example", "https://dbxio.com/plugins/example")).toBe("https://dbxio.com/plugins/example");
|
||||
});
|
||||
});
|
||||
@@ -17,6 +17,18 @@ export interface MarketplacePluginListing {
|
||||
status: MarketplacePluginStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the homepage only when it points somewhere different from the
|
||||
* source repository. Marketplace metadata often repeats the repository URL in
|
||||
* both fields, which otherwise renders two identical links.
|
||||
*/
|
||||
export function marketplaceHomepageUrl(source?: string, homepage?: string): string | undefined {
|
||||
const normalizedSource = normalizeExternalUrl(source);
|
||||
const normalizedHomepage = normalizeExternalUrl(homepage);
|
||||
if (!normalizedHomepage || normalizedHomepage === normalizedSource) return undefined;
|
||||
return homepage?.trim() || undefined;
|
||||
}
|
||||
|
||||
export function buildMarketplacePluginListings(results: readonly PluginRepositoryCatalogResult[], installedPlugins: readonly InstalledPlugin[], locale: string): MarketplacePluginListing[] {
|
||||
const installedById = new Map(installedPlugins.map((plugin) => [plugin.manifest.id, plugin]));
|
||||
return results
|
||||
@@ -104,3 +116,16 @@ function parseVersion(version: string): [number, number, number, string] | null
|
||||
if (!match) return null;
|
||||
return [Number(match[1]), Number(match[2]), Number(match[3]), match[4] || "~"];
|
||||
}
|
||||
|
||||
function normalizeExternalUrl(value?: string): string | undefined {
|
||||
const trimmed = value?.trim();
|
||||
if (!trimmed) return undefined;
|
||||
try {
|
||||
const parsed = new URL(trimmed);
|
||||
parsed.hash = "";
|
||||
parsed.pathname = parsed.pathname.replace(/\/+$/, "") || "/";
|
||||
return `${parsed.protocol.toLowerCase()}//${parsed.host.toLowerCase()}${parsed.pathname}${parsed.search}`;
|
||||
} catch {
|
||||
return trimmed.replace(/\/+$/, "").toLowerCase();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user