Skip to content

Conversation

@fregante
Copy link
Member

@fregante fregante commented Jun 6, 2017

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

@fregante fregante force-pushed the shorten-url-labels branch 2 times, most recently from 4b0c850 to 999b8fa Compare June 6, 2017 10:23
@hkdobrev
Copy link
Contributor

hkdobrev commented Jun 6, 2017

I'd prefer to use colon as a separator between branch and file path as Git does.

@fregante
Copy link
Member Author

fregante commented Jun 6, 2017

@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 => {
Copy link
Member

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.

@hkdobrev
Copy link
Contributor

hkdobrev commented Jun 6, 2017

@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
(will link to official manual when it stops giving 500 error pages)

I think this is good because Git is using : to separate refs and path specs in various cases, but other software like scp is using it as well. Also, the forward slash character / is used for both directory separator and often used in the name of branches in different Git workflows.

On the regex matching:

You're trying to do positive lookbehind which could be achieved with a regex like the following:

/(?<=2)red/

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 /2([a-z_-\/\+)/ and then use the first matched group.

@fregante
Copy link
Member Author

fregante commented Jun 7, 2017

@hkdobrev how about external repos? Like this? user/not-this-repo/master:index.js

Thanks for the info about regex. I was hoping for a way to avoid the ${repo}/ part here:

  // Shorten and highlight commit hashes
  .replace(/([^/]+\/[^/]+)\/blob\/([\da-f]{7,})/i, (m, repo, hash) => {
  	return `${repo}/<code>${hash.substr(0, 7)}</code>`;
  })

@fregante
Copy link
Member Author

fregante commented Jun 7, 2017

I worked around the regex complexity by using URL parsing and explicit variables. This should be safer and it's also more mindful of external URLs.

Also added raw handling and switched to : after the branch.

Current situation:

screen shot 2017-06-07 at 14 06 24

But I'm not a fan of how : looks, I prefer the first one:

  1. user/repo/branch/.gitignore
  2. user/repo/branch:.gitignore

@hkdobrev
Copy link
Contributor

hkdobrev commented Jun 7, 2017

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.

@fregante
Copy link
Member Author

fregante commented Jun 7, 2017

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:

  1. user/repo/branch/.gitignore <- similar to the URL: github.com/user/repo/blob/master/.gitignore
  2. user/repo/branch:.gitignore <- still not a fan of :.

@jgierer12
Copy link
Contributor

jgierer12 commented Jun 12, 2017

I'm not a fan of the slash either. What about using @ similar to npm (and GitHub sometimes, e.g. sindresorhus/linkify-urls@aca71b8):

@fregante
Copy link
Member Author

fregante commented Jun 12, 2017

That's not bad. Perhaps the blame link can be formatted like GitHub's comment links, live example:

#473 (comment)

Which for blame would be

.editorconfig@patch-diff-shortcuts (blame)

Edit: ⬇️ rebase only

@fregante fregante force-pushed the shorten-url-labels branch from e5ec947 to a8eb55a Compare June 13, 2017 09:22
@jgierer12
Copy link
Contributor

jgierer12 commented Jun 13, 2017

Some thoughts:


Putting blame in brackets definitely seems nicer. I also noticed that GitHub puts the repo before the @ as seen in this comment: #467 (comment)
So maybe we should do that too:

To differentiate between directories and repos, we could always add a leading slash before the path:


Don't forget tree links:


GitHub usually displays branch names with a blue background, via the branch-name class. Maybe you could do that too?


What about dropping the branch name if it's master?

@fregante
Copy link
Member Author

fregante commented Jun 13, 2017

Just now I'm doing a roundup of any links I find (top comment) so that they can be easily discussed and tested.

GitHub always displays branch names with a blue background, via the branch-name class. Maybe you could do that too?

That'd be nice, but there's no way to tell a branch apart from a tagname or commit:

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

Should they all (master, v0.12, cc8fc46) be blue?

What about dropping the branch name if it's master?

That was the initial idea, but if felt like additional context and there's always who uses branches other than master as the base branch.

The links to raw could use the regular parens syntax as well: rollup/rollup/.eslintrc (raw)

@fregante
Copy link
Member Author

@sindresorhus @hkdobrev @jgierer12 please review the top post and let me know if any URLs should be added.

@jgierer12
Copy link
Contributor

Missing repo pages: issues, pulls, milestones, labels, pulse, graphs

@jgierer12
Copy link
Contributor

Should they all (master, v0.12, cc8fc46) be blue?

No, I'd prefer the normal, gray tag. I don't really mind if branches aren't blue, it was just something I noticed.

That was the initial idea, but if felt like additional context and there's always who uses branches other than master as the base branch.

Right, it will just get confusing if the default branch isn't master

The links to raw could use the regular parens syntax as well: rollup/rollup/.eslintrc (raw)

👍

@fregante
Copy link
Member Author

pulse, graphs

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 user/repo/pulse

@fregante
Copy link
Member Author

fregante commented Jun 14, 2017

How does this look? Try it on the first post in this PR.

Notes:

  • All files are marked by @reference, this reduces ambiguity between
    • user/repo/file
    • user/repo/a-page-like-issues
  • I kept the repo on the left side of @ to be consistent across all links:
    • user/repo@branch
    • user/repo/file@branch

Next:

  • (How) do we shorten milestones further?
    Currently nodejs/node/milestone/25
  • (How) do we shorten releases further?
    Currently nodejs/node/releases/tag/v0.12.0
    This can't be shortened to nodejs/node@v0.12.0 because it'd be the same as a repo link to a tag.
  • (How) do we shorten labels further?
    Currently nodejs/node/labels/npm
    It'd be nice to match the color, but that'd require a fetch

@jgierer12
Copy link
Contributor

Looking great so far!

Like I said, I would add a leading slash to directories/files to distinguish them from repos. e.g.
/some/dir@master vs some/repo@master

I would also print all of the repo pages with the parens syntax, e.g. user/repo (wiki), user/repo (projects)

For commits links, I think it would be better to use the singular (commit): nodejs/node/.gitignore@master (commit)

How about

@fregante
Copy link
Member Author

fregante commented Jun 14, 2017

For commits links, I think it would be better to use the singular (commit): nodejs/node/.gitignore@master (commit)

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@master (history) would be an alternative.

For everything else: excellent, will do!

@jgierer12
Copy link
Contributor

That would make it look like it's a link to a single commit, rather than the list of commits coming up to it

My bad, I actually thought they were single commits. In that case, commits sounds fine

@fregante fregante force-pushed the shorten-url-labels branch from 4b5e949 to 9ad17a3 Compare June 15, 2017 02:58
@fregante fregante changed the title Shorten links (WIP) Shorten links Jun 16, 2017
@fregante
Copy link
Member Author

fregante commented Jun 16, 2017

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 25 (milestone) wasn't shorter than milestone/25; 25 isn't exactly indicative of its content; 25 looks too much like an issue number.

@fregante
Copy link
Member Author

fregante commented Jun 16, 2017

@sindresorhus I ended up going for cc8fc46.diff because my suggested cc8fc46 (diff)
may look like a link to the diff view rather than a diff file.

Generated with
copy($$('#issue-233840042 .comment-body a:not([class])').map(a =>
`['${a.href}', '${a.innerHTML}']`).join(',\n'))

On page #473
return this._currentURI;
}
};

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

👍

@sindresorhus
Copy link
Member

sindresorhus commented Jun 17, 2017

Can you add it to the feature highlights in the readme with a link to a screenshot?

@fregante
Copy link
Member Author

screenshot-shortened-urls

@sindresorhus
Copy link
Member

Perfect

@fregante fregante merged commit 7fa022f into master Jun 17, 2017
@fregante fregante deleted the shorten-url-labels branch June 17, 2017 10:39
@fregante
Copy link
Member Author

🎉

@sindresorhus
Copy link
Member

🍾✨🎉

@hkdobrev
Copy link
Contributor

🙌 Great work @bfred-it!

@fregante
Copy link
Member Author

fregante commented Jun 22, 2017

I'm loving this. Perhaps we should follow @hkdobrev's advice and use : between the repo and filename:

user/repo:filename@master <-- changes to :
/filename@master <-- stays the same

@sindresorhus
Copy link
Member

@bfred-it 👍

@FernandoMiguel
Copy link

is there a way we can avoid some of these short bits on readme.md?
it's breaking my documentation commands, preventing easy copy paste

for instance:
git submodule add https://github.com/xxx/Docker.git Dockerfile
loses the URL so you can execute that

@fregante
Copy link
Member Author

fregante commented Sep 5, 2018

That should not happen (#789). URL shortening is supposed to only happen to real links. If it's a regression, open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

5 participants