convert homepage link to openExternal (#432)

* #429 forgot to convert one

* trim github slug of release/tags

---------

Co-authored-by: neil molina <neil@neils-MacBook-Pro.local>
This commit is contained in:
Neil 2023-04-11 12:23:32 +08:00 committed by GitHub
parent 663e0a37b8
commit 4aab5fa0e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 7 deletions

View file

@ -11,6 +11,7 @@
import { shellOpenExternal } from "@native";
import InstallButton from "$components/install-button/install-button.svelte";
import { findAvailableVersions } from "$libs/packages/pkg-utils";
import { trimGithubSlug } from "$libs/github";
export let pkg: GUIPackage;
@ -46,9 +47,8 @@
<article class="w-2/3 p-4 pt-8">
<h3 class="text-primary text-3xl">{pkg.full_name}</h3>
{#if pkg.homepage}
<a target="_blank" rel="noreferrer" href={pkg.homepage}>
<span>{pkg.homepage}</span>
</a>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<span on:click={() => shellOpenExternal(pkg.homepage)} >{pkg.homepage}</span>
{/if}
<p class="mt-4 text-sm">{pkg.desc}</p>
<menu class="mt-4 grid h-10 grid-cols-3 gap-4 text-xs">
@ -78,7 +78,10 @@
type="plain"
color="black"
onClick={() => {
shellOpenExternal(`https://github.com/${pkg.github}`);
if (pkg.github) {
const slug = trimGithubSlug(pkg.github);
shellOpenExternal(`https://github.com/${slug}`);
}
}}>{$t("common.view-on-github")}</Button
>
{/if}

View file

@ -46,3 +46,8 @@ export async function getRepoAsPackage(owner: string, repo: string): Promise<Par
}
return pkg;
}
export const trimGithubSlug = (slug: string): string => {
const [owner, repo] = slug.split("/");
return [owner, repo].join("/");
};

View file

@ -19,6 +19,7 @@ import type { Package } from "@tea/ui/types";
import { trackInstall, trackInstallFailed } from "$libs/analytics";
import { addInstalledVersion } from "$libs/packages/pkg-utils";
import withDebounce from "$libs/utils/debounce";
import { trimGithubSlug } from "$libs/github";
const log = window.require("electron-log");
@ -55,7 +56,7 @@ export default function initPackagesStore() {
};
const syncPackageData = async (guiPkg: Partial<GUIPackage> | undefined) => {
if (!guiPkg || guiPkg.synced) return;
if (!guiPkg) return;
const pkg = await getPackage(guiPkg.full_name!); // ATM: pkg only bottles and github:string
const readmeMd = `# ${guiPkg.full_name} #
@ -65,7 +66,8 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}).
const updatedPackage: Partial<GUIPackage> = {
...pkg,
readme_md: readmeMd,
synced: true
synced: true,
github: pkg.github ? trimGithubSlug(pkg.github) : ""
};
if (pkg.github) {
const [owner, repo] = pkg.github.split("/");

View file

@ -4,7 +4,6 @@
import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";
import { shellOpenExternal } from "@native";
dayjs.extend(relativeTime);
export let pkg: Package;
@ -27,6 +26,7 @@
return `${(n / divisor).toFixed(2)} ${unit}`;
};
console.log(pkg);
</script>
<section class="bg-black pt-2">