ソースを参照

Merge branch 'feat/replace-perma-link' into feat/replace-updated-markdown-link

# Conflicts:
#	src/client/js/components/PageEditor/LinkEditModal.jsx
#	src/client/js/models/Linker.js
yusuketk 5 年 前
コミット
623a383dfd

+ 1 - 1
src/client/js/components/PageEditor/LinkEditModal.jsx

@@ -1,7 +1,6 @@
 import React from 'react';
 import React from 'react';
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
 
 
-
 import {
 import {
   Modal,
   Modal,
   ModalHeader,
   ModalHeader,
@@ -195,6 +194,7 @@ class LinkEditModal extends React.PureComponent {
       labelInputValue,
       labelInputValue,
       linkInputValue,
       linkInputValue,
       isUseRelativePath,
       isUseRelativePath,
+      pageContainer.state.path,
       isUsePermanentLink,
       isUsePermanentLink,
       permalink,
       permalink,
       pageContainer.state.path,
       pageContainer.state.path,

+ 27 - 3
src/client/js/models/Linker.js

@@ -2,12 +2,22 @@ import path from 'path';
 
 
 export default class Linker {
 export default class Linker {
 
 
-  constructor(type = this.type.markdownLink, label = '', link = '', isUseRelativePath = false, rootPath = '') {
+  constructor(
+      type,
+      label,
+      link,
+      isUseRelativePath = false,
+      rootPath = '',
+      isUsePermanentLink = false,
+      permalink = '',
+  ) {
     this.type = type;
     this.type = type;
     this.label = label;
     this.label = label;
     this.link = link;
     this.link = link;
     this.isUseRelativePath = isUseRelativePath;
     this.isUseRelativePath = isUseRelativePath;
     this.rootPath = rootPath;
     this.rootPath = rootPath;
+    this.isUsePermanentLink = isUsePermanentLink;
+    this.permalink = permalink;
 
 
     this.generateMarkdownText = this.generateMarkdownText.bind(this);
     this.generateMarkdownText = this.generateMarkdownText.bind(this);
   }
   }
@@ -31,6 +41,9 @@ export default class Linker {
     if (this.isUseRelativePath && this.link.match(/^\//)) {
     if (this.isUseRelativePath && this.link.match(/^\//)) {
       reshapedLink = path.relative(this.rootPath, this.link);
       reshapedLink = path.relative(this.rootPath, this.link);
     }
     }
+    if (this.isUsePermanentLink && this.permalink != null) {
+      reshapedLink = this.permalink;
+    }
 
 
     if (this.type === Linker.types.pukiwikiLink) {
     if (this.type === Linker.types.pukiwikiLink) {
       if (this.label === reshapedLink) return `[[${reshapedLink}]]`;
       if (this.label === reshapedLink) return `[[${reshapedLink}]]`;
@@ -44,7 +57,6 @@ export default class Linker {
     }
     }
   }
   }
 
 
-
   // create an instance of Linker from string
   // create an instance of Linker from string
   static fromMarkdownString(str) {
   static fromMarkdownString(str) {
     // if str doesn't mean a linker, create a link whose label is str
     // if str doesn't mean a linker, create a link whose label is str
@@ -75,7 +87,19 @@ export default class Linker {
       ({ label, link } = str.match(this.patterns.markdownLink).groups);
       ({ label, link } = str.match(this.patterns.markdownLink).groups);
     }
     }
 
 
-    return new Linker(type, label, link);
+    // TODO GW-3074 相対パスを利用しているかテキストから判定し以下の値に反映する
+    const isUseRelativePath = false;
+    const rootPath = '';
+
+    return new Linker(
+      type,
+      label,
+      link,
+      isUseRelativePath,
+      rootPath,
+      false,
+      '',
+    );
   }
   }
 
 
   // create an instance of Linker from text with index
   // create an instance of Linker from text with index