fix: strip hash and search from project name #251

This commit is contained in:
Rohid
2024-08-15 22:30:23 +06:00
parent 769f6fd921
commit fce2c9cc50
2 changed files with 9 additions and 6 deletions

View File

@@ -2,12 +2,14 @@ export const IS_EDGE = navigator.userAgent.includes('Edg');
export const IS_FIREFOX = navigator.userAgent.includes('Firefox');
export const IS_CHROME = IS_EDGE === false && IS_FIREFOX === false;
export const generateProjectFromDevSites = (url: string): string | null => {
const githubUrls = ['https://github.com/', 'https://github.dev/'];
export const generateProjectFromDevSites = (siteUrl: string): string | null => {
const url = new URL(siteUrl);
const githubUrls = ['github.com', 'github.dev'];
for (const githubUrl of githubUrls) {
if (url.startsWith(githubUrl)) {
const newUrl = url.replace(githubUrl, '');
return newUrl.split('/')[1] || null;
if (url.host === githubUrl) {
// input: https://github.com/wakatime/browser-wakatime?tab=readme-ov-file#development-instructions
// output: browser-wakatime
return url.pathname.split('/')[2] || null;
}
}
return null;