Socket
Socket
Sign inDemoInstall

hexo-util

Package Overview
Dependencies
Maintainers
8
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hexo-util - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

lib/full_url_for.js

2

highlight_alias.json

@@ -1,1 +0,1 @@

{"languages":["1c","abnf","accesslog","actionscript","ada","angelscript","apache","applescript","arcade","cpp","arduino","armasm","xml","asciidoc","aspectj","autohotkey","autoit","avrasm","awk","axapta","bash","basic","bnf","brainfuck","cal","capnproto","ceylon","clean","clojure","clojure-repl","cmake","coffeescript","coq","cos","crmsh","crystal","cs","csp","css","d","markdown","dart","delphi","diff","django","dns","dockerfile","dos","dsconfig","dts","dust","ebnf","elixir","elm","ruby","erb","erlang-repl","erlang","excel","fix","flix","fortran","fsharp","gams","gauss","gcode","gherkin","glsl","gml","go","golo","gradle","groovy","haml","handlebars","haskell","haxe","hsp","htmlbars","http","hy","inform7","ini","irpf90","isbl","java","javascript","jboss-cli","json","julia","julia-repl","kotlin","lasso","ldif","leaf","less","lisp","livecodeserver","livescript","llvm","lsl","lua","makefile","mathematica","matlab","maxima","mel","mercury","mipsasm","mizar","perl","mojolicious","monkey","moonscript","n1ql","nginx","nimrod","nix","nsis","objectivec","ocaml","openscad","oxygene","parser3","pf","pgsql","php","plaintext","pony","powershell","processing","profile","prolog","properties","protobuf","puppet","purebasic","python","q","qml","r","reasonml","rib","roboconf","routeros","rsl","ruleslanguage","rust","sas","scala","scheme","scilab","scss","shell","smali","smalltalk","sml","sqf","sql","stan","stata","step21","stylus","subunit","swift","taggerscript","yaml","tap","tcl","tex","thrift","tp","twig","typescript","vala","vbnet","vbscript","vbscript-html","verilog","vhdl","vim","x86asm","xl","xquery","zephir"],"aliases":{"1c":"1c","abnf":"abnf","accesslog":"accesslog","actionscript":"actionscript","as":"actionscript","ada":"ada","angelscript":"angelscript","asc":"angelscript","apache":"apache","apacheconf":"apache","applescript":"applescript","osascript":"applescript","arcade":"arcade","cpp":"cpp","c":"cpp","cc":"cpp","h":"cpp","c++":"cpp","h++":"cpp","hpp":"cpp","hh":"cpp","hxx":"cpp","cxx":"cpp","arduino":"arduino","armasm":"armasm","arm":"armasm","xml":"xml","html":"xml","xhtml":"xml","rss":"xml","atom":"xml","xjb":"xml","xsd":"xml","xsl":"xml","plist":"xml","asciidoc":"asciidoc","adoc":"asciidoc","aspectj":"aspectj","autohotkey":"autohotkey","ahk":"autohotkey","autoit":"autoit","avrasm":"avrasm","awk":"awk","axapta":"axapta","bash":"bash","sh":"bash","zsh":"bash","basic":"basic","bnf":"bnf","brainfuck":"brainfuck","bf":"brainfuck","cal":"cal","capnproto":"capnproto","capnp":"capnproto","ceylon":"ceylon","clean":"clean","icl":"clean","dcl":"clean","clojure":"clojure","clj":"clojure","clojure-repl":"clojure-repl","cmake":"cmake","cmake.in":"cmake","coffeescript":"coffeescript","coffee":"coffeescript","cson":"coffeescript","iced":"coffeescript","coq":"coq","cos":"cos","cls":"cos","crmsh":"crmsh","crm":"crmsh","pcmk":"crmsh","crystal":"crystal","cr":"crystal","cs":"cs","csharp":"cs","c#":"cs","csp":"csp","css":"css","d":"d","markdown":"markdown","md":"markdown","mkdown":"markdown","mkd":"markdown","dart":"dart","delphi":"delphi","dpr":"delphi","dfm":"delphi","pas":"delphi","pascal":"delphi","freepascal":"delphi","lazarus":"delphi","lpr":"delphi","lfm":"delphi","diff":"diff","patch":"diff","django":"django","jinja":"django","dns":"dns","bind":"dns","zone":"dns","dockerfile":"dockerfile","docker":"dockerfile","dos":"dos","bat":"dos","cmd":"dos","dsconfig":"dsconfig","dts":"dts","dust":"dust","dst":"dust","ebnf":"ebnf","elixir":"elixir","elm":"elm","ruby":"ruby","rb":"ruby","gemspec":"ruby","podspec":"ruby","thor":"ruby","irb":"ruby","erb":"erb","erlang-repl":"erlang-repl","erlang":"erlang","erl":"erlang","excel":"excel","xlsx":"excel","xls":"excel","fix":"fix","flix":"flix","fortran":"fortran","f90":"fortran","f95":"fortran","fsharp":"fsharp","fs":"fsharp","gams":"gams","gms":"gams","gauss":"gauss","gss":"gauss","gcode":"gcode","nc":"gcode","gherkin":"gherkin","feature":"gherkin","glsl":"glsl","gml":"gml","GML":"gml","go":"go","golang":"go","golo":"golo","gradle":"gradle","groovy":"groovy","haml":"haml","handlebars":"handlebars","hbs":"handlebars","html.hbs":"handlebars","html.handlebars":"handlebars","haskell":"haskell","hs":"haskell","haxe":"haxe","hx":"haxe","hsp":"hsp","htmlbars":"htmlbars","http":"http","https":"http","hy":"hy","hylang":"hy","inform7":"inform7","i7":"inform7","ini":"ini","toml":"ini","irpf90":"irpf90","isbl":"isbl","java":"java","jsp":"java","javascript":"javascript","js":"javascript","jsx":"javascript","jboss-cli":"jboss-cli","wildfly-cli":"jboss-cli","json":"json","julia":"julia","julia-repl":"julia-repl","kotlin":"kotlin","kt":"kotlin","lasso":"lasso","ls":"livescript","lassoscript":"lasso","ldif":"ldif","leaf":"leaf","less":"less","lisp":"lisp","livecodeserver":"livecodeserver","livescript":"livescript","llvm":"llvm","lsl":"lsl","lua":"lua","makefile":"makefile","mk":"makefile","mak":"makefile","mathematica":"mathematica","mma":"mathematica","wl":"mathematica","matlab":"matlab","maxima":"maxima","mel":"mel","mercury":"mercury","m":"mercury","moo":"mercury","mipsasm":"mipsasm","mips":"mipsasm","mizar":"mizar","perl":"perl","pl":"perl","pm":"perl","mojolicious":"mojolicious","monkey":"monkey","moonscript":"moonscript","moon":"moonscript","n1ql":"n1ql","nginx":"nginx","nginxconf":"nginx","nimrod":"nimrod","nim":"nimrod","nix":"nix","nixos":"nix","nsis":"nsis","objectivec":"objectivec","mm":"objectivec","objc":"objectivec","obj-c":"objectivec","ocaml":"ocaml","ml":"sml","openscad":"openscad","scad":"openscad","oxygene":"oxygene","parser3":"parser3","pf":"pf","pf.conf":"pf","pgsql":"pgsql","postgres":"pgsql","postgresql":"pgsql","php":"php","php3":"php","php4":"php","php5":"php","php6":"php","php7":"php","plaintext":"plaintext","pony":"pony","powershell":"powershell","ps":"powershell","processing":"processing","profile":"profile","prolog":"prolog","properties":"properties","protobuf":"protobuf","puppet":"puppet","pp":"puppet","purebasic":"purebasic","pb":"purebasic","pbi":"purebasic","python":"python","py":"python","gyp":"python","ipython":"python","q":"q","k":"q","kdb":"q","qml":"qml","qt":"qml","r":"r","reasonml":"reasonml","re":"reasonml","rib":"rib","roboconf":"roboconf","graph":"roboconf","instances":"roboconf","routeros":"routeros","mikrotik":"routeros","rsl":"rsl","ruleslanguage":"ruleslanguage","rust":"rust","rs":"rust","sas":"sas","SAS":"sas","scala":"scala","scheme":"scheme","scilab":"scilab","sci":"scilab","scss":"scss","shell":"shell","console":"shell","smali":"smali","smalltalk":"smalltalk","st":"smalltalk","sml":"sml","sqf":"sqf","sql":"sql","stan":"stan","stata":"stata","do":"stata","ado":"stata","step21":"step21","p21":"step21","step":"step21","stp":"step21","stylus":"stylus","styl":"stylus","subunit":"subunit","swift":"swift","taggerscript":"taggerscript","yaml":"yaml","yml":"yaml","YAML":"yaml","tap":"tap","tcl":"tcl","tk":"tcl","tex":"tex","thrift":"thrift","tp":"tp","twig":"twig","craftcms":"twig","typescript":"typescript","ts":"typescript","vala":"vala","vbnet":"vbnet","vb":"vbnet","vbscript":"vbscript","vbs":"vbscript","vbscript-html":"vbscript-html","verilog":"verilog","v":"verilog","sv":"verilog","svh":"verilog","vhdl":"vhdl","vim":"vim","x86asm":"x86asm","xl":"xl","tao":"xl","xquery":"xquery","xpath":"xquery","xq":"xquery","zephir":"zephir","zep":"zephir"}}
{"languages":["1c","abnf","accesslog","actionscript","ada","angelscript","apache","applescript","arcade","cpp","arduino","armasm","xml","asciidoc","aspectj","autohotkey","autoit","avrasm","awk","axapta","bash","basic","bnf","brainfuck","cal","capnproto","ceylon","clean","clojure","clojure-repl","cmake","coffeescript","coq","cos","crmsh","crystal","cs","csp","css","d","markdown","dart","delphi","diff","django","dns","dockerfile","dos","dsconfig","dts","dust","ebnf","elixir","elm","ruby","erb","erlang-repl","erlang","excel","fix","flix","fortran","fsharp","gams","gauss","gcode","gherkin","glsl","gml","go","golo","gradle","groovy","haml","handlebars","haskell","haxe","hsp","htmlbars","http","hy","inform7","ini","irpf90","isbl","java","javascript","jboss-cli","json","julia","julia-repl","kotlin","lasso","ldif","leaf","less","lisp","livecodeserver","livescript","llvm","lsl","lua","makefile","mathematica","matlab","maxima","mel","mercury","mipsasm","mizar","perl","mojolicious","monkey","moonscript","n1ql","nginx","nimrod","nix","nsis","objectivec","ocaml","openscad","oxygene","parser3","pf","pgsql","php","plaintext","pony","powershell","processing","profile","prolog","properties","protobuf","puppet","purebasic","python","q","qml","r","reasonml","rib","roboconf","routeros","rsl","ruleslanguage","rust","sas","scala","scheme","scilab","scss","shell","smali","smalltalk","sml","sqf","sql","stan","stata","step21","stylus","subunit","swift","taggerscript","yaml","tap","tcl","tex","thrift","tp","twig","typescript","vala","vbnet","vbscript","vbscript-html","verilog","vhdl","vim","x86asm","xl","xquery","zephir"],"aliases":{"1c":"1c","abnf":"abnf","accesslog":"accesslog","actionscript":"actionscript","as":"actionscript","ada":"ada","angelscript":"angelscript","asc":"angelscript","apache":"apache","apacheconf":"apache","applescript":"applescript","osascript":"applescript","arcade":"arcade","cpp":"cpp","c":"cpp","cc":"cpp","h":"cpp","c++":"cpp","h++":"cpp","hpp":"cpp","hh":"cpp","hxx":"cpp","cxx":"cpp","arduino":"arduino","armasm":"armasm","arm":"armasm","xml":"xml","html":"xml","xhtml":"xml","rss":"xml","atom":"xml","xjb":"xml","xsd":"xml","xsl":"xml","plist":"xml","asciidoc":"asciidoc","adoc":"asciidoc","aspectj":"aspectj","autohotkey":"autohotkey","ahk":"autohotkey","autoit":"autoit","avrasm":"avrasm","awk":"awk","axapta":"axapta","bash":"bash","sh":"bash","zsh":"bash","basic":"basic","bnf":"bnf","brainfuck":"brainfuck","bf":"brainfuck","cal":"cal","capnproto":"capnproto","capnp":"capnproto","ceylon":"ceylon","clean":"clean","icl":"clean","dcl":"clean","clojure":"clojure","clj":"clojure","clojure-repl":"clojure-repl","cmake":"cmake","cmake.in":"cmake","coffeescript":"coffeescript","coffee":"coffeescript","cson":"coffeescript","iced":"coffeescript","coq":"coq","cos":"cos","cls":"cos","crmsh":"crmsh","crm":"crmsh","pcmk":"crmsh","crystal":"crystal","cr":"crystal","cs":"cs","csharp":"cs","c#":"cs","csp":"csp","css":"css","d":"d","markdown":"markdown","md":"markdown","mkdown":"markdown","mkd":"markdown","dart":"dart","delphi":"delphi","dpr":"delphi","dfm":"delphi","pas":"delphi","pascal":"delphi","freepascal":"delphi","lazarus":"delphi","lpr":"delphi","lfm":"delphi","diff":"diff","patch":"diff","django":"django","jinja":"django","dns":"dns","bind":"dns","zone":"dns","dockerfile":"dockerfile","docker":"dockerfile","dos":"dos","bat":"dos","cmd":"dos","dsconfig":"dsconfig","dts":"dts","dust":"dust","dst":"dust","ebnf":"ebnf","elixir":"elixir","elm":"elm","ruby":"ruby","rb":"ruby","gemspec":"ruby","podspec":"ruby","thor":"ruby","irb":"ruby","erb":"erb","erlang-repl":"erlang-repl","erlang":"erlang","erl":"erlang","excel":"excel","xlsx":"excel","xls":"excel","fix":"fix","flix":"flix","fortran":"fortran","f90":"fortran","f95":"fortran","fsharp":"fsharp","fs":"fsharp","gams":"gams","gms":"gams","gauss":"gauss","gss":"gauss","gcode":"gcode","nc":"gcode","gherkin":"gherkin","feature":"gherkin","glsl":"glsl","gml":"gml","GML":"gml","go":"go","golang":"go","golo":"golo","gradle":"gradle","groovy":"groovy","haml":"haml","handlebars":"handlebars","hbs":"handlebars","html.hbs":"handlebars","html.handlebars":"handlebars","haskell":"haskell","hs":"haskell","haxe":"haxe","hx":"haxe","hsp":"hsp","htmlbars":"htmlbars","http":"http","https":"http","hy":"hy","hylang":"hy","inform7":"inform7","i7":"inform7","ini":"ini","toml":"ini","irpf90":"irpf90","isbl":"isbl","java":"java","jsp":"java","javascript":"javascript","js":"javascript","jsx":"javascript","jboss-cli":"jboss-cli","wildfly-cli":"jboss-cli","json":"json","julia":"julia","julia-repl":"julia-repl","kotlin":"kotlin","kt":"kotlin","lasso":"lasso","ls":"livescript","lassoscript":"lasso","ldif":"ldif","leaf":"leaf","less":"less","lisp":"lisp","livecodeserver":"livecodeserver","livescript":"livescript","llvm":"llvm","lsl":"lsl","lua":"lua","makefile":"makefile","mk":"makefile","mak":"makefile","mathematica":"mathematica","mma":"mathematica","matlab":"matlab","maxima":"maxima","mel":"mel","mercury":"mercury","m":"mercury","moo":"mercury","mipsasm":"mipsasm","mips":"mipsasm","mizar":"mizar","perl":"perl","pl":"perl","pm":"perl","mojolicious":"mojolicious","monkey":"monkey","moonscript":"moonscript","moon":"moonscript","n1ql":"n1ql","nginx":"nginx","nginxconf":"nginx","nimrod":"nimrod","nim":"nimrod","nix":"nix","nixos":"nix","nsis":"nsis","objectivec":"objectivec","mm":"objectivec","objc":"objectivec","obj-c":"objectivec","ocaml":"ocaml","ml":"sml","openscad":"openscad","scad":"openscad","oxygene":"oxygene","parser3":"parser3","pf":"pf","pf.conf":"pf","pgsql":"pgsql","postgres":"pgsql","postgresql":"pgsql","php":"php","php3":"php","php4":"php","php5":"php","php6":"php","php7":"php","plaintext":"plaintext","pony":"pony","powershell":"powershell","ps":"powershell","processing":"processing","profile":"profile","prolog":"prolog","properties":"properties","protobuf":"protobuf","puppet":"puppet","pp":"puppet","purebasic":"purebasic","pb":"purebasic","pbi":"purebasic","python":"python","py":"python","gyp":"python","ipython":"python","q":"q","k":"q","kdb":"q","qml":"qml","qt":"qml","r":"r","reasonml":"reasonml","re":"reasonml","rib":"rib","roboconf":"roboconf","graph":"roboconf","instances":"roboconf","routeros":"routeros","mikrotik":"routeros","rsl":"rsl","ruleslanguage":"ruleslanguage","rust":"rust","rs":"rust","sas":"sas","SAS":"sas","scala":"scala","scheme":"scheme","scilab":"scilab","sci":"scilab","scss":"scss","shell":"shell","console":"shell","smali":"smali","smalltalk":"smalltalk","st":"smalltalk","sml":"sml","sqf":"sqf","sql":"sql","stan":"stan","stata":"stata","do":"stata","ado":"stata","step21":"step21","p21":"step21","step":"step21","stp":"step21","stylus":"stylus","styl":"stylus","subunit":"subunit","swift":"swift","taggerscript":"taggerscript","yaml":"yaml","yml":"yaml","YAML":"yaml","tap":"tap","tcl":"tcl","tk":"tcl","tex":"tex","thrift":"thrift","tp":"tp","twig":"twig","craftcms":"twig","typescript":"typescript","ts":"typescript","vala":"vala","vbnet":"vbnet","vb":"vbnet","vbscript":"vbscript","vbs":"vbscript","vbscript-html":"vbscript-html","verilog":"verilog","v":"verilog","sv":"verilog","svh":"verilog","vhdl":"vhdl","vim":"vim","x86asm":"x86asm","xl":"xl","tao":"xl","xquery":"xquery","xpath":"xquery","xq":"xquery","zephir":"zephir","zep":"zephir"}}

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

