Skip to content

Commit

Permalink
Fix bug in website badge (specifying colours & test + subdirectories …
Browse files Browse the repository at this point in the history
…was improperly parsed). Allow specifying website name (left part of the badge).
  • Loading branch information
SuzanneSoy committed Apr 19, 2017
1 parent 07cedee commit 3b1fe43
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
14 changes: 12 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ <h3 id="downloads"> Downloads </h3>
<td><code>https://img.shields.io/chrome-web-store/d/nimelepbpejjlbmoobocpfnjhihnpked.svg</code></td>
</tr>
<tr><th data-keywords='website' data-doc='websiteDoc'> Website: </th>
<td><img src='https://img.shields.io/website-up-down-green-red/http/shields.io.svg?maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/website-up-down-green-red/http/shields.io.svg</code></td>
<td><img src='https://img.shields.io/website-up-down-green-red-my--website/http/shields.io.svg?maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/website-up-down-green-red-my--website/http/shields.io.svg</code></td>
</tr>
<tr><th data-keywords='cocoapods'> CocoaPods: </th>
<td><img src='https://img.shields.io/cocoapods/dt/AFNetworking.svg?maxAge=2592000' alt='' /></td>
Expand Down Expand Up @@ -1202,10 +1202,16 @@ <h2 id="like-this"> Like This? </h2>
<ul>
<li>Nothing:
<code>…/website/…</code></li>
<li>Website name, as displayed in the left part of the badge:
<code>…/website-mysitename.com/…</code></li>
<li>Online and offline text:
<code>…/website-up-down/…</code></li>
<li>Online and offline text, then website name:
<code>…/website-up-down-mysitename.com/…</code></li>
<li>Online and offline text, then online and offline colors:
<code>…/website-up-down-green-orange/…</code></li>
<li>Online and offline text, then online and offline colors, then website name:
<code>…/website-up-down-green-orange-mysitename.com/…</code></li>
</ul>
<table class=centered><tbody>
<tr><td> Dashes <code>--</code>
Expand All @@ -1216,6 +1222,10 @@ <h2 id="like-this"> Like This? </h2>
</td><td>
</td><td> <code>_</code> Underscore <br/>
</td></tr>
<tr><td> Slashes <code>//</code>
</td><td>
</td><td> <code>/</code> Slash <br/>
</td></tr>
<tr><td> <code>_</code> or Space <code>&nbsp;</code>
</td><td>
</td><td> <code>&nbsp;</code> Space
Expand Down
26 changes: 17 additions & 9 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5833,21 +5833,22 @@ cache(function(data, match, sendBadge, request) {
}));

// Test if a webpage is online
camp.route(/^\/website(-(([^-]|--)*?)-(([^-]|--)*)(-(([^-]|--)+)-(([^-]|--)+))?)?\/([^/]+)\/(.+)\.(svg|png|gif|jpg|json)$/,
camp.route(/^\/website(-(([^-/]|--|\/\/)*?)-(([^-/]|--|\/\/)*)(-(([^-/]|--|\/\/)+)-(([^-/]|--|\/\/)+))?)?(-(([^-/]|--|\/\/)+))?\/([^/]+)\/(.+)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var onlineMessage = escapeFormat(match[2] != null ? match[2] : "online");
var offlineMessage = escapeFormat(match[4] != null ? match[4] : "offline");
var onlineColor = escapeFormat(match[7] != null ? match[7] : "brightgreen");
var offlineColor = escapeFormat(match[9] != null ? match[9] : "red");
var userProtocol = match[11];
var userURI = match[12];
var format = match[13];
var onlineMessage = escapeFormatSlashes(match[2] != null ? match[2] : "online");
var offlineMessage = escapeFormatSlashes(match[4] != null ? match[4] : "offline");
var onlineColor = escapeFormatSlashes(match[7] != null ? match[7] : "brightgreen");
var offlineColor = escapeFormatSlashes(match[9] != null ? match[9] : "red");
var websiteName = escapeFormatSlashes(match[12] != null ? match[11] : "website");
var userProtocol = match[14];
var userURI = match[15];
var format = match[16];
var withProtocolURI = userProtocol + "://" + userURI;
var options = {
method: 'HEAD',
uri: withProtocolURI,
};
var badgeData = getBadgeData('website', data);
var badgeData = getBadgeData(websiteName, data);
badgeData.colorscheme = undefined;
request(options, function(err, res) {
// We consider all HTTP status codes below 310 as success.
Expand Down Expand Up @@ -6159,6 +6160,13 @@ function escapeFormat(t) {
.replace(/__/g, '_').replace(/--/g, '-');
}

function escapeFormatSlashes(t) {
return escapeFormat(t)
// Double slash
.replace(/\/\//g, '//');
}


function sixHex(s) { return /^[0-9a-fA-F]{6}$/.test(s); }

function getLabel(label, data) {
Expand Down

0 comments on commit 3b1fe43

Please sign in to comment.