Răsfoiți Sursa

add tools for path

Yuki Takei 3 ani în urmă
părinte
comite
aadf38b9ff

+ 11 - 0
packages/core/src/utils/page-path-utils.ts

@@ -1,6 +1,8 @@
 import nodePath from 'path';
 import nodePath from 'path';
 
 
 import escapeStringRegexp from 'escape-string-regexp';
 import escapeStringRegexp from 'escape-string-regexp';
+import { isValidObjectId } from 'mongoose';
+
 
 
 import { addTrailingSlash } from './path-utils';
 import { addTrailingSlash } from './path-utils';
 
 
@@ -20,6 +22,15 @@ export const isUsersTopPage = (path: string): boolean => {
   return path === '/user';
   return path === '/user';
 };
 };
 
 
+/**
+ * Whether the path is permalink
+ * @param path
+ */
+export const isPermalink = (path: string): boolean => {
+  const pageIdStr = path.substring(1);
+  return isValidObjectId(pageIdStr);
+};
+
 /**
 /**
  * Whether path is user's home page
  * Whether path is user's home page
  * @param path
  * @param path

+ 16 - 0
packages/core/src/utils/path-utils.js

@@ -73,6 +73,22 @@ export function addTrailingSlash(path) {
   return path;
   return path;
 }
 }
 
 
+/**
+ *
+ * @param {string} path
+ * @returns {string}
+ * @memberof pathUtils
+ */
+export function removeHeadingSlash(path) {
+  if (path === '/') {
+    return path;
+  }
+
+  return hasHeadingSlash(path)
+    ? path.substring(1)
+    : path;
+}
+
 /**
 /**
  *
  *
  * @param {string} path
  * @param {string} path