1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-06 01:12:03 +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:
llj
2020-04-08 16:51:21 +08:00
committed by GitHub
parent 5a140d35c9
commit 605068cb7a
2 changed files with 19 additions and 8 deletions

View File

@@ -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';
@@ -158,13 +158,19 @@ 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.isInternalMarkdownLink(url, repoID)) { if (Utils.isInternalFileLink(url, repoID)) {
let path = Utils.getPathFromInternalMarkdownLink(url, repoID); if (Utils.isInternalMarkdownLink(url, repoID)) {
// replace url let path = Utils.getPathFromInternalMarkdownLink(url, repoID);
item.data.href = serviceURL + '/published/' + slug + path; // replace url
} item.data.href = serviceURL + '/published/' + slug + path;
// change dir url } 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
else if (Utils.isInternalDirLink(url, repoID)) { else if (Utils.isInternalDirLink(url, repoID)) {
let path = Utils.getPathFromInternalDirLink(url, repoID); let path = Utils.getPathFromInternalDirLink(url, repoID);
// replace url // replace url

View File

@@ -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);