mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-06 17:33:18 +00:00
[wiki markdown file] modified links in the file content (#4517)
* only modified links of inserted files from the current library
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import MarkdownViewer from '@seafile/seafile-editor/dist/viewer/markdown-viewer';
|
import MarkdownViewer from '@seafile/seafile-editor/dist/viewer/markdown-viewer';
|
||||||
import { gettext, repoID, slug, serviceURL, isPublicWiki, siteRoot } from '../utils/constants';
|
import { gettext, repoID, slug, serviceURL, isPublicWiki, siteRoot, sharedToken } from '../utils/constants';
|
||||||
import { Card, CardTitle, CardText } from 'reactstrap';
|
import { Card, CardTitle, CardText } from 'reactstrap';
|
||||||
import Loading from './loading';
|
import Loading from './loading';
|
||||||
import { seafileAPI } from '../utils/seafile-api';
|
import { seafileAPI } from '../utils/seafile-api';
|
||||||
@@ -159,10 +159,16 @@ class WikiMarkdownViewer extends React.Component {
|
|||||||
else if (item.type == 'link') {
|
else if (item.type == 'link') {
|
||||||
url = item.data.href;
|
url = item.data.href;
|
||||||
// change file url
|
// change file url
|
||||||
|
if (Utils.isInternalFileLink(url, repoID)) {
|
||||||
if (Utils.isInternalMarkdownLink(url, repoID)) {
|
if (Utils.isInternalMarkdownLink(url, repoID)) {
|
||||||
let path = Utils.getPathFromInternalMarkdownLink(url, repoID);
|
let path = Utils.getPathFromInternalMarkdownLink(url, repoID);
|
||||||
// replace url
|
// replace url
|
||||||
item.data.href = serviceURL + '/published/' + slug + path;
|
item.data.href = serviceURL + '/published/' + slug + path;
|
||||||
|
} else {
|
||||||
|
item.data.href = url.replace(/(.*)lib\/([-0-9a-f]{36})\/file(.*)/g, (match, p1, p2, p3) => {
|
||||||
|
return `${p1}d/${sharedToken}/files/?p=${p3}&dl=1`;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// change dir url
|
// change dir url
|
||||||
else if (Utils.isInternalDirLink(url, repoID)) {
|
else if (Utils.isInternalDirLink(url, repoID)) {
|
||||||
|
@@ -714,6 +714,11 @@ export const Utils = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isInternalFileLink: function(url, repoID) {
|
||||||
|
var re = new RegExp(serviceURL + '/lib/' + repoID + '/file.*');
|
||||||
|
return re.test(url);
|
||||||
|
},
|
||||||
|
|
||||||
isInternalMarkdownLink: function(url, repoID) {
|
isInternalMarkdownLink: function(url, repoID) {
|
||||||
var re = new RegExp(serviceURL + '/lib/' + repoID + '.*\.md$');
|
var re = new RegExp(serviceURL + '/lib/' + repoID + '.*\.md$');
|
||||||
return re.test(url);
|
return re.test(url);
|
||||||
|
Reference in New Issue
Block a user