yoastseo
Version:
Yoast client-side content analysis
36 lines (33 loc) • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _url = _interopRequireDefault(require("../url/url"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/** @module stringProcess/getLinkType */
/**
* Determines the type of link.
*
* @param {string} anchor String with anchor element.
* @param {string} siteUrlOrDomain URL or domain to match against.
*
* @returns {string} The link type (other, external or internal).
*/
function _default(anchor, siteUrlOrDomain) {
const anchorUrl = _url.default.getFromAnchorTag(anchor);
/**
* A link is "Other" if:
* - The protocol is neither null, nor http, nor https.
* - The link is a relative fragment URL (starts with #), because it won't navigate to another page.
*/
const protocol = _url.default.getProtocol(anchorUrl);
if (protocol && !_url.default.protocolIsHttpScheme(protocol) || _url.default.isRelativeFragmentURL(anchorUrl)) {
return "other";
}
if (_url.default.isInternalLink(anchorUrl, siteUrlOrDomain)) {
return "internal";
}
return "external";
}
//# sourceMappingURL=getLinkType.js.map