Generate a jsDelivr URL for a file hosted in a public GitHub repository.
var jsdelivr = require( '@stdlib/_tools/utils/jsdelivr-url' );
Returns a jsDelivr URL for a file hosted in a public GitHub repository.
var opts = {
'slug': 'stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34',
'file': 'README.md'
};
var url = jsdelivr( opts );
// returns 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@5c53c78310e7c2cb8b3c166555d0fb81a3723f34/README.md'
The function accepts the following options
:
-
slug: public GitHub repository slug (required). The slug should include
owner
andrepo
information and should include eithercommit
,branch
, ortag
information. For example,stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34
stdlib-js/stdlib/develop
- ...etc.
-
file: filepath (required). For example,
lib/index.js
./README.md
- ...etc.
var jsdelivr = require( '@stdlib/_tools/utils/jsdelivr-url' );
var opts = {
'slug': 'stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34',
'file': 'README.md'
};
var url = jsdelivr( opts );
console.log( url );
// => 'https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@5c53c78310e7c2cb8b3c166555d0fb81a3723f34/README.md'
Usage: jsdelivr [options] <file>
Options:
-h, --help Print this message.
-V, --version Print the package version.
--slug slug GitHub repository slug (should include branch,
commit, or tag info).
-
If not provided a
slug
, the module attempts to resolve aslug
from a local.git
repository located in the current working directory of the calling process. Theslug
is a combination ofremote.origin.url
and the current Git hash. For example,$ git config --get remote.origin.url https://github.com/stdlib-js/stdlib.git $ git rev-parse HEAD 5c53c78310e7c2cb8b3c166555d0fb81a3723f34
becomes
var slug = 'stdlib-js/stdlib/5c53c78310e7c2cb8b3c166555d0fb81a3723f34';
$ jsdelivr README.md --slug 'stdlib-js/stdlib/develop'
https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@develop/README.md
To infer a GitHub repository slug
from a local .git
repository, omit the slug
option.
$ jsdelivr docs/assets/web/logo_header.png
https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@345a31cb0e0cc534ccedaa91775873f3da2038c2/docs/assets/web/logo_header.png