MCPcopy Index your code
hub / github.com/GitbookIO/gitbook / toAbsolute

Function toAbsolute

lib/utils/location.js:65–89  ·  view source on GitHub ↗

* Convert a relative path to absolute * * @param {String} href * @param {String} dir: directory parent of the file currently in rendering process * @param {String} outdir: directory parent from the html output * @return {String}

(_href, dir, outdir)

Source from the content-addressed store, hash-verified

63 * @return {String}
64 */
65function toAbsolute(_href, dir, outdir) {
66 if (isExternal(_href) || isDataURI(_href)) {
67 return _href;
68 }
69
70 outdir = outdir == undefined? dir : outdir;
71
72 _href = normalize(_href);
73 dir = normalize(dir);
74 outdir = normalize(outdir);
75
76 // Path "_href" inside the base folder
77 var hrefInRoot = normalize(path.join(dir, _href));
78 if (_href[0] == '/') {
79 hrefInRoot = normalize(_href.slice(1));
80 }
81
82 // Make it relative to output
83 _href = path.relative(outdir, hrefInRoot);
84
85 // Normalize windows paths
86 _href = normalize(_href);
87
88 return _href;
89}
90
91/**
92 * Convert an absolute path to a relative path for a specific folder (dir)

Callers

nothing calls this directly

Calls 3

isExternalFunction · 0.85
isDataURIFunction · 0.85
normalizeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…