-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug in website badge, allow specifying website name (left part of badge) #949
Conversation
Hi! Thanks for this. Could you include a couple examples of badges which should work, which fail with the old regex? Did #720 break something that used to work? |
@paulmelnikow Sure! In The problem was that I hadn't excluded slashes in the "up/down" and "colour" capture groups, so the last one could greedily gobble past the following slash. I don't think #720 broke anything that used to work, as before, if would simply fail to parse correctly anything with subdirectories after the domain name. #720 fixed that when no options (up/down text + colour) were given, but I had overlooked the fact that when options are given, they must not contain slashes. This PR (#949) fixes that problem, allows specifying the text on the left part of the badge instead of the rather generic "website", so that one can have a |
index.html
Outdated
<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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move these changes to try.html
? Sorry, but this file is autogenerated from that one.
server.js
Outdated
return escapeFormat(t) | ||
// Double slash | ||
.replace(/\/\//g, '//'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#952 does not seem to move the definition of escapeFormat
, so I suppose this should be okay, right?
server.js
Outdated
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Calling this label
would make the intent clearer.
I did some quick testing: Works:
Expected to work, but doesn't: |
@paulmelnikow I applied the changes you suggested on the diff (and used the term "label" in the documentation too, as it is indeed clearer). I'm trying to install shields.io and its dependencies to figure out why some of the URLs still don't work. |
@paulmelnikow I'm trying to install shields inside a vanilla Ubuntu 14.04 VirtualBox machine, using these commands (from the
However, I get the following error (when trying to run a checkout of the
Did I miss some obvious step somewhere? |
Ah, you need Node 6 or later: Feel free to PR those instructions, if you'd like. |
By the way, what's your dev machine? You probably can run it directly. |
@paulmelnikow Thanks, I opened a PR for INSTALL.md here: #955. I'm running NixOS, which was a somewhat unfortunate decision for a development machine. It has a completely write-protected /usr tree, even for sudo, and stock executables cannot be run directly, they must be patched. It also isolates applications in a rather strict way, to force all dependencies to be explicit. This allows NixOS to have a "purely functional" package manager, guaranteeing that a given configuration will always yield the same installed files, and allowing multiple versions of libraries to coexist. It sounds great on paper, but in practice it is a bit of a pain as installing any non-packaged tool which ships binaries requires patching them, and specifying their list of dependencies. So usually, I don't even bother, and pop up a VM :) . |
38c47f5
to
aff1488
Compare
…was improperly parsed). Allow specifying website name (left part of the badge).
@paulmelnikow I tested the three problematic URLs that you mentioned, there were a few small issues (an extra dash before the label, and double slashes were not properly un-escaped, and incorrect handling of the label-only case when it contains dashes), but aside from these issues they seem to work. Are you sure you were on the right branch when testing? I tried with these urls, each giving the the badge following it:
In principle, it is not possible to make the "down" or "label" parts start with a double dash, as the meaning is ambiguous and the dash ends up as the last character of the preceding group. However this is a rather unlikely use case, and a zero-width no-break-space can be used to disambiguate, without affecting the graphical output.
Of course, these are contrived examples, and hopefully most people should be plenty satisfied by the following :)
|
aff1488
to
8087843
Compare
Thanks for the thorough testing! All the examples are working now. Seems entirely possible I was on the wrong branch. Whoops! After #937 is merged, would be great to circle back and add some good tests of this badge, which seems particularly tricky. Possibly a test of the helper functions would help to clarify why they exist. |
@jsmaniac - For what it's worth, you should also be able to use Docker. There's a Dockerfile in this repo. |
- Build index.html at deploy time - Update corresponding documentation references - Since index.html is untracked, git add needs -f - Clarify gh-pages generated commit message - Improve Makefile dependencies related to website generation As discussed in #936, tracking the index.html causes makes PRs longer / noisier and causes extra merge conflicts. More importantly, it causes contributors to inadvertently edit the wrong file, which causes extra work (#949) or contributions to be lost (#898). Since there's no need for index.html in development (everything uses try.html) a logical solution is to generate and commit the index.html at deploy time. Recording compiled or generated files in a deploy commit is a reasonable practice for git-based deploys (Heroku, gh-pages, and others). The old version of this was slightly "unsafe" for my taste, in that it depended on the local copy of gh-pages (if it existed) and master. The new version just replaces gh-pages with master + the new commit. Closes #936. Fixes #954 (the PR).
@jsmaniac I realized |
@paulmelnikow Indeed, I didn't know there was a I just pushed an update which removes the label-handling code for |
I didn't either! The logic is in |
@paulmelnikow Thanks for merging #720.
I double-checked the regexp, and realised that there was still a bug when the
up-down
and colour options were specified. Sorry about that, hopefully this regexp fixes these issues (I tested it more thoroughly at https://regex101.com/r/xTAHin/1).I also added support for specifying the left part of the badge, so that one can easily make badges that look like
docs|online
,downloads|online
,official site|up
and so on. This change is backwards-compatible, as it can only occur when an odd number of options is present (eitherSiteName
, orup-down-SiteName
, orup-down-green-red-SiteName
, in addition to the previously supported formats “empty”,up-down
andup-down-green-red
which all had an even number of options).Could you have a look at this PR?