Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/hooks/use-pretty-repo-url.ts
2500 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { useMemo } from "react";
8
9
// Given a URL string:
10
// * Strips protocol
11
// * Removes a trailing .git if present
12
export const usePrettyRepoURL = (url: string) => {
13
return useMemo(() => {
14
let urlString = url;
15
try {
16
const parsedURL = new URL(url);
17
urlString = `${parsedURL.host}${parsedURL.pathname}`;
18
} catch (e) {}
19
20
return urlString.endsWith(".git") ? urlString.slice(0, -4) : urlString;
21
}, [url]);
22
};
23
24