|
|
@@ -11,6 +11,7 @@ import {
|
|
|
import { debounce } from 'throttle-debounce';
|
|
|
|
|
|
import path from 'path';
|
|
|
+import validator from 'validator';
|
|
|
import Preview from './Preview';
|
|
|
|
|
|
import AppContainer from '../../services/AppContainer';
|
|
|
@@ -81,6 +82,7 @@ class LinkEditModal extends React.PureComponent {
|
|
|
show: true,
|
|
|
labelInputValue: label,
|
|
|
linkerType: type,
|
|
|
+ isUsePermanentLink: false,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -159,17 +161,23 @@ class LinkEditModal extends React.PureComponent {
|
|
|
}
|
|
|
|
|
|
async getPreview(path) {
|
|
|
- let markdown = '';
|
|
|
- let permalink = '';
|
|
|
- try {
|
|
|
- const res = await this.props.appContainer.apiGet('/pages.get', { path });
|
|
|
- markdown = res.page.revision.body;
|
|
|
- permalink = `${window.location.origin}/${res.page.id}`;
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- markdown = `<div class="alert alert-warning" role="alert"><strong>${err.message}</strong></div>`;
|
|
|
+ if (path.startsWith('/')) {
|
|
|
+ const isPermanentLink = validator.isMongoId(path.slice(1));
|
|
|
+ const pageId = isPermanentLink ? path.slice(1) : null;
|
|
|
+
|
|
|
+ let markdown = '';
|
|
|
+ let permalink = '';
|
|
|
+ try {
|
|
|
+ const { page } = await this.props.appContainer.apiGet('/pages.get', { path, page_id: pageId });
|
|
|
+ markdown = page.revision.body;
|
|
|
+ // create permanent link only if path isn't permanent link because checkbox for isUsePermanentLink is disabled when permalink is ''.
|
|
|
+ permalink = !isPermanentLink ? `${window.location.origin}/${page.id}` : '';
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ markdown = `<div class="alert alert-warning" role="alert"><strong>${err.message}</strong></div>`;
|
|
|
+ }
|
|
|
+ this.setState({ markdown, permalink });
|
|
|
}
|
|
|
- this.setState({ markdown, permalink });
|
|
|
}
|
|
|
|
|
|
handleChangeTypeahead(selected) {
|
|
|
@@ -222,7 +230,7 @@ class LinkEditModal extends React.PureComponent {
|
|
|
}
|
|
|
|
|
|
if (isUsePermanentLink && permalink != null) {
|
|
|
- reshapedLink = this.permalink;
|
|
|
+ reshapedLink = permalink;
|
|
|
}
|
|
|
|
|
|
return new Linker(linkerType, labelInputValue, reshapedLink);
|