@@ -7,7 +7,18 @@ 'use strict';

if (parse(str).protocol) {
return format({
const obj = Object.assign({}, {
auth: parse(str).auth,
protocol: parse(str).protocol,
hostname: parse(str).hostname,
host: parse(str).host,
pathname: encodeURI(decodeURI(parse(str).pathname))
});
if (parse(str).hash) {
Object.assign(obj, { hash: encodeURI(decodeURI(parse(str).hash)) });
}
if (parse(str).search) {
Object.assign(obj, { search: encodeURI(decodeURI(parse(str).search)) });
}
return format(obj);
}

@@ -14,0 +25,0 @@

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

@@ -13,2 +13,4 @@ 'use strict';

exports.escapeRegExp = require('./escape_regexp');
exports.full_url_for = require('./full_url_for');
exports.gravatar = require('./gravatar');
exports.hash = hash.hash;

@@ -20,2 +22,3 @@ exports.HashStream = hash.HashStream;

exports.Permalink = require('./permalink');
exports.relative_url = require('./relative_url');
exports.slugize = require('./slugize');

@@ -25,2 +28,3 @@ exports.spawn = require('./spawn');

exports.truncate = require('./truncate');
exports.url_for = require('./url_for');
exports.wordWrap = require('./word_wrap');

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

'use strict';
module.exports = require('striptags');

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

{
"name": "hexo-util",
"version": "1.1.0",
"version": "1.2.0",
"description": "Utilities for Hexo.",

@@ -5,0 +5,0 @@ "main": "lib/index",

@@ -52,6 +52,29 @@ # hexo-util

### escapeRegex(str)
### createSha1Hash()
return SHA1 hash object.
This is the same as calling `createHash('utf8')` in the node.js native module crypto.
``` js
const sha1 = createSha1Hash();
fs.createReadStream('/path/to/file')
.pipe(sha1)
.on('finish', () => {
console.log(sha1.read());
});
```
Escapes special characters in a regular expression.
### encodeURL(str)
Encode URL or path into a [safe format](https://en.wikipedia.org/wiki/Percent-encoding). Domain is encoded into [punycode](https://en.wikipedia.org/wiki/Punycode) when necessary.
``` js
encodeURL('http://foo.com/bár')
// http://foo.com/b%C3%A1r
encodeURL('http://bár.com/baz')
// http://xn--br-mia.com/baz
encodeURL('/foo/bár/')
// /foo/b%C3%A1r/
```
### escapeDiacritic(str)

@@ -65,2 +88,44 @@

### escapeRegex(str)
Escapes special characters in a regular expression.
### full_url_for(path)
Returns a url with the config.url prefixed. Output is [encoded](#encodeurlstr) automatically. Requires [`bind(hexo)`](#bindhexo).
``` yml
_config.yml
url: https://example.com/blog # example
```
``` js
full_url_for('/a/path')
// https://example.com/blog/a/path
```
### gravatar(str, [options])
Returns the gravatar image url from an email.
If you didn't specify the [options] parameter, the default options will apply. Otherwise, you can set it to a number which will then be passed on as the size parameter to Gravatar. Finally, if you set it to an object, it will be converted into a query string of parameters for Gravatar.
Option | Description | Default
--- | --- | ---
`s` | Output image size | 80
`d` | Default image |
`f` | Force default |
`r` | Rating |
More info: [Gravatar](https://en.gravatar.com/site/implement/images/)
``` js
gravatar('a@abc.com')
// https://www.gravatar.com/avatar/b9b00e66c6b8a70f88c73cb6bdb06787
gravatar('a@abc.com', 40)
// https://www.gravatar.com/avatar/b9b00e66c6b8a70f88c73cb6bdb06787?s=40
gravatar('a@abc.com' {s: 40, d: 'https://via.placeholder.com/150'})
// https://www.gravatar.com/avatar/b9b00e66c6b8a70f88c73cb6bdb06787?s=40&d=https%3A%2F%2Fvia.placeholder.com%2F150
```
### hash(str)

@@ -76,3 +141,3 @@

### HashStream()
**\[deprecated\]** use `createSha1Hash()`.
**\[deprecated\]** use [`createSha1Hash()`](#createsha1hash).

@@ -91,29 +156,2 @@ Generates SHA1 hash with a transform stream.

### createSha1Hash()
return SHA1 hash object.
This is the same as calling `createHash('utf8')` in the node.js native module crypto.
``` js
const sha1 = createSha1Hash();
fs.createReadStream('/path/to/file')
.pipe(sha1)
.on('finish', () => {
console.log(sha1.read());
});
```
### encodeURL(str)
Encode URL or path into a [safe format](https://en.wikipedia.org/wiki/Percent-encoding). Domain is encoded into [punycode](https://en.wikipedia.org/wiki/Punycode) when necessary.
``` js
encodeURL('http://foo.com/bár')
// http://foo.com/b%C3%A1r
encodeURL('http://bár.com/baz')
// http://xn--br-mia.com/baz
encodeURL('/foo/bár/')
// /foo/b%C3%A1r/
```
### highlight(str, [options])

@@ -191,2 +229,11 @@

### relative_url(from, to)
Returns the relative URL from `from` to `to`. Output is [encoded](#encodeurlstr) automatically. Requires [`bind(hexo)`](#bindhexo).
``` js
relative_url('foo/bar/', 'css/style.css')
// ../../css/style.css
```
### slugize(str, [options])

@@ -280,2 +327,98 @@

### url_for(path, [option])
Returns a url with the root path prefixed. Output is [encoded](#encodeurlstr) automatically. Requires [`bind(hexo)`](#bindhexo).
Option | Description | Default
--- | --- | ---
`relative` | Output relative link | Value of `config.relative_link`
``` yml
_config.yml
root: /blog/ # example
```
``` js
url_for('/a/path')
// /blog/a/path
```
Relative link, follows `relative_link` option by default
e.g. post/page path is '/foo/bar/index.html'
``` yml
_config.yml
relative_link: true
```
``` js
url_for('/css/style.css')
// ../../css/style.css
/* Override option
* you could also enable it to output a relative link,
* even when `relative_link` is disabled and vice versa.
*/
url_for('/css/style.css', {relative: false})
// /css/style.css
```
## bind(hexo)
Following utilities require `bind(hexo)` / `bind(this)` to parse the user config when initializing:
- [`full_url_for()`](#full_url_forpath)
- [`url_for()`](#url_forpath)
- [`relative_url()`](#relative_urlfrom-to)
Below examples demonstrate four approaches of creating a [helper](https://hexo.io/api/helper) (each example is separated by `/******/`),
``` js
// Single function
const url_for = require('hexo-util').url_for.bind(hexo);
hexo.extend.helper.register('test_url', (str) => {
return url_for(str);
})
/******/
// Multiple functions
const url_for = require('hexo-util').url_for.bind(hexo)
function testurlHelper(str) {
return url_for(str);
}
hexo.extend.helper.register('test_url', testurlHelper);
/******/
// Functions separated into different files.
// test_url.js
module.exports = function(str) {
const url_for = require('hexo-util').url_for.bind(this);
return url_for(str);
}
// index.js
hexo.extend.helper.register('test_url', require('./test_url'));
/******/
// Separating functions into individual files
// Each file has multiple functions
// test_url.js
function testurlHelper(str) {
const url_for = require('hexo-util').url_for.bind(this);
return url_for(str);
}
module.exports = {
testurlHelper: testurlHelper
}
// index.js
hexo.extend.helper.register('test_url', require('./test_url').testurlHelper);
```
## License

@@ -282,0 +425,0 @@

@@ -0,0 +0,0 @@ 'use strict';

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc