-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Shorten links #473
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
Shorten links #473
Conversation
4b0c850 to
999b8fa
Compare
|
I'd prefer to use colon as a separator between branch and file path as Git does. |
|
@hkdobrev I'm not familiar, can you show me? Also I'd accept suggestions on how to match something like: const regex = /(?=2)red/; // match 'red' only if it's preceded by 2?
console.log('0red'.replace(regex, 'blue')) // '0red'
console.log('2red'.replace(regex, 'blue')) // '2red' but I want '2blue' |
src/content.js
Outdated
| } | ||
|
|
||
| function shortenVisibleUrls() { | ||
| $('a[href]').get().forEach(a => { |
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.
Prefer a for-of loop whenever possible as it's faster and more readable. Just use continue instead of return.
|
@bfred-it On the final visualisation of the links I recommend the following:
Example of Git using such notation: https://stackoverflow.com/a/338470/679227 I think this is good because Git is using On the regex matching: You're trying to do positive lookbehind which could be achieved with a regex like the following: However, positive lookbehind is not supported in the JavaScript regex engine. That's why you'd need to use match groups to extract the text you need. Relevant SO answer: https://stackoverflow.com/a/3569116/679227 E.g. you could use |
|
@hkdobrev how about external repos? Like this? user/not-this-repo/ Thanks for the info about regex. I was hoping for a way to avoid the // Shorten and highlight commit hashes
.replace(/([^/]+\/[^/]+)\/blob\/([\da-f]{7,})/i, (m, repo, hash) => {
return `${repo}/<code>${hash.substr(0, 7)}</code>`;
}) |
|
If you use the forward slash it's not so easy to determine where the branch name end and where the filename starts. Here, you have used inline code to distinguish it, but on the command line this is not possible and that's why colon is used. I'd prefer to wrap both the branch and the path to a single inline code element. |
|
The command line does not highlight the branch name like we do though though, so what's necessary there isn't necessary here. A monospaced filename can get long too. I don't think the filename start gets lost if only the branch is highlighted:
|
|
I'm not a fan of the slash either. What about using |
|
That's not bad. Perhaps the blame link can be formatted like GitHub's comment links, live example: Which for blame would be .editorconfig@ Edit: ⬇️ rebase only |
e5ec947 to
a8eb55a
Compare
|
Some thoughts: Putting
To differentiate between directories and repos, we could always add a leading slash before the path:
Don't forget
GitHub usually displays branch names with a blue background, via the What about dropping the branch name if it's
|
|
Just now I'm doing a roundup of any links I find (top comment) so that they can be easily discussed and tested.
That'd be nice, but there's no way to tell a branch apart from a tagname or commit:
Should they all (master, v0.12, cc8fc46) be blue?
That was the initial idea, but if felt like additional context and there's always who uses branches other than The links to |
|
@sindresorhus @hkdobrev @jgierer12 please review the top post and let me know if any URLs should be added. |
|
Missing repo pages: issues, pulls, milestones, labels, pulse, graphs |
No, I'd prefer the normal, gray tag. I don't really mind if branches aren't blue, it was just something I noticed.
Right, it will just get confusing if the default branch isn't
👍 |
There are actually a lot more of these but they're all the same, as far as we're concerned, no changes will likely be made other than to |
|
How does this look? Try it on the first post in this PR. Notes:
Next:
|
|
Looking great so far! Like I said, I would add a leading slash to directories/files to distinguish them from repos. e.g. I would also print all of the repo pages with the parens syntax, e.g. user/repo (wiki), user/repo (projects) For How about |
That would make it look like it's a link to a single commit, rather than the list of commits coming up to it. Perhaps nodejs/node/.gitignore@ For everything else: excellent, will do! |
My bad, I actually thought they were single commits. In that case, |
4b5e949 to
9ad17a3
Compare
|
Oooooook I think we're there. Code-wise not 100% happy but I'm already at my third refactoring at this point. 😅 @jgierer12 I didn't shorten the milestone because the |
|
@sindresorhus I ended up going for |
| return this._currentURI; | ||
| } | ||
| }; | ||
|
|
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.
@sindresorhus please verify. This is Node 7+
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.
👍
|
Can you add it to the feature highlights in the readme with a link to a screenshot? |
|
Perfect |
|
🎉 |
|
🍾✨🎉 |
|
🙌 Great work @bfred-it! |
|
I'm loving this. Perhaps we should follow @hkdobrev's advice and use : between the repo and filename: user/repo:filename@ |
|
is there a way we can avoid some of these short bits on readme.md? for instance: |
|
That should not happen (#789). URL shortening is supposed to only happen to real links. If it's a regression, open a new issue. |


Closes #472. This post serves as test. Most likes are 404s or rick rolls, don't click.
Repo root
https://github.com/sindresorhus/refined-github/
https://github.com/sindresorhus/refined-github/tree/v0.12
https://github.com/sindresorhus/refined-github/tree/d71718db6aa4feb8dc10edbad1134472468e971a
https://github.com/nodejs/node/
https://github.com/nodejs/node/tree/v0.12
https://github.com/nodejs/node/tree/d71718db6aa4feb8dc10edbad1134472468e971a
Directory
https://github.com/sindresorhus/refined-github/tree/master/doc
https://github.com/sindresorhus/refined-github/tree/v0.12/doc
https://github.com/sindresorhus/refined-github/tree/d71718db6aa4feb8dc10edbad1134472468e971a/doc
https://github.com/nodejs/node/tree/master/doc
https://github.com/nodejs/node/tree/v0.12/doc
https://github.com/nodejs/node/tree/d71718db6aa4feb8dc10edbad1134472468e971a/doc
File
https://github.com/sindresorhus/refined-github/blob/master/.gitignore
https://github.com/sindresorhus/refined-github/blob/v0.12/.gitignore
https://github.com/sindresorhus/refined-github/blob/cc8fc46/.gitignore
https://github.com/nodejs/node/blob/master/.gitignore
https://github.com/nodejs/node/blob/v0.12/.gitignore
https://github.com/nodejs/node/blob/cc8fc46/.gitignore
File blame
https://github.com/sindresorhus/refined-github/blame/master/.gitignore
https://github.com/sindresorhus/refined-github/blame/v0.12/.gitignore
https://github.com/sindresorhus/refined-github/blame/cc8fc46/.gitignore
https://github.com/nodejs/node/blame/master/.gitignore
https://github.com/nodejs/node/blame/v0.12/.gitignore
https://github.com/nodejs/node/blame/cc8fc46/.gitignore
File commits/history
https://github.com/sindresorhus/refined-github/commits/master/.gitignore
https://github.com/sindresorhus/refined-github/commits/v0.12/.gitignore
https://github.com/sindresorhus/refined-github/commits/cc8fc46/.gitignore
https://github.com/nodejs/node/commits/master/.gitignore
https://github.com/nodejs/node/commits/v0.12/.gitignore
https://github.com/nodejs/node/commits/cc8fc46/.gitignore
Commit diff and patch
https://github.com/sindresorhus/refined-github/commit/cc8fc46.diff
https://github.com/sindresorhus/refined-github/commit/cc8fc46.patch
https://github.com/nodejs/node/commit/cc8fc46.diff
https://github.com/nodejs/node/commit/cc8fc46.patch
Tag/release
https://github.com/sindresorhus/refined-github/releases/tag/v0.12.0
https://github.com/nodejs/node/releases/tag/v0.12.0
Milestones
https://github.com/sindresorhus/refined-github/milestone/25
https://github.com/nodejs/node/milestone/25
Labels
https://github.com/sindresorhus/refined-github/labels/npm
https://github.com/nodejs/node/labels/npm
Downloads
https://github.com/sindresorhus/refined-github/archive/6.4.1.zip
https://github.com/sindresorhus/refined-github/releases/download/6.4.1/now-macos
https://github.com/zeit/now-cli/archive/6.4.1.zip
https://github.com/zeit/now-cli/releases/download/6.4.1/now-macos
Repo pages
https://github.com/sindresorhus/refined-github/wiki
https://github.com/sindresorhus/refined-github/pulse
https://github.com/sindresorhus/refined-github/labels
https://github.com/sindresorhus/refined-github/network
https://github.com/sindresorhus/refined-github/projects
https://github.com/sindresorhus/refined-github/releases
https://github.com/sindresorhus/refined-github/milestones
https://github.com/sindresorhus/refined-github/contributors
https://github.com/nodejs/node/wiki
https://github.com/nodejs/node/pulse
https://github.com/nodejs/node/labels
https://github.com/nodejs/node/network
https://github.com/nodejs/node/projects
https://github.com/nodejs/node/releases
https://github.com/nodejs/node/milestones
https://github.com/nodejs/node/contributors
https://github.com/nodejs/node/graphs/commit-activity
etc...
Raw links
https://rawgit.com/sindresorhus/refined-github/master/.gitignore
https://cdn.rawgit.com/sindresorhus/refined-github/v0.12/.gitignore
https://cdn.rawgit.com/sindresorhus/refined-github/d71718db/.gitignore
https://raw.githubusercontent.com/sindresorhus/refined-github/master/.gitignore
https://raw.githubusercontent.com/sindresorhus/refined-github/v0.12/.gitignore
https://raw.githubusercontent.com/sindresorhus/refined-github/d71718db/.gitignore
https://rawgit.com/nodejs/node/master/.gitignore
https://cdn.rawgit.com/nodejs/node/v0.12/.gitignore
https://cdn.rawgit.com/nodejs/node/d71718db/.gitignore
https://raw.githubusercontent.com/nodejs/node/master/.gitignore
https://raw.githubusercontent.com/nodejs/node/v0.12/.gitignore
https://raw.githubusercontent.com/nodejs/node/d71718db/.gitignore
Users and orgs
https://github.com/sindresorhus
https://github.com/nodejs
Reserved URLs
https://github.com/pulls
https://github.com/issues
https://github.com/trending
https://github.com/features
https://github.com/marketplace
https://github.com/trending/developers
https://github.com/settings/profile
etc...
Non-local URLs
https://www.npmjs.com
https://www.npmjs.com/package/node
https://example.com/nodejs/node/blob/cc8fc46/.gitignore looks like file, but isn't safe to shorten
Natively shortened
#1 PR
#3 issue
9d7895c commit
9d7895c?w=1 commit with query string
v0.12.0...v0.12.1 compare across branches
v7.x...v8:master compare across forks
nodejs/node#1 PR
nodejs/node#3 issue
nodejs/node@9d7895c commit
nodejs/node@9d7895c?w=1 commit with query string
nodejs/node@v0.12.0...v0.12.1 compare across branches
nodejs/node@v7.x...v8:master compare across forks