Skip to content

Commit 7e561f6

Browse files
danielroekheiner
andcommitted
fix(github): set max size of 460
Co-authored-by: Kevin Heiner <kheiner@gmail.com>
1 parent 237e480 commit 7e561f6

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

docs/content/3.providers/github.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,21 @@ links:
1111
Easily use GitHub avatars in your Nuxt app.
1212

1313

14-
Just pass the username as the `src` prop and set the width and height. Since GitHub avatars must always be square, the largest dimension is used as the size.
14+
Just pass the username as the `src` prop and set the width or height. Since GitHub avatars must always be square, the largest dimension is used as the size.
1515

1616

1717
```vue
1818
<!-- Width and Height -->
1919
<NuxtImg provider="github" src="nuxt" height="50" width="50" />
2020
21-
<!-- Width only -->
21+
<!-- Width above 460 resolves to the default size of 460 -->
2222
<NuxtImg provider="github" src="unjs" width="512" />
2323
2424
<!-- Default size -->
2525
<NuxtImg provider="github" src="npm"/>
2626
```
2727

28+
29+
::note
30+
GitHub Avatars are returned with a minimum size of 1 and maximum size of 460 with a default size of 460. Values outside of the bounds will return the default.
31+
::

src/runtime/providers/github.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ export default defineProvider<GitHubOptions>({
1515
getImage: (src, { modifiers, baseURL = 'https://avatars.githubusercontent.com/' }) => {
1616
let size = 460 // Default size
1717
// Calculate size based on width/height
18-
if (modifiers?.width || modifiers?.height) {
19-
size = Math.max(modifiers?.height ?? 0, modifiers?.width ?? 0)
18+
const requestedSize = Math.max(modifiers?.height ?? 0, modifiers?.width ?? 0)
19+
if (requestedSize > 0) {
20+
size = Math.min(Math.max(1, requestedSize), 460)
2021
}
2122

2223
const operations = operationsGenerator({

0 commit comments

Comments
 (0)