From 53d6c5fdf27fd3f7000d2e307c66bed6ff84e068 Mon Sep 17 00:00:00 2001 From: ProjGoodF Date: Wed, 22 May 2019 09:03:16 +0300 Subject: [PATCH 1/6] first commit --- src/Documentation/SidebarMenu/SidebarMenu.js | 66 ++++++++------------ 1 file changed, 25 insertions(+), 41 deletions(-) diff --git a/src/Documentation/SidebarMenu/SidebarMenu.js b/src/Documentation/SidebarMenu/SidebarMenu.js index 7a19f4fed9..d98fc81f7a 100644 --- a/src/Documentation/SidebarMenu/SidebarMenu.js +++ b/src/Documentation/SidebarMenu/SidebarMenu.js @@ -2,9 +2,6 @@ import React, { Fragment } from 'react' import $ from 'jquery' // components import DownloadButton from '../../DownloadButton' -// utils -import startCase from 'lodash.startcase' -import includes from 'lodash.includes' // styles import styled from 'styled-components' import { media, OnlyDesktop } from '../../styles' @@ -32,10 +29,19 @@ export default class SidebarMenu extends React.Component { } } render() { - let self = this + let self = this; + function includes(array, value) { + let flag = false; + array.map(elem=>{ + if(elem.indexFile===value){ + flag = true; + } + }); + return flag; + } const { sidebar, - currentSection, + currentSection,/*индекс дефолтной корневой секции*/ currentFile, onSectionSelect, onFileSelect, @@ -48,15 +54,12 @@ export default class SidebarMenu extends React.Component { {sidebar.map( ({ name, files = [], labels = {}, indexFile }, index) => { - const isSectionActive = currentSection === index + const isSectionActive = currentSection === index; return (
onSectionSelect(index, e)} className={isSectionActive ? 'docSearch-lvl0' : ''} isActive={isSectionActive} @@ -66,54 +69,35 @@ export default class SidebarMenu extends React.Component { {/* Section Files */} - {files && - files.map((fileOrGroup, fileIndex) => { - const file = Array.isArray(fileOrGroup) - ? fileOrGroup[0] - : fileOrGroup - const subgroup = Array.isArray(fileOrGroup) - ? fileOrGroup.slice(1) - : null - const isFileActive = currentFile === file + {files && files.map((file, fileIndex) => { + const subgroup = file.files.length>0 ? file.files : null; + const isFileActive = currentFile === file.indexFile; return (
onFileSelect(file, index, e)} isActive={isFileActive} > - {labels[file] || startCase(file.slice(0, -3))} + {file.name}
{/* Subgroup files */} {subgroup && ( - - {subgroup.map((sub, subIndex) => { + + {subgroup.map((file, subIndex) => { return ( -
+
- onFileSelect(sub, index, e) - } - isActive={currentFile === sub} + href={getLinkHref(index, file.indexFile)} + onClick={e => onFileSelect(file, index, e)} + isActive={currentFile === file.indexFile} > - {labels[sub] || - startCase(sub.slice(0, -3))} + {file.name}
) From 3a2e3201c5558de381574fa66740033d739e07ba Mon Sep 17 00:00:00 2001 From: ProjGoodF Date: Wed, 22 May 2019 11:26:05 +0300 Subject: [PATCH 2/6] second commit --- pages/doc.js | 110 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 43 deletions(-) diff --git a/pages/doc.js b/pages/doc.js index 4c2704b2a1..eb3475942b 100644 --- a/pages/doc.js +++ b/pages/doc.js @@ -54,36 +54,58 @@ export default class Documentation extends Component { window.removeEventListener('popstate', this.loadStateFromURL) } + /*сделать!*/ loadStateFromURL = () => { - const { pathname } = window.location - const sectionURL = pathname.split('/')[2] // match section from URL + const { pathname } = window.location; + const sectionURL = pathname.split('/')[2]; const sectionIndex = sidebar.findIndex( - section => (section.slug || kebabCase(section.name)) === sectionURL - ) + section => kebabCase(section.name) === sectionURL + ); if (sectionIndex === -1) { - sectionURL - ? this.setState({ pageNotFound: true }) - : this.onSectionSelect(0) + this.setState({ pageNotFound: true }) } else { - const fileURL = pathname.split('/')[3] // match file from URL - const sectionFiles = flatten(sidebar[sectionIndex].files) - const fileIndex = sectionFiles.findIndex( - file => kebabCase(file.slice(0, -3)) === fileURL - ) - if (fileIndex === -1) { - fileURL - ? this.setState({ pageNotFound: true }) - : this.onSectionSelect(sectionIndex) - } else { - this.loadFile({ - section: sectionIndex, - file: sectionFiles[fileIndex], - parseHeadings: true, - pageNotFound: false - }) + const fileURL = pathname.split('/')[3]; // match file from URL + const section = sidebar[sectionIndex]; + if(fileURL){ + let fileIndex = section.files.findIndex( + file => kebabCase(file.indexFile.slice(0, -3)) === fileURL + ); + if (fileIndex === -1) { + let fileIndex2=-1, subsectionIndex=0; + section.files.map((subsection,index2)=>{ + if (subsection.files.length>0){ + fileIndex2 = subsection.files.findIndex( + file2 => { + if(kebabCase(file2.indexFile.slice(0, -3)) === fileURL){ + subsectionIndex = index2; + } + return kebabCase(file2.indexFile.slice(0, -3)) === fileURL + } + ); + } + }); + if (fileIndex2 === -1){ + fileURL ? this.setState({ pageNotFound: true }) : this.onSectionSelect(sectionIndex) + }else{ + this.loadFile({ + file: section.files[subsectionIndex].files[fileIndex2], + section: sectionIndex, + parseHeadings: true, + }) + } + }else{ + this.loadFile({ + file: section.files[fileIndex], + section: sectionIndex, + parseHeadings: true, + }) + } + }else{ + console.log(section); + this.loadFile({ file:section, section: sectionIndex, parseHeadings: false }); } } - } + }; initDocsearch = () => { docsearch({ @@ -92,41 +114,43 @@ export default class Documentation extends Component { inputSelector: '#doc-search', debug: false // Set debug to true if you want to inspect the dropdown }) - } + }; + /*готово*/ getLinkHref = (section, file) => { - const sectionSlug = - sidebar[section].slug || kebabCase(sidebar[section].name) - const fileSlug = file ? kebabCase(file.slice(0, -3)) : undefined - return `/doc/${compact([sectionSlug, fileSlug]).join('/')}` - } + const sectionSlug = kebabCase(sidebar[section].name); + const fileSlug = file ? file.slice(0, -3) : undefined; + return `/doc/${compact([sectionSlug, fileSlug]).join('/')}`; + }; + /*готово*/ setCurrentPath = (section, file) => { window.history.pushState(null, null, this.getLinkHref(section, file)) - } + }; + /*готово*/ onSectionSelect = (section, e) => { - e && e.preventDefault() - const { indexFile, files } = sidebar[section] - const file = indexFile || flatten(files)[0] - e && this.setCurrentPath(section, indexFile ? undefined : file) - this.loadFile({ file, section, parseHeadings: false }) - } + e && e.preventDefault(); + const file = sidebar[section]; + e && this.setCurrentPath(section); + this.loadFile({ file, section, parseHeadings: false }); + }; + /*готово*/ onFileSelect = (file, section, e) => { - e && e.preventDefault() - this.setCurrentPath(section, file) - this.loadFile({ file, section, parseHeadings: true }) - } + e && e.preventDefault(); + this.setCurrentPath(section, file.indexFile); + this.loadFile({ file, section, parseHeadings: true }); + }; loadFile = ({ file, section, parseHeadings }) => { - fetch(`${sidebar[section].folder}/${file}`) + fetch(`${file.folder}/${file.indexFile}`) .then(res => { res.text().then(text => { this.setState( { currentSection: section, - currentFile: file, + currentFile: file.indexFile, markdown: text, headings: [], pageNotFound: false, From e4ee2096e9f5927d16737b6bae4c89de6ebbe78e Mon Sep 17 00:00:00 2001 From: ProjGoodF Date: Wed, 22 May 2019 11:32:39 +0300 Subject: [PATCH 3/6] third commit --- src/Documentation/sidebar.json | 692 ++++++++++++++++++++++++--------- 1 file changed, 518 insertions(+), 174 deletions(-) diff --git a/src/Documentation/sidebar.json b/src/Documentation/sidebar.json index a64c67bff0..b56577b646 100644 --- a/src/Documentation/sidebar.json +++ b/src/Documentation/sidebar.json @@ -4,212 +4,556 @@ "folder": "/static/docs/get-started", "indexFile": "index.md", "files": [ - "agenda.md", - "install.md", - "initialize.md", - "configure.md", - "add-files.md", - "share-data.md", - "retrieve-data.md", - "connect-code-and-data.md", - "pipeline.md", - "visualize.md", - "reproduce.md", - "metrics.md", - "experiments.md", - "compare-experiments.md", - "older-versions.md", - "example-versioning.md", - "example-pipeline.md" - ], - "labels": { - "connect-code-and-data.md": "Connect with Code", - "example-pipeline.md": "Example: Pipelines", - "example-versioning.md": "Example: Versioning", - "older-versions.md": "Get Older Files" - } + { + "name": "Agenda", + "folder": "/static/docs/get-started", + "indexFile": "agenda.md", + "files": [] + }, + { + "name": "Install", + "folder": "/static/docs/get-started", + "indexFile": "install.md", + "files": [] + }, + { + "name": "Initialize", + "folder": "/static/docs/get-started", + "indexFile": "initialize.md", + "files": [] + }, + { + "name": "Configure", + "folder": "/static/docs/get-started", + "indexFile": "configure.md", + "files": [] + }, + { + "name": "Add Files", + "folder": "/static/docs/get-started", + "indexFile": "add-files.md", + "files": [] + }, + { + "name": "Share Data", + "folder": "/static/docs/get-started", + "indexFile": "share-data.md", + "files": [] + }, + { + "name": "Retrieve Data", + "folder": "/static/docs/get-started", + "indexFile": "retrieve-data.md", + "files": [] + }, + { + "name": "Connect Code And Data", + "folder": "/static/docs/get-started", + "indexFile": "connect-code-and-data.md", + "files": [] + }, + { + "name": "Pipeline", + "folder": "/static/docs/get-started", + "indexFile": "pipeline.md", + "files": [] + }, + { + "name": "Visualize", + "folder": "/static/docs/get-started", + "indexFile": "visualize.md", + "files": [] + }, + { + "name": "Reproduce", + "folder": "/static/docs/get-started", + "indexFile": "reproduce.md", + "files": [] + }, + { + "name": "Metrics", + "folder": "/static/docs/get-started", + "indexFile": "metrics.md", + "files": [] + }, + { + "name": "Experiments", + "folder": "/static/docs/get-started", + "indexFile": "experiments.md", + "files": [] + }, + { + "name": "Compare Experiments", + "folder": "/static/docs/get-started", + "indexFile": "compare-experiments.md", + "files": [] + }, + { + "name": "Older Versions", + "folder": "/static/docs/get-started", + "indexFile": "older-versions.md", + "files": [] + }, + { + "name": "Example Versioning", + "folder": "/static/docs/get-started", + "indexFile": "example-versioning.md", + "files": [] + }, + { + "name": "Example Pipeline", + "folder": "/static/docs/get-started", + "indexFile": "example-pipeline.md", + "files": [] + } + ] }, { "name": "Use Cases", "folder": "/static/docs/use-cases", "indexFile": "index.md", "files": [ - "data-and-model-files-versioning.md", - "share-data-and-model-files.md", - "multiple-data-scientists-on-a-single-machine.md" - ], - "labels": { - "data-and-model-files-versioning.md": "Data & Model Files Versioning", - "share-data-and-model-files.md": "Share Data & Model Files", - "multiple-data-scientists-on-a-single-machine.md": - "Shared Development Machine" - } + { + "name": "Data And Model Files Versioning", + "folder": "/static/docs/use-cases", + "indexFile": "data-and-model-files-versioning.md", + "files": [] + }, + { + "name": "Share Data And Model Files", + "folder": "/static/docs/use-cases", + "indexFile": "share-data-and-model-files.md", + "files": [] + }, + { + "name": "Multiple Data Scientists On A Single Machine", + "folder": "/static/docs/use-cases", + "indexFile": "multiple-data-scientists-on-a-single-machine.md", + "files": [] + } + ] }, { "name": "User Guide", "folder": "/static/docs/user-guide", "files": [ - "dvc-files-and-directories.md", - "dvc-file-format.md", - "external-dependencies.md", - "external-outputs.md", - "development.md", - "contributing.md", - "contributing-documentation.md", - "update-tracked-file.md", - "autocomplete.md", - "plugins.md", - "analytics.md", - "dvcignore.md" - ], - "labels": { - "dvc-files-and-directories.md": "Files and Directories", - "dvc-file-format.md": "File Format (.dvc)", - "development.md": "Development Version", - "external-dependencies.md": "External Dependencies", - "external-outputs.md": "External Outputs", - "contributing.md": "Contributing", - "contributing-documentation.md": "Contributing Documentation", - "update-tracked-file.md": "Update a Tracked File", - "autocomplete.md": "Shell Autocomplete", - "plugins.md": "Plugins & Integrations", - "analytics.md": "Anonymized Usage Analytics" - } + { + "name" : "Dvc Files And Directries", + "indexFile" : "dvc-files-and-directries.md", + "folder": "/static/docs/user-guide", + "files":[] + }, + { + "name" : "Dvc File Format", + "indexFile" : "dvc-file-format.md", + "folder": "/static/docs/user-guide", + "files": [] + }, + { + "name" : "External Dependences", + "indexFile" : "external-dependences.md", + "folder": "/static/docs/user-guide", + "files":[] + }, + { + "name" : "External Output", + "indexFile" : "external-outputs.m", + "folder": "/static/docs/user-guide", + "files":[] + }, + { + "name" : "Development", + "indexFile" : "development.md", + "folder": "/static/docs/user-guide", + "files":[] + }, + + { + "name" : "Contributing", + "indexFile" : "contributing.md", + "folder" : "/static/docs/user-guide", + "files" : [] + }, + { + "name": "Contributing Documntation", + "indexFile": "contributing-documntation.md", + "folder": "/static/docs/user-guide", + "files": [] + }, + + { + "name" : "Update Tracked Fil", + "indexFile" : "update-tracked-fil.md", + "folder": "/static/docs/user-guide", + "files":[] + }, + { + "name": "Autocomplete", + "indexFile": "autocomplete.md", + "folder": "/static/docs/user-guide", + "files": [] + }, + { + "name": "Plugins", + "indexFile": "plugins.md", + "folder": "/static/docs/user-guide", + "files": [] + }, + { + "name": "Analytics", + "indexFile": "analytics.md", + "folder": "/static/docs/user-guide", + "files": [] + }, + { + "name": "Dvcignore", + "indexFile": "dvcignore.md", + "folder": "/static/docs/user-guide", + "files": [] + }, + { + "name": "Data And Model Files Versioning", + "folder": "/static/docs/user-guide", + "indexFile": "data-and-model-files-versioning.md", + "files": [] + } + ] }, { "name": "Commands Reference", "folder": "/static/docs/commands-reference", "indexFile": "index.md", "files": [ - "add.md", - [ - "cache.md", - "cache:dir.md" - ], - "checkout.md", - "commit.md", - "config.md", - "diff.md", - "destroy.md", - "fetch.md", - "gc.md", - "init.md", - "install.md", - "import.md", - "lock.md", - [ - "metrics.md", - "metrics:add.md", - "metrics:modify.md", - "metrics:remove.md", - "metrics:show.md" - ], - "move.md", - [ - "pipeline.md", - "pipeline:list.md", - "pipeline:show.md" - ], - "push.md", - "pull.md", - [ - "remote.md", - "remote:add.md", - "remote:default.md", - "remote:list.md", - "remote:modify.md", - "remote:remove.md" - ], - "remove.md", - "repro.md", - "root.md", - "run.md", - "status.md", - "unlock.md", - "unprotect.md", - "version.md" - ], - "labels": { - "run.md": "run", - "push.md": "push", - "init.md": "init", - "add.md": "add", - "checkout.md": "checkout", - "diff.md": "diff", - "pull.md": "pull", - "status.md": "status", - "repro.md": "repro", - "fetch.md": "fetch", - "remove.md": "remove", - "gc.md": "gc", - "config.md": "config", - "remote.md": "remote", - "remote:add.md": "remote add", - "remote:default.md": "remote default", - "remote:list.md": "remote list", - "remote:modify.md": "remote modify", - "remote:remove.md": "remote remove", - "metrics.md": "metrics", - "metrics:add.md": "metrics add", - "metrics:show.md": "metrics show", - "metrics:modify.md": "metrics modify", - "metrics:remove.md": "metrics remove", - "install.md": "install", - "root.md": "root", - "lock.md": "lock", - "unlock.md": "unlock", - "import.md": "import", - "move.md": "move", - "pipeline.md": "pipeline", - "pipeline:list.md": "pipeline list", - "pipeline:show.md": "pipeline show", - "destroy.md": "destroy", - "unprotect.md": "unprotect", - "cache.md": "cache", - "cache:dir.md": "cache dir", - "commit.md": "commit", - "version.md": "version" - } + { + "name": "Add", + "folder": "/static/docs/commands-reference", + "indexFile": "add.md", + "files": [] + }, + { + "name": "Cache", + "folder": "/static/docs/commands-reference", + "indexFile": "cache.md", + "files": [ + { + "name": "Dir", + "folder": "/static/docs/commands-reference", + "indexFile": "dir.md", + "files": [] + } + ] + }, + { + "name": "Checkout", + "folder": "/static/docs/commands-reference", + "indexFile": "checkout.md", + "files": [] + }, + { + "name": "Commit", + "folder": "/static/docs/commands-reference", + "indexFile": "commit.md", + "files": [] + }, + { + "name": "Config", + "folder": "/static/docs/commands-reference", + "indexFile": "config.md", + "files": [] + }, + { + "name": "Diff", + "folder": "/static/docs/commands-reference", + "indexFile": "diff.md", + "files": [] + }, + { + "name": "Destroy", + "folder": "/static/docs/commands-reference", + "indexFile": "destroy.md", + "files": [] + }, + { + "name": "Fetch", + "folder": "/static/docs/commands-reference", + "indexFile": "fetch.md", + "files": [] + }, + { + "name": "Gc", + "folder": "/static/docs/commands-reference", + "indexFile": "gc.md", + "files": [] + }, + { + "name": "Init", + "folder": "/static/docs/commands-reference", + "indexFile": "init.md", + "files": [] + }, + { + "name": "Install", + "folder": "/static/docs/commands-reference", + "indexFile": "install.md", + "files": [] + }, + { + "name": "Import", + "folder": "/static/docs/commands-reference", + "indexFile": "import.md", + "files": [] + }, + { + "name": "Lock", + "folder": "/static/docs/commands-reference", + "indexFile": "lock.md", + "files": [] + }, + { + "name": "Metrics", + "folder": "/static/docs/commands-reference", + "indexFile": "metrics.md", + "files": [ + { + "name": "Add", + "folder": "/static/docs/commands-reference", + "indexFile": "add.md", + "files": [] + }, + { + "name": "Modify", + "folder": "/static/docs/commands-reference", + "indexFile": "modify.md", + "files": [] + }, + { + "name": "Remove", + "folder": "/static/docs/commands-reference", + "indexFile": "remove.md", + "files": [] + }, + { + "name": "Show", + "folder": "/static/docs/commands-reference", + "indexFile": "show.md", + "files": [] + } + ] + }, + { + "name": "Move", + "folder": "/static/docs/commands-reference", + "indexFile": "move.md", + "files": [] + }, + { + "name": "Pipeline", + "folder": "/static/docs/commands-reference", + "indexFile": "pipeline.md", + "files": [ + { + "name": "List", + "folder": "/static/docs/commands-reference", + "indexFile": "list.md", + "files": [] + }, + { + "name": "Show", + "folder": "/static/docs/commands-reference", + "indexFile": "show.md", + "files": [] + } + ] + }, + { + "name": "Push", + "folder": "/static/docs/commands-reference", + "indexFile": "push.md", + "files": [] + }, + { + "name": "Pull", + "folder": "/static/docs/commands-reference", + "indexFile": "Pull.md", + "files": [] + }, + { + "name": "Remote", + "folder": "/static/docs/commands-reference", + "indexFile": "remote.md", + "files": [ + { + "name": "Add", + "folder": "/static/docs/commands-reference", + "indexFile": "add.md", + "files": [] + }, + { + "name": "Default", + "folder": "/static/docs/commands-reference", + "indexFile": "default.md", + "files": [] + }, + { + "name": "List", + "folder": "/static/docs/commands-reference", + "indexFile": "list.md", + "files": [] + }, + { + "name": "Modify", + "folder": "/static/docs/commands-reference", + "indexFile": "modify.md", + "files": [] + }, + { + "name": "Remove", + "folder": "/static/docs/commands-reference", + "indexFile": "remove.md", + "files": [] + } + ] + }, + { + "name": "Remove", + "folder": "/static/docs/commands-reference", + "indexFile": "remove.md", + "files": [] + }, + { + "name": "Repro", + "folder": "/static/docs/commands-reference", + "indexFile": "repro.md", + "files": [] + }, + { + "name": "Root", + "folder": "/static/docs/commands-reference", + "indexFile": "root.md", + "files": [] + }, + { + "name": "Run", + "folder": "/static/docs/commands-reference", + "indexFile": "run.md", + "files": [] + }, + { + "name": "Status", + "folder": "/static/docs/commands-reference", + "indexFile": "status.md", + "files": [] + }, + { + "name": "Unlock", + "folder": "/static/docs/commands-reference", + "indexFile": "unlock.md", + "files": [] + }, + { + "name": "Unprotect", + "folder": "/static/docs/commands-reference", + "indexFile": "unprotect.md", + "files": [] + }, + { + "name": "Version", + "folder": "/static/docs/commands-reference", + "indexFile": "version.md", + "files": [] + } + ] }, { "name": "Tutorial", "folder": "/static/docs/tutorial", "indexFile": "index.md", "files": [ - "preparation.md", - "define-ml-pipeline.md", - "reproducibility.md", - "sharing-data.md" - ], - "labels": { - "define-ml-pipeline.md": "Define ML Pipeline" - } + { + "name": "Preparation", + "folder": "/static/docs/tutorial", + "indexFile": "preparation.md", + "files": [] + }, + { + "name": "Define Ml Pipeline", + "folder": "/static/docs/tutorial", + "indexFile": "define-ml-pipeline.md", + "files": [] + }, + { + "name": "Reproducibility", + "folder": "/static/docs/tutorial", + "indexFile": "reproducibility.md", + "files": [] + }, + { + "name": "Sharing Data", + "folder": "/static/docs/tutorial", + "indexFile": "sharing-data.md", + "files": [] + } + + ] }, { "name": "DVC Philosophy", "folder": "/static/docs/philosophy", "files": [ - "collaboration-issues.md", - "existing-tools.md", - "what-is-dvc.md", - "core-features.md", - "how-it-works.md", - "related-technologies.md" - ], - "labels": { - "what-is-dvc.md": "What is DVC?" - } + { + "name": "Collaboration Issues", + "folder": "/static/docs/philosophy", + "indexFile": "collaboration-issues.md", + "files": [] + }, + { + "name": "Existing Tools", + "folder": "/static/docs/philosophy", + "indexFile": "existing-tools.md", + "files": [] + }, + { + "name": "What Is Dvc", + "folder": "/static/docs/philosophy", + "indexFile": "what-is-dvc.md", + "files": [] + }, + { + "name": "Core Features", + "folder": "/static/docs/philosophy", + "indexFile": "core-features.md", + "files": [] + }, + { + "name": "How It Works", + "folder": "/static/docs/philosophy", + "indexFile": "how-it-works.md", + "files": [] + }, + { + "name": "Related Technologies", + "folder": "/static/docs/philosophy", + "indexFile": "related-technologies.md", + "files": [] + } + ] }, { "name": "Changelog", "folder": "/static/docs/changelog", "files": [ - "0.35.md", - "0.18.md" - ], - "labels": { - "0.18.md": "v0.12 - v0.18", - "0.35.md": "v0.19 - v0.35" - } + { + "name": "0.35", + "folder": "/static/docs/changelog", + "indexFile": "0.35.md", + "files": [] + }, + { + "name": "0.18", + "folder": "/static/docs/changelog", + "indexFile": "0.18.md", + "files": [] + } + ] } ] From 05614ee63faf2c786d41d4760632e98c6c7caf86 Mon Sep 17 00:00:00 2001 From: ProjGoodF Date: Thu, 23 May 2019 12:56:27 +0300 Subject: [PATCH 4/6] fourth commit --- src/Documentation/SidebarMenu/SidebarMenu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Documentation/SidebarMenu/SidebarMenu.js b/src/Documentation/SidebarMenu/SidebarMenu.js index d98fc81f7a..1a60ecda3a 100644 --- a/src/Documentation/SidebarMenu/SidebarMenu.js +++ b/src/Documentation/SidebarMenu/SidebarMenu.js @@ -87,7 +87,7 @@ export default class SidebarMenu extends React.Component { {/* Subgroup files */} {subgroup && ( - + {subgroup.map((file, subIndex) => { return (
From c2294be29e6bedba8a1b26f6623a995a106d1779 Mon Sep 17 00:00:00 2001 From: ProjGoodF Date: Thu, 23 May 2019 15:00:23 +0300 Subject: [PATCH 5/6] fifth commit --- pages/doc.js | 82 ++++++++++++-------- src/Documentation/SidebarMenu/SidebarMenu.js | 2 +- src/Documentation/sidebar.json | 4 +- 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/pages/doc.js b/pages/doc.js index eb3475942b..d843f3cc39 100644 --- a/pages/doc.js +++ b/pages/doc.js @@ -54,7 +54,7 @@ export default class Documentation extends Component { window.removeEventListener('popstate', this.loadStateFromURL) } - /*сделать!*/ + /*готово*/ loadStateFromURL = () => { const { pathname } = window.location; const sectionURL = pathname.split('/')[2]; @@ -67,42 +67,55 @@ export default class Documentation extends Component { const fileURL = pathname.split('/')[3]; // match file from URL const section = sidebar[sectionIndex]; if(fileURL){ - let fileIndex = section.files.findIndex( - file => kebabCase(file.indexFile.slice(0, -3)) === fileURL - ); - if (fileIndex === -1) { - let fileIndex2=-1, subsectionIndex=0; - section.files.map((subsection,index2)=>{ - if (subsection.files.length>0){ - fileIndex2 = subsection.files.findIndex( - file2 => { - if(kebabCase(file2.indexFile.slice(0, -3)) === fileURL){ - subsectionIndex = index2; + if(pathname.split('/')[4]){ + let subsectionIndex = section.files.findIndex( + file => kebabCase(file.indexFile.slice(0, -3)) === fileURL + ); + let fileIndex = section.files[subsectionIndex].files.findIndex( + file => kebabCase(file.indexFile.slice(0, -3)) === pathname.split('/')[4] + ); + this.loadFile({ + file: section.files[subsectionIndex].files[fileIndex], + section: sectionIndex, + parseHeadings: true, + }) + }else{ + let fileIndex = section.files.findIndex( + file => kebabCase(file.indexFile.slice(0, -3)) === fileURL + ); + if (fileIndex === -1) { + let fileIndex2=-1, subsectionIndex=0; + section.files.map((subsection,index2)=>{ + if (subsection.files.length>0){ + fileIndex2 = subsection.files.findIndex( + file2 => { + if(kebabCase(file2.indexFile.slice(0, -3)) === fileURL){ + subsectionIndex = index2; + } + return kebabCase(file2.indexFile.slice(0, -3)) === fileURL } - return kebabCase(file2.indexFile.slice(0, -3)) === fileURL - } - ); + ); + } + }); + if (fileIndex2 === -1){ + fileURL ? this.setState({ pageNotFound: true }) : this.onSectionSelect(sectionIndex) + }else{ + this.loadFile({ + file: section.files[subsectionIndex].files[fileIndex2], + section: sectionIndex, + parseHeadings: true, + }) } - }); - if (fileIndex2 === -1){ - fileURL ? this.setState({ pageNotFound: true }) : this.onSectionSelect(sectionIndex) }else{ this.loadFile({ - file: section.files[subsectionIndex].files[fileIndex2], + file: section.files[fileIndex], section: sectionIndex, parseHeadings: true, }) } - }else{ - this.loadFile({ - file: section.files[fileIndex], - section: sectionIndex, - parseHeadings: true, - }) } }else{ - console.log(section); - this.loadFile({ file:section, section: sectionIndex, parseHeadings: false }); + this.loadFile({ file:section.hasOwnProperty('indexFile') ? section : section.files[0], section: sectionIndex, parseHeadings: false }); } } }; @@ -117,29 +130,30 @@ export default class Documentation extends Component { }; /*готово*/ - getLinkHref = (section, file) => { + getLinkHref = (section, file, subsection=null) => { const sectionSlug = kebabCase(sidebar[section].name); const fileSlug = file ? file.slice(0, -3) : undefined; - return `/doc/${compact([sectionSlug, fileSlug]).join('/')}`; + let subsectionSlug = subsection ? sidebar[section].files[subsection].indexFile.slice(0,-3) : ''; + return `/doc/${compact([sectionSlug, subsectionSlug, fileSlug]).join('/')}`; }; /*готово*/ - setCurrentPath = (section, file) => { - window.history.pushState(null, null, this.getLinkHref(section, file)) + setCurrentPath = (section, file, subsection) => { + window.history.pushState(null, null, this.getLinkHref(section, file, subsection)) }; /*готово*/ onSectionSelect = (section, e) => { e && e.preventDefault(); - const file = sidebar[section]; + const file = sidebar[section].hasOwnProperty('indexFile') ? sidebar[section] : sidebar[section].files[0]; e && this.setCurrentPath(section); this.loadFile({ file, section, parseHeadings: false }); }; /*готово*/ - onFileSelect = (file, section, e) => { + onFileSelect = (file, section, e, subsection) => { e && e.preventDefault(); - this.setCurrentPath(section, file.indexFile); + this.setCurrentPath(section, file.indexFile, subsection); this.loadFile({ file, section, parseHeadings: true }); }; diff --git a/src/Documentation/SidebarMenu/SidebarMenu.js b/src/Documentation/SidebarMenu/SidebarMenu.js index 1a60ecda3a..acda8bf483 100644 --- a/src/Documentation/SidebarMenu/SidebarMenu.js +++ b/src/Documentation/SidebarMenu/SidebarMenu.js @@ -94,7 +94,7 @@ export default class SidebarMenu extends React.Component { onFileSelect(file, index, e)} + onClick={e => onFileSelect(file, index, e, fileIndex)} isActive={currentFile === file.indexFile} > {file.name} diff --git a/src/Documentation/sidebar.json b/src/Documentation/sidebar.json index b56577b646..3c66bab17c 100644 --- a/src/Documentation/sidebar.json +++ b/src/Documentation/sidebar.json @@ -138,8 +138,8 @@ "folder": "/static/docs/user-guide", "files": [ { - "name" : "Dvc Files And Directries", - "indexFile" : "dvc-files-and-directries.md", + "name" : "Dvc Files And Directories", + "indexFile" : "dvc-files-and-directories.md", "folder": "/static/docs/user-guide", "files":[] }, From 0a5b534d8dea3c132428638d5a9a74be1cf6ebe0 Mon Sep 17 00:00:00 2001 From: ProjGoodF Date: Thu, 23 May 2019 15:05:33 +0300 Subject: [PATCH 6/6] cleaning --- pages/doc.js | 5 ----- src/Documentation/SidebarMenu/SidebarMenu.js | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/pages/doc.js b/pages/doc.js index d843f3cc39..2c29a233da 100644 --- a/pages/doc.js +++ b/pages/doc.js @@ -54,7 +54,6 @@ export default class Documentation extends Component { window.removeEventListener('popstate', this.loadStateFromURL) } - /*готово*/ loadStateFromURL = () => { const { pathname } = window.location; const sectionURL = pathname.split('/')[2]; @@ -129,7 +128,6 @@ export default class Documentation extends Component { }) }; - /*готово*/ getLinkHref = (section, file, subsection=null) => { const sectionSlug = kebabCase(sidebar[section].name); const fileSlug = file ? file.slice(0, -3) : undefined; @@ -137,12 +135,10 @@ export default class Documentation extends Component { return `/doc/${compact([sectionSlug, subsectionSlug, fileSlug]).join('/')}`; }; - /*готово*/ setCurrentPath = (section, file, subsection) => { window.history.pushState(null, null, this.getLinkHref(section, file, subsection)) }; - /*готово*/ onSectionSelect = (section, e) => { e && e.preventDefault(); const file = sidebar[section].hasOwnProperty('indexFile') ? sidebar[section] : sidebar[section].files[0]; @@ -150,7 +146,6 @@ export default class Documentation extends Component { this.loadFile({ file, section, parseHeadings: false }); }; - /*готово*/ onFileSelect = (file, section, e, subsection) => { e && e.preventDefault(); this.setCurrentPath(section, file.indexFile, subsection); diff --git a/src/Documentation/SidebarMenu/SidebarMenu.js b/src/Documentation/SidebarMenu/SidebarMenu.js index acda8bf483..da8e5d0e8c 100644 --- a/src/Documentation/SidebarMenu/SidebarMenu.js +++ b/src/Documentation/SidebarMenu/SidebarMenu.js @@ -41,7 +41,7 @@ export default class SidebarMenu extends React.Component { } const { sidebar, - currentSection,/*индекс дефолтной корневой секции*/ + currentSection, currentFile, onSectionSelect, onFileSelect,