MCPcopy Create free account
hub / github.com/Automattic/mongoose / mapURLs

Function mapURLs

scripts/website.js:411–455  ·  view source on GitHub ↗

* Map urls (https://mongoosejs.com/) to local paths * @param {String} block The String block to look for urls * @param {String} currentUrl The URL the block is for (non-versioned)

(block, currentUrl)

Source from the content-addressed store, hash-verified

409 * @param {String} currentUrl The URL the block is for (non-versioned)
410 */
411function mapURLs(block, currentUrl) {
412 let match;
413
414 let out = '';
415 let lastIndex = 0;
416
417 while ((match = mongooseComRegex.exec(block)) !== null) {
418 // console.log("match", match);
419 // cant just use "match.index" byitself, because of the extra "href=\"" condition, which is not factored in in "match.index"
420 const startIndex = match.index + match[0].length - match[1].length;
421 out += block.slice(lastIndex, startIndex);
422 lastIndex = startIndex + match[1].length;
423
424 // somewhat primitive gathering of the url, but should be enough for now
425 const fullUrl = /^\/[^"]+/.exec(block.slice(lastIndex - 1));
426
427 let noPrefix = false;
428
429 if (fullUrl) {
430 // extra processing to only use "#otherId" instead of using full url for the same page
431 // at least firefox does not make a difference between a full path and just "#", but it makes debugging paths easier
432 if (fullUrl[0].startsWith(currentUrl)) {
433 const indexMatch = /#/.exec(fullUrl);
434
435 if (indexMatch) {
436 lastIndex += indexMatch.index - 1;
437 noPrefix = true;
438 }
439 }
440 }
441
442 if (!noPrefix) {
443 // map all to the versioned-path, unless a explicit version is given
444 if (!versionedDocs.test(block.slice(lastIndex, lastIndex + 10))) {
445 out += versionObj.versionedPath + '/';
446 } else {
447 out += '/';
448 }
449 }
450 }
451
452 out += block.slice(lastIndex);
453
454 return out;
455}
456
457/**
458 * Render a given file with the given options

Callers 1

renderFileFunction · 0.85

Calls 1

testMethod · 0.80

Tested by

no test coverage detected