Przeglądaj źródła

use growi-commons

Yuki Takei 7 lat temu
rodzic
commit
fe88f79c5b

+ 1 - 1
packages/growi-plugin-lsx/package.json

@@ -21,7 +21,7 @@
   },
   "homepage": "https://github.com/weseek/growi-plugin-lsx#readme",
   "dependencies": {
-    "growi-pluginkit": "^1.1.0",
+    "growi-commons": "^3.1.0",
     "url": "^0.11.0"
   },
   "devDependencies": {

+ 7 - 21
packages/growi-plugin-lsx/src/client/js/components/Lsx.jsx

@@ -3,6 +3,8 @@ import PropTypes from 'prop-types';
 
 import * as url from 'url';
 
+import { pathUtils } from 'growi-commons';
+
 // eslint-disable-next-line no-unused-vars
 import styles from '../../css/index.css';
 
@@ -43,7 +45,7 @@ export class Lsx extends React.Component {
 
     // add slash ensure not to forward match to another page
     // ex: '/Java/' not to match to '/JavaScript'
-    let pagePath = this.addSlashOfEnd(lsxContext.pagePath);
+    let pagePath = pathUtils.addTrailingSlash(lsxContext.pagePath);
 
     this.props.crowi.apiGet('/plugins/lsx', {pagePath, options: lsxContext.options})
       .then((res) => {
@@ -82,7 +84,7 @@ export class Lsx extends React.Component {
     pages.forEach((page) => {
       // add slash ensure not to forward match to another page
       // e.g. '/Java/' not to match to '/JavaScript'
-      const pagePath = this.addSlashOfEnd(page.path);
+      const pagePath = pathUtils.addTrailingSlash(page.path);
 
       // exclude rootPagePath itself
       if (this.isEquals(pagePath, rootPagePath)) {
@@ -151,23 +153,7 @@ export class Lsx extends React.Component {
   }
 
   /**
-   * return path that added slash to the end for specified path
-   *
-   * @param {string} path
-   * @returns
-   *
-   * @memberOf LsxContext
-   */
-  addSlashOfEnd(path) {
-    let returnPath = path;
-    if (!path.match(/\/$/)) {
-      returnPath += '/';
-    }
-    return returnPath;
-  }
-
-  /**
-   * addSlashOfEnd and compare whether path1 and path2 is the same
+   * compare whether path1 and path2 is the same
    *
    * @param {string} path1
    * @param {string} path2
@@ -176,11 +162,11 @@ export class Lsx extends React.Component {
    * @memberOf Lsx
    */
   isEquals(path1, path2) {
-    return this.addSlashOfEnd(path1) === this.addSlashOfEnd(path2);
+    return pathUtils.removeTrailingSlash(path1) === pathUtils.removeTrailingSlash(path2);
   }
 
   getParentPath(path) {
-    return this.addSlashOfEnd(decodeURIComponent(url.resolve(path, '../')));
+    return pathUtils.addTrailingSlash(decodeURIComponent(url.resolve(path, '../')));
   }
 
   renderContents() {

+ 3 - 13
packages/growi-plugin-lsx/src/client/js/components/LsxPageList/LsxPage.jsx

@@ -1,6 +1,8 @@
 import React from 'react';
 import PropTypes from 'prop-types';
 
+import { pathUtils } from 'growi-commons';
+
 import PageListMeta from '@client/js/components/PageList/PageListMeta';
 
 import { LsxContext } from '../../util/LsxContext';
@@ -75,25 +77,13 @@ export class LsxPage extends React.Component {
       : <i className="ti-file lsx-page-not-exist" aria-hidden="true"></i>;
   }
 
-  /**
-   * return path that omitted slash of the end for specified path
-   *
-   * @param {string} path
-   * @returns
-   *
-   * @memberOf LsxContext
-   */
-  omitSlashOfEnd(path) {
-    return path.replace((/\/$/), '');
-  }
-
   render() {
     const pageNode = this.props.pageNode;
 
     // create PagePath element
     let pagePathNode = <PagePathWrapper pagePath={pageNode.pagePath} isExists={this.state.isExists} />;
     if (this.state.isLinkable) {
-      pagePathNode = <a className="page-list-link" href={this.omitSlashOfEnd(pageNode.pagePath)}>{pagePathNode}</a>;
+      pagePathNode = <a className="page-list-link" href={pathUtils.removeTrailingSlash(pageNode.pagePath)}>{pagePathNode}</a>;
     }
 
     // create PageListMeta element

+ 1 - 1
packages/growi-plugin-lsx/src/client/js/util/Interceptor/LsxPostRenderInterceptor.js

@@ -1,7 +1,7 @@
 import React from 'react';
 import ReactDOM from 'react-dom';
 
-import { BasicInterceptor } from 'growi-pluginkit';
+import { BasicInterceptor } from 'growi-commons';
 
 import { Lsx } from '../../components/Lsx';
 import { LsxCacheHelper } from '../LsxCacheHelper';

+ 1 - 1
packages/growi-plugin-lsx/src/client/js/util/Interceptor/LsxPreRenderInterceptor.js

@@ -1,4 +1,4 @@
-import { BasicInterceptor } from 'growi-pluginkit';
+import { BasicInterceptor } from 'growi-commons';
 
 import { LsxContext } from '../LsxContext';
 import { LsxCacheHelper } from '../LsxCacheHelper';

+ 3 - 17
packages/growi-plugin-lsx/src/client/js/util/LsxContext.js

@@ -1,5 +1,7 @@
 import * as url from 'url';
 
+import { pathUtils } from 'growi-commons';
+
 export class LsxContext {
 
   constructor() {
@@ -62,28 +64,12 @@ export class LsxContext {
     //   when `fromPagePath`=/hoge and `specifiedPath`=undefined,
     //        `pagePath` to be /hoge
     this.pagePath = (specifiedPath !== undefined) ?
-      decodeURIComponent(url.resolve(this.addSlashOfEnd(this.fromPagePath), specifiedPath)):
+      decodeURIComponent(url.resolve(pathUtils.addTrailingSlash(this.fromPagePath), specifiedPath)):
       this.fromPagePath;
 
     this.isParsed = true;
   }
 
-  /**
-   * return path that added slash to the end for specified path
-   *
-   * @param {string} path
-   * @returns
-   *
-   * @memberOf LsxContext
-   */
-  addSlashOfEnd(path) {
-    let returnPath = path;
-    if (!path.match(/\/$/)) {
-      returnPath += '/';
-    }
-    return returnPath;
-  }
-
   getOptDepth() {
     if (this.options.depth == undefined) {
       return undefined;

+ 4 - 3
packages/growi-plugin-lsx/yarn.lock

@@ -878,9 +878,10 @@ graceful-fs@^4.1.2:
   version "4.1.11"
   resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
 
-growi-pluginkit@^1.1.0:
-  version "1.1.0"
-  resolved "https://registry.yarnpkg.com/growi-pluginkit/-/growi-pluginkit-1.1.0.tgz#8e837cd0ba50e6a13eacc75882e09c96eda10679"
+growi-commons@^3.1.0:
+  version "3.1.0"
+  resolved "https://registry.yarnpkg.com/growi-commons/-/growi-commons-3.1.0.tgz#f75756d7c34aa2f96612243968b3e7b8c36a5280"
+  integrity sha512-x57/t8is1SIAA7NkdTCgCNAWpETNbUb7mnd6X4wbc7z5WbiqURB6GBECR7uNxLvGDFl6/6ngknOZLy+AmhB/ng==
 
 has-ansi@^2.0.0:
   version "2.0.0"