Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add link support for all badges#1172

Merged
paulmelnikow merged 1 commit into
badges:masterfrom
RedSparr0w:links_support
Oct 17, 2017
Merged

Add link support for all badges#1172
paulmelnikow merged 1 commit into
badges:masterfrom
RedSparr0w:links_support

Conversation

@RedSparr0w

@RedSparr0w RedSparr0w commented Oct 13, 2017

Copy link
Copy Markdown
Member

Relates to:
#852
#598
closes #1079

Add link support to the following badges:

  • flat
  • flat-square
  • plastic

Adjust social badge

  • if only 1 link supplied the whole badge will use that link
  • only use hover effects if badge contains a link
  • remove link if no link specified (currently links to undefined)

For all badges if only 1 link is supplied the whole badge will use that link (currently no way to manually specify a second link) you can specify the second link using link=//firstlink.com&link=//secondlink.com

Also the only way i know of that a badge will show the links is if it is included via:
<object data="linktobadge.svg"/>

Add link support to the following badges:
- flat
- flat-square
- plastic
Adjust social badge
- if only 1 link supplied the whole badge will use that link
- only use hover effects if badge contains a link
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-1172 October 13, 2017 23:31 Inactive
@paulmelnikow

Copy link
Copy Markdown
Member

Thanks for looking into this. Have you made sense of the discussion in #598? This seems like it's the same fix. Does it patch around the Chrome bug somehow?

@paulmelnikow paulmelnikow added the core Server, BaseService, GitHub auth, Shared helpers label Oct 13, 2017
@RedSparr0w

RedSparr0w commented Oct 13, 2017

Copy link
Copy Markdown
Member Author

The main difference is the <a> doesn't surround the text in this PR so it wont change the color of the text.

I have basically just added this to the bottom of each template:

  {{?(it.links[0] && it.links[0].length)}}
    <a xlink:href="{{=it.links[0]}}">
      <rect width="{{=it.widths[0]}}" height="20" fill="rgba(0,0,0,0)"/>
    </a>
  {{?}}
  {{?(it.links[0] && it.links[0].length || it.links[1] && it.links[1].length)}}
    <a xlink:href="{{=it.links[1] || it.links[0]}}">
      <rect x="{{=it.widths[0]}}" width="{{=it.widths[1]}}" height="20" fill="rgba(0,0,0,0)"/>
    </a>
  {{?}}

which adds another rect object over top of the text and original rect so it isn't linked to the text,
And once it has been visited will not change the text color.

@RedSparr0w

RedSparr0w commented Oct 14, 2017

Copy link
Copy Markdown
Member Author

One thing i have just realised:
For some reason you cannot overwrite the links on badges which already include a link (for social style)

Examples:

https://shields-staging-pr-1172.herokuapp.com/github/forks/badges/shields.svg?style=social&label=Fork&link=//google.com
will link to https://github.com still.

https://shields-staging-pr-1172.herokuapp.com/github/forks/badges/shields.svg?style=flat&label=Fork&link=//google.com
will link to https://google.com as expected (although the second half should still link to github as it has been set)

https://shields-staging-pr-1172.herokuapp.com/github/forks/badges/shields.svg?style=flat&label=Fork
will not have any links, even though it should have the github links.

https://shields-staging-pr-1172.herokuapp.com/badge/test-badge-blue.svg?style=social&label=Fork&link=//google.com
This social badge will include the user specified link because it wasn't set by server.js

Not sure why this is happening,
The templates are using the exact same variable.

@paulmelnikow

Copy link
Copy Markdown
Member

Ah, right, the problem is in the server code, not the templates.

shields/server.js

Lines 3690 to 3696 in 14286e1

if (badgeData.template === 'social') {
badgeData.logo = getLogo('github', data);
badgeData.links = [
'https://github.com/' + user + '/' + repo + '/fork',
'https://github.com/' + user + '/' + repo + '/network',
];
}

After this PR, can we turn on the links everywhere instead of limiting them to the social badges?

When we do that, we should let the user-provided link(s) override the default ones in code. Basically we should handle it the same as the label. To see what I mean, take a look at the way we use getLabel aka makeLabel.

function makeLabel(defaultLabel, overrides) {
return overrides.label || defaultLabel;
}

@paulmelnikow

Copy link
Copy Markdown
Member

I feel like this is good to merge! Do you agree?

Also, I wanted to ask: would you be interested in joining as a maintainer? You've shown a real interest in fixing some long-standing issues with the badge templates, developing powerful and flexible new badges, and fixing bugs here and there. It would be great to have your help reviewing contributions and contributing in whatever way you'd like. Would appreciate having you on board!

@paulmelnikow

Copy link
Copy Markdown
Member

Just wanted to follow up! Do you think this is ready to merge?

Are you interested in being a maintainer? 😃

@RedSparr0w

Copy link
Copy Markdown
Member Author

Yeah should be ready to merge,
Think it would be best to update the social link handling/overrides in a separate PR just to keep things tidier.

Thanks for the offer,
I would love to join the team as a maintainer! 😄

@paulmelnikow paulmelnikow merged commit a83d43a into badges:master Oct 17, 2017
@RedSparr0w RedSparr0w deleted the links_support branch November 1, 2017 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Server, BaseService, GitHub auth, Shared helpers

Development

Successfully merging this pull request may close these issues.

link query parameter for non social styles

2 participants