MCPcopy Index your code
hub / github.com/ColmapView/Colmapview.github.io / normalizeGitHostingUrl

Function normalizeGitHostingUrl

src/utils/urlUtils.ts:205–242  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

203 * Supports: HuggingFace, GitHub, GitLab, Bitbucket, Gitea, Codeberg
204 */
205export function normalizeGitHostingUrl(url: string): string {
206 // HuggingFace: Convert tree/main or blob/main to resolve/main
207 if (url.includes('huggingface.co')) {
208 return url
209 .replace('/tree/main/', '/resolve/main/')
210 .replace('/blob/main/', '/resolve/main/');
211 }
212
213 // GitHub: Convert to raw.githubusercontent.com
214 // https://github.com/user/repo/blob/main/path -> https://raw.githubusercontent.com/user/repo/main/path
215 const githubMatch = url.match(/^https?:\/\/github\.com\/([^/]+)\/([^/]+)\/(blob|tree)\/([^/]+)\/(.*)$/);
216 if (githubMatch) {
217 const [, user, repo, , branch, path] = githubMatch;
218 return `https://raw.githubusercontent.com/${user}/${repo}/${branch}/${path}`;
219 }
220
221 // GitLab (including self-hosted): Convert blob/tree to raw
222 // https://gitlab.com/user/repo/-/blob/main/path -> https://gitlab.com/user/repo/-/raw/main/path
223 if (url.includes('gitlab.com') || url.includes('gitlab.')) {
224 return url
225 .replace('/-/tree/', '/-/raw/')
226 .replace('/-/blob/', '/-/raw/');
227 }
228
229 // Bitbucket: Convert src to raw
230 // https://bitbucket.org/user/repo/src/main/path -> https://bitbucket.org/user/repo/raw/main/path
231 if (url.includes('bitbucket.org')) {
232 return url.replace('/src/', '/raw/');
233 }
234
235 // Gitea / Codeberg: Convert src/branch to raw/branch
236 // https://codeberg.org/user/repo/src/branch/main/path -> https://codeberg.org/user/repo/raw/branch/main/path
237 if (url.includes('codeberg.org') || url.includes('gitea.')) {
238 return url.replace('/src/branch/', '/raw/branch/');
239 }
240
241 return url;
242}
243
244/**
245 * Check if URL points to a JSON manifest file.

Callers 2

urlUtils.test.tsFile · 0.90
normalizeLoadUrlFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected