Get links for your GitHub files based on text, and forget the line numbers!
Why GitHub Link?
In Short
We usually create link-to-code to point our readers, users or developers to the exact code. But such links are created based on line-number and if you're updating the file regularly, those links will not point to correct line or you will need to keep updating your links. GitHub Link helps you to get the right link-to-code, based on text you give, so that it always points to contextually right definition. Jump to usage
In Long
We generally create permanent link to code snippet. As they are for specific commit, they work great when referred in issues/PRs.
But what if you want to give such links in your README or such files? Like you have already defined a coded file with proper comments and you want to give link to same in README, so that you can keep your README short and concise, and have links to all the extra definitions in it. Because you will always want up-to-date reference in README, permanent links will not work, as it shows file from specific commit.
You may use "Copy Link" feature, that links to the latest version of file, but then it may point to wrong definition, because you might have added/removed more lines of code in the file.
This is where GitHub Link comes into the picture. It gives you the link to code line, based on the text, so that it always points to contextually right definition.
Example
You have all of your types defined in hot-toast.model.ts
As the line for previous type is changed, the link on your README will point to export type ToastPosition..., instead of export type ToastType....
So, to resolve this problem, you can create github-link
Let's take this URL for example: https://github.com/ngneat/hot-toast/blob/master/projects/ngneat/hot-toast/src/lib/hot-toast.model.ts
Now the text to which we want to generate link is: export type ToastType
Considering points 8 & 9, below will be your link:
https://github-link.vercel.app/api?ghUrl=https://github.com/ngneat/hot-toast/blob/master/projects/ngneat/hot-toast/src/lib/hot-toast.model.ts&q=export type ToastType
Above link will find first occurance of export type ToastType in given URL, get it's line and will redirect there!
Usage
Open the file in browser and copy it's URL, let's call it: URL_TO_FILE
Find the text to which you want to generate the link, let's call it: SEARCH
Use both of above and create the link using GitHub Link API:
⚓ Get links to code in your GitHub files based on text, and forget the line numbers!
GitHub Link
Get links for your GitHub files based on text, and forget the line numbers!
Why GitHub Link?
In Short
We usually create link-to-code to point our readers, users or developers to the exact code. But such links are created based on line-number and if you're updating the file regularly, those links will not point to correct line or you will need to keep updating your links. GitHub Link helps you to get the right link-to-code, based on text you give, so that it always points to contextually right definition. Jump to usage
In Long
We generally create permanent link to code snippet. As they are for specific commit, they work great when referred in issues/PRs.
But what if you want to give such links in your README or such files? Like you have already defined a coded file with proper comments and you want to give link to…