@tryghost/url-utils 4.1.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/url-utils.js +17 -0
  2. package/package.json +2 -2
package/lib/url-utils.js CHANGED
@@ -495,6 +495,23 @@ module.exports = class UrlUtils {
495
495
  return utils.plaintextToTransformReady(plaintext, this.getSiteUrl(), _options);
496
496
  }
497
497
 
498
+ /**
499
+ * Return whether the provided URL is part of the site (checks if same domain and within subdirectory)
500
+ * @param {URL} url
501
+ * @param {string} [context] describing the context for which you need to check a url
502
+ * @returns {boolean}
503
+ */
504
+ isSiteUrl(url, context = 'home') {
505
+ const siteUrl = new URL(this.urlFor(context, true));
506
+ if (siteUrl.host === url.host) {
507
+ if (url.pathname.startsWith(siteUrl.pathname)) {
508
+ return true;
509
+ }
510
+ return false;
511
+ }
512
+ return false;
513
+ }
514
+
498
515
  get isSSL() {
499
516
  return utils.isSSL;
500
517
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/url-utils",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "repository": "https://github.com/TryGhost/SDK/tree/master/packages/url-utils",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -34,5 +34,5 @@
34
34
  "remark-footnotes": "^1.0.0",
35
35
  "unist-util-visit": "^2.0.0"
36
36
  },
37
- "gitHead": "c4bc4d5ee2c7fea2eb9fc8de6cb8fd479ea039e3"
37
+ "gitHead": "7e8faa4260a758bca46ef7f6ff7ed0bd7ec21a13"
38
38
  }