Skip to content

Commit

Permalink
fix: wrong url for placeholder badge (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
amio authored Aug 1, 2023
1 parent 9ee8d02 commit 1c5b2c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions components/badgen-title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default function BadgenTitle ({ host }) {
.title.hidden {
opacity: 0;
transform: translateY(-20px);
pointer-events: none;
}
.title.show {
transition-delay: 100ms;
Expand Down
25 changes: 13 additions & 12 deletions components/builder-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const BadgePreview = ({ host, badgeURL, focus }) => {
<BadgenTitle host={host} />
</div>
<div className={'preview ' + (showPreview ? 'show' : 'none')}>
<PreviewBadge host={host} url={badgeURL} />
<PreviewBadge badgePath={badgeURL} />
</div>
<style jsx>{`
.header-preview {
Expand All @@ -32,6 +32,7 @@ const BadgePreview = ({ host, badgeURL, focus }) => {
.title.hidden {
opacity: 0;
transform: translateY(-20px);
pointer-events: none;
}
.title.show {
transition-delay: 100ms;
Expand All @@ -53,20 +54,20 @@ const BadgePreview = ({ host, badgeURL, focus }) => {
)
}

const PreviewBadge = ({ host, url }) => {
// eslint-disable-next-line @next/next/no-img-element
return <img alt={url} style={{ height: '30px' }} src={genBadgeSrc(host, url)} />
}
const PreviewBadge = ({ badgePath }) => {
let src: string // the final badge image src path

const genBadgeSrc = (host: string, url: string) => {
if (!url) {
return host + 'static/%20/%20'
}
if (url.split('/').length > 2) {
return host + url
if (!badgePath) {
src = '/static/%20/%20'
} else if (badgePath.split('/').length > 2) {
// if it looks like a valid badge path
src = badgePath
} else {
return host + 'static/%20/%20'
src = `/static/%20/%20`
}

// eslint-disable-next-line @next/next/no-img-element
return <a href={src}><img alt={badgePath} style={{ height: '30px' }} src={src} /></a>
}

export default BadgePreview

1 comment on commit 1c5b2c1

@vercel
Copy link

@vercel vercel bot commented on 1c5b2c1 Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.