From fdff270e5ce5c33ca37ef7005d660e270b9a63a6 Mon Sep 17 00:00:00 2001 From: ilearnit Date: Wed, 24 Apr 2019 08:40:23 +0000 Subject: [PATCH] fix index.md bug && update url wikis-->published --- frontend/src/app.js | 2 +- frontend/src/components/index-viewer.js | 21 +++++++++++++------ frontend/src/components/main-side-nav.js | 2 +- .../wiki-dir-list-view/wiki-dir-list-item.js | 2 +- .../src/components/wiki-markdown-viewer.js | 4 ++-- frontend/src/pages/wiki/main-panel.js | 2 +- frontend/src/utils/utils.js | 8 +++---- frontend/src/wiki.js | 6 +++--- seahub/urls.py | 1 + tests/api/endpoints/test_wikis.py | 4 ++-- tests/seahub/wiki/test_models.py | 2 +- tests/seahub/wiki/test_views.py | 2 +- 12 files changed, 33 insertions(+), 23 deletions(-) diff --git a/frontend/src/app.js b/frontend/src/app.js index 300f620264..d212faa452 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -230,7 +230,7 @@ class App extends Component { onTabNavClick={this.tabItemClick} onGroupChanged={this.onGroupChanged} /> - + diff --git a/frontend/src/components/index-viewer.js b/frontend/src/components/index-viewer.js index 6ab44415cd..c6f93fdf2d 100644 --- a/frontend/src/components/index-viewer.js +++ b/frontend/src/components/index-viewer.js @@ -9,7 +9,7 @@ const viewerPropTypes = { onLinkClick: PropTypes.func.isRequired, }; -const contentClass = 'wiki-page-content'; +const contentClass = 'wiki-nav-content'; class IndexContentViewer extends React.Component { @@ -58,6 +58,7 @@ class IndexContentViewer extends React.Component { target = target.parentNode; } link = target.href; + } else { link = event.target.href; } @@ -86,18 +87,27 @@ class IndexContentViewer extends React.Component { else if (item.type == 'link') { url = item.data.href; + + let expression = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/ + let re = new RegExp(expression); + + // Solving relative paths + if (!re.test(url)) { + item.data.href = serviceURL + "/published/" + slug + '/' + url; + } // change file url - if (Utils.isInternalMarkdownLink(url, repoID)) { + else if (Utils.isInternalMarkdownLink(url, repoID)) { let path = Utils.getPathFromInternalMarkdownLink(url, repoID); + console.log(path); // replace url - item.data.href = serviceURL + '/wikis/' + slug + path; + item.data.href = serviceURL + '/published/' + slug + path; } // change dir url else if (Utils.isInternalDirLink(url, repoID)) { let path = Utils.getPathFromInternalDirLink(url, repoID); // replace url - item.data.href = serviceURL + '/wikis/' + slug + path; - } + item.data.href = serviceURL + '/published/' + slug + path; + } } } @@ -126,7 +136,6 @@ class IndexContentViewer extends React.Component { ); } - } IndexContentViewer.propTypes = viewerPropTypes; diff --git a/frontend/src/components/main-side-nav.js b/frontend/src/components/main-side-nav.js index 02807bf9d5..c6d5e2a3fe 100644 --- a/frontend/src/components/main-side-nav.js +++ b/frontend/src/components/main-side-nav.js @@ -200,7 +200,7 @@ class MainSideNav extends React.Component { } {enableWiki &&
  • - this.tabItemClick('wikis')}> + this.tabItemClick('published')}> {gettext('Published Libraries')} diff --git a/frontend/src/components/wiki-dir-list-view/wiki-dir-list-item.js b/frontend/src/components/wiki-dir-list-view/wiki-dir-list-item.js index 30fd208c83..c9be38d194 100644 --- a/frontend/src/components/wiki-dir-list-view/wiki-dir-list-item.js +++ b/frontend/src/components/wiki-dir-list-view/wiki-dir-list-item.js @@ -38,7 +38,7 @@ class WikiDirListItem extends React.Component { render() { let { path, dirent } = this.props; - let href = siteRoot + 'wikis' + Utils.joinPath(path, dirent.name); + let href = siteRoot + 'published' + Utils.joinPath(path, dirent.name); let iconUrl = Utils.getDirentIcon(dirent); return ( diff --git a/frontend/src/components/wiki-markdown-viewer.js b/frontend/src/components/wiki-markdown-viewer.js index 90f1c7a942..ac391851f4 100644 --- a/frontend/src/components/wiki-markdown-viewer.js +++ b/frontend/src/components/wiki-markdown-viewer.js @@ -151,13 +151,13 @@ class WikiMarkdownViewer extends React.Component { if (Utils.isInternalMarkdownLink(url, repoID)) { let path = Utils.getPathFromInternalMarkdownLink(url, repoID); // replace url - item.data.href = serviceURL + '/wikis/' + slug + path; + item.data.href = serviceURL + '/published/' + slug + path; } // change dir url else if (Utils.isInternalDirLink(url, repoID)) { let path = Utils.getPathFromInternalDirLink(url, repoID); // replace url - item.data.href = serviceURL + '/wikis/' + slug + path; + item.data.href = serviceURL + '/published/' + slug + path; } } } diff --git a/frontend/src/pages/wiki/main-panel.js b/frontend/src/pages/wiki/main-panel.js index adc9ab928b..0efdcc4a14 100644 --- a/frontend/src/pages/wiki/main-panel.js +++ b/frontend/src/pages/wiki/main-panel.js @@ -93,7 +93,7 @@ class MainPanel extends Component {
    - {slug} + {slug} {this.renderNavPath()}
    diff --git a/frontend/src/utils/utils.js b/frontend/src/utils/utils.js index 22c33d0e16..3140a12e86 100644 --- a/frontend/src/utils/utils.js +++ b/frontend/src/utils/utils.js @@ -473,19 +473,19 @@ export const Utils = { isWikiInternalMarkdownLink: function(url, slug) { slug = encodeURIComponent(slug); - var re = new RegExp(serviceURL + '/wikis/' + slug + '.*\.md$'); + var re = new RegExp(serviceURL + '/published/' + slug + '.*\.md$'); return re.test(url); }, isWikiInternalDirLink: function(url, slug) { slug = encodeURIComponent(slug); - var re = new RegExp(serviceURL + '/wikis/' + slug + '.*'); + var re = new RegExp(serviceURL + '/published/' + slug + '.*'); return re.test(url); }, getPathFromWikiInternalMarkdownLink: function(url, slug) { slug = encodeURIComponent(slug); - var re = new RegExp(serviceURL + '/wikis/' + slug + '(.*\.md)'); + var re = new RegExp(serviceURL + '/published/' + slug + '(.*\.md)'); var array = re.exec(url); var path = array[1]; try { @@ -499,7 +499,7 @@ export const Utils = { getPathFromWikiInternalDirLink: function(url, slug) { slug = encodeURIComponent(slug); - var re = new RegExp(serviceURL + '/wikis/' + slug + '(/.*)'); + var re = new RegExp(serviceURL + '/published/' + slug + '(/.*)'); var array = re.exec(url); var path = array[1]; try { diff --git a/frontend/src/wiki.js b/frontend/src/wiki.js index 31dd093461..f3397bdf1b 100644 --- a/frontend/src/wiki.js +++ b/frontend/src/wiki.js @@ -58,7 +58,7 @@ class Wiki extends Component { this.showDir('/'); } else { this.setState({pathExist: false}); - let fileUrl = siteRoot + 'wikis/' + slug + Utils.encodePath(initialPath); + let fileUrl = siteRoot + 'published/' + slug + Utils.encodePath(initialPath); window.history.pushState({url: fileUrl, path: initialPath}, initialPath, fileUrl); } } else if (isDir === 'True') { @@ -102,7 +102,7 @@ class Wiki extends Component { this.loadDirentList(dirPath); // update location url - let fileUrl = siteRoot + 'wikis/' + slug + Utils.encodePath(dirPath); + let fileUrl = siteRoot + 'published/' + slug + Utils.encodePath(dirPath); window.history.pushState({url: fileUrl, path: dirPath}, dirPath, fileUrl); } @@ -125,7 +125,7 @@ class Wiki extends Component { }); const hash = window.location.hash; - let fileUrl = siteRoot + 'wikis/' + slug + Utils.encodePath(filePath) + hash; + let fileUrl = siteRoot + 'published/' + slug + Utils.encodePath(filePath) + hash; if (filePath === '/home.md') { window.history.replaceState({url: fileUrl, path: filePath}, filePath, fileUrl); } else { diff --git a/seahub/urls.py b/seahub/urls.py index c50afe0099..232a7ce5dc 100644 --- a/seahub/urls.py +++ b/seahub/urls.py @@ -497,6 +497,7 @@ urlpatterns = [ url(r'^inst/', include('seahub.institutions.urls', app_name='institutions', namespace='institutions')), url(r'^invite/', include('seahub.invitations.urls', app_name='invitations', namespace='invitations')), url(r'^terms/', include('termsandconditions.urls')), + url(r'^published/', include('seahub.wiki.urls', app_name='wiki', namespace='wiki')), url(r'^wikis/', include('seahub.wiki.urls', app_name='wiki', namespace='wiki')), url(r'^drafts/', include('seahub.drafts.urls', app_name='drafts', namespace='drafts')), diff --git a/tests/api/endpoints/test_wikis.py b/tests/api/endpoints/test_wikis.py index 8590ff626f..4fb397a2cc 100644 --- a/tests/api/endpoints/test_wikis.py +++ b/tests/api/endpoints/test_wikis.py @@ -29,7 +29,7 @@ class WikisViewTest(BaseTestCase): json_resp = json.loads(resp.content) assert len(json_resp['data']) == 1 assert json_resp['data'][0]['name'] == wiki.name - assert 'wikis/test-wiki' in json_resp['data'][0]['link'] + assert 'published/test-wiki' in json_resp['data'][0]['link'] assert json_resp['data'][0]['owner'] == self.user.username print json_resp['data'][0]['created_at'] assert json_resp['data'][0]['created_at'] is not None @@ -53,7 +53,7 @@ class WikisViewTest(BaseTestCase): json_resp = json.loads(resp.content) assert len(json_resp['data']) == 1 assert json_resp['data'][0]['name'] == wiki.name - assert 'wikis/test-wiki' in json_resp['data'][0]['link'] + assert 'published/test-wiki' in json_resp['data'][0]['link'] assert json_resp['data'][0]['owner'] == self.user.username def test_can_add(self): diff --git a/tests/seahub/wiki/test_models.py b/tests/seahub/wiki/test_models.py index 7f350d9473..17033a2e13 100644 --- a/tests/seahub/wiki/test_models.py +++ b/tests/seahub/wiki/test_models.py @@ -10,7 +10,7 @@ class WikiTest(BaseTestCase): wiki = Wiki.objects.add('new wiki', self.user.username) d = wiki.to_dict() - assert 'wikis/new-wiki/' in d['link'] + assert 'published/new-wiki/' in d['link'] assert 'new-wiki' == d['slug'] assert 'T' in d['created_at'] assert 'T' in d['updated_at'] diff --git a/tests/seahub/wiki/test_views.py b/tests/seahub/wiki/test_views.py index 646b10ef17..29e7455271 100644 --- a/tests/seahub/wiki/test_views.py +++ b/tests/seahub/wiki/test_views.py @@ -17,4 +17,4 @@ class SlugTest(BaseTestCase): def test_old_home_page(self, ): resp = self.client.get(reverse('wiki:slug', args=['new-wiki', 'home'])) self.assertEqual(302, resp.status_code) - self.assertRegexpMatches(resp['Location'], '/wikis/new-wiki/home.md') + self.assertRegexpMatches(resp['Location'], '/published/new-wiki/home.md')