mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-15 23:00:57 +00:00
wiki relative image path
This commit is contained in:
@@ -127,21 +127,23 @@ class WikiMarkdownViewer extends React.Component {
|
||||
|
||||
changeInlineNode = (item) => {
|
||||
if (item.object == 'inline') {
|
||||
let url;
|
||||
let url, imagePath;
|
||||
|
||||
// change image url
|
||||
if (item.type == 'image' && isPublicWiki) {
|
||||
url = item.data.src;
|
||||
const re = new RegExp(serviceURL + '/lib/' + repoID +'/file.*raw=1');
|
||||
// different repo
|
||||
if (!re.test(url)) {
|
||||
return;
|
||||
}
|
||||
if (re.test(url)) {
|
||||
// get image path
|
||||
let index = url.indexOf('/file');
|
||||
let index2 = url.indexOf('?');
|
||||
const imagePath = url.substring(index + 5, index2);
|
||||
// replace url
|
||||
imagePath = url.substring(index + 5, index2);
|
||||
} else if (/^\.\.\/*/.test(url) || /^\.\/*/.test(url)) {
|
||||
imagePath = Utils.pathNormalize(this.props.path, url);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
item.data.src = serviceURL + '/view-image-via-public-wiki/?slug=' + slug + '&path=' + imagePath;
|
||||
}
|
||||
|
||||
|
@@ -116,6 +116,7 @@ class MainPanel extends Component {
|
||||
latestContributor={this.props.latestContributor}
|
||||
onLinkClick={this.props.onLinkClick}
|
||||
isWiki={true}
|
||||
path={this.props.path}
|
||||
/>
|
||||
)}
|
||||
{(!this.props.isDataLoading && !this.props.isViewFile) && (
|
||||
|
@@ -880,6 +880,22 @@ export const Utils = {
|
||||
return password;
|
||||
},
|
||||
|
||||
pathNormalize: function(filePath, relativePath) {
|
||||
let newPath = relativePath.split('/');
|
||||
let path = filePath.slice(1, filePath.lastIndexOf('/')).split('/');
|
||||
for (let i = 0, len = newPath.length; i < len; i++) {
|
||||
if (newPath[i] === '..') {
|
||||
path.pop();
|
||||
newPath.splice(i, 1);
|
||||
i--;
|
||||
} else if (newPath[i] === '.') {
|
||||
newPath.splice(i, 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
return path.concat(newPath).join('/');
|
||||
},
|
||||
|
||||
getEventData: function(event, data) {
|
||||
if (event.target.dataset) {
|
||||
return event.target.dataset[data];
|
||||
|
Reference in New Issue
Block a user