[READ-ONLY] a fast, modern browser for the npm registry
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: support tree files in image path resolver (#866)

Co-authored-by: Daniel Roe <daniel@roe.dev>

authored by

Alex Savelyev
Daniel Roe
and committed by
GitHub
c035a32f 517d0218

+13 -6
+1 -1
app/components/VersionSelector.vue
··· 546 546 <span 547 547 v-else 548 548 class="w-3 h-3 transition-transform duration-200 rtl-flip" 549 - :class="group.isExpanded ? 'i:carbon:chevron-down' : 'i-carbon:chevron-right'" 549 + :class="group.isExpanded ? 'i-carbon:chevron-down' : 'i-carbon:chevron-right'" 550 550 aria-hidden="true" 551 551 /> 552 552 </button>
+2 -2
server/utils/readme.ts
··· 2 2 import sanitizeHtml from 'sanitize-html' 3 3 import { hasProtocol } from 'ufo' 4 4 import type { ReadmeResponse, TocItem } from '#shared/types/readme' 5 - import { convertBlobToRawUrl, type RepositoryInfo } from '#shared/utils/git-providers' 5 + import { convertBlobOrFileToRawUrl, type RepositoryInfo } from '#shared/utils/git-providers' 6 6 import { highlightCodeSync } from './shiki' 7 7 import { convertToEmoji } from '#shared/utils/emoji' 8 8 ··· 258 258 function resolveImageUrl(url: string, packageName: string, repoInfo?: RepositoryInfo): string { 259 259 const resolved = resolveUrl(url, packageName, repoInfo) 260 260 if (repoInfo?.provider) { 261 - return convertBlobToRawUrl(resolved, repoInfo.provider) 261 + return convertBlobOrFileToRawUrl(resolved, repoInfo.provider) 262 262 } 263 263 return resolved 264 264 }
+10 -3
shared/utils/git-providers.ts
··· 48 48 getRawBaseUrl(ref: RepoRef, branch?: string): string 49 49 /** Get blob/rendered URL base for markdown files */ 50 50 getBlobBaseUrl(ref: RepoRef, branch?: string): string 51 + /** Convert file URLs to blob URLs (for images) */ 52 + fileToRaw?(url: string): string 51 53 /** Convert blob URLs to raw URLs (for images) */ 52 54 blobToRaw?(url: string): string 53 55 } ··· 69 71 `https://raw.githubusercontent.com/${ref.owner}/${ref.repo}/${branch}`, 70 72 getBlobBaseUrl: (ref, branch = 'HEAD') => 71 73 `https://github.com/${ref.owner}/${ref.repo}/blob/${branch}`, 74 + fileToRaw: url => url.replace('/tree/', '/raw/'), 72 75 blobToRaw: url => url.replace('/blob/', '/raw/'), 73 76 }, 74 77 { ··· 386 389 return providers.find(p => p.id === providerId) 387 390 } 388 391 389 - export function convertBlobToRawUrl(url: string, providerId: ProviderId): string { 392 + export function convertBlobOrFileToRawUrl(url: string, providerId: ProviderId): string { 390 393 const provider = providers.find(p => p.id === providerId) 394 + let rawUrl = url 395 + if (provider?.fileToRaw) { 396 + rawUrl = provider.fileToRaw(url) 397 + } 391 398 if (provider?.blobToRaw) { 392 - return provider.blobToRaw(url) 399 + rawUrl = provider.blobToRaw(rawUrl) 393 400 } 394 - return url 401 + return rawUrl 395 402 } 396 403 397 404 export function isKnownGitProvider(url: string): boolean {