-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(website): refactor fetch cannonfile (website-build-refactor) (#1639
- Loading branch information
1 parent
0ef0551
commit 38ed522
Showing
3 changed files
with
37 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { isCannonFileURL } from '@/helpers/isCannonFileURL'; | ||
|
||
export type CannonfileGitInfo = { | ||
gitUrl: string; | ||
gitRef: string; | ||
gitFile: string; | ||
}; | ||
|
||
const EMPTY_GIT_INFO: CannonfileGitInfo = { | ||
gitUrl: '', | ||
gitRef: '', | ||
gitFile: '', | ||
}; | ||
|
||
export function useGitInfoFromCannonFileUrl(cannonfileUrlInput: string): CannonfileGitInfo { | ||
if (!isCannonFileURL(cannonfileUrlInput) || !cannonfileUrlInput.includes('/blob/')) { | ||
return EMPTY_GIT_INFO; | ||
} | ||
|
||
const [url, blobPath] = cannonfileUrlInput.split('/blob/'); | ||
const urlComponents = blobPath.split('/'); | ||
const branchName = urlComponents[0]; | ||
const filePath = urlComponents.slice(1).join('/'); | ||
|
||
return { | ||
gitUrl: url, | ||
gitRef: branchName, | ||
gitFile: filePath, | ||
}; | ||
} |