mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-06 09:21:54 +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 PropTypes from 'prop-types';
|
||||
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 Loading from './loading';
|
||||
import { seafileAPI } from '../utils/seafile-api';
|
||||
@@ -159,10 +159,16 @@ class WikiMarkdownViewer extends React.Component {
|
||||
else if (item.type == 'link') {
|
||||
url = item.data.href;
|
||||
// change file url
|
||||
if (Utils.isInternalFileLink(url, repoID)) {
|
||||
if (Utils.isInternalMarkdownLink(url, repoID)) {
|
||||
let path = Utils.getPathFromInternalMarkdownLink(url, repoID);
|
||||
// replace url
|
||||
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
|
||||
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) {
|
||||
var re = new RegExp(serviceURL + '/lib/' + repoID + '.*\.md$');
|
||||
return re.test(url);
|
||||
|
Reference in New Issue
Block a user