Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pages/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import RightPanel from '../src/Documentation/RightPanel/RightPanel'
import fetch from 'isomorphic-fetch'
import kebabCase from 'lodash.kebabcase'
// sidebar data and helpers
import sidebar, { getItemByPath } from '../src/Documentation/SidebarMenu/helper'
import { structure, getItemByPath } from '../src/utils/sidebar'
// styles
import styled from 'styled-components'
import { media } from '../src/styles'
Expand Down Expand Up @@ -104,7 +104,7 @@ export default function Documentation({ item, headings, markdown, errorCode }) {
)}

<SidebarMenu
sidebar={sidebar}
sidebar={structure}
currentPath={path}
id={SIDEBAR_MENU}
onClick={toggleMenu}
Expand Down Expand Up @@ -166,7 +166,7 @@ Documentation.propTypes = {
item: PropTypes.object,
headings: PropTypes.array,
markdown: PropTypes.string,
errorCode: PropTypes.bool
errorCode: PropTypes.number
}

const Container = styled.div`
Expand Down
5 changes: 5 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')
const querystring = require('querystring')
const { getItemByPath } = require('./src/utils/sidebar')

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
Expand Down Expand Up @@ -106,6 +107,10 @@ app.prepare().then(() => {
})
res.end()
} else {
if (!getItemByPath(pathname)) {
res.statusCode = 404
}

app.render(req, res, '/doc', query)
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Documentation/Markdown/utils/remark-linker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
;`use strict`

import visit from 'unist-util-visit'
import { getItemByPath } from '../../SidebarMenu/helper'
import { getItemByPath } from '../../../utils/sidebar'

const DVC_REGEXP = /dvc\s+[a-z][a-z-.]*/
const COMMAND_REGEXP = /^[a-z][a-z-]*$/
Expand Down
2 changes: 1 addition & 1 deletion src/Documentation/SidebarMenu/SidebarMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import includes from 'lodash.includes'
import styled from 'styled-components'
import { media, OnlyDesktop } from '../../styles'
// sidebar helpers
import { getParentsListFromPath } from './helper'
import { getParentsListFromPath } from '../../utils/sidebar'

/** Height of each menu child items (to calc Element weight for animations) */
const heightMap = {}
Expand Down
15 changes: 10 additions & 5 deletions src/Documentation/SidebarMenu/helper.js → src/utils/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import startCase from 'lodash.startcase'
/* eslint-env node */

import sidebar from '../sidebar'
const startCase = require('lodash.startcase')
const sidebar = require('../../static/docs/sidebar.json')

/*
We will use this helper to normalize sidebar structure and create
Expand Down Expand Up @@ -148,7 +149,7 @@ const normalizedSidebar = normalizeSidebar({

// Exports

export function getItemByPath(path) {
function getItemByPath(path) {
const normalizedPath = path.replace(/\/$/, '')
const isRoot = normalizedPath === PATH_ROOT.slice(0, -1)
const item = isRoot
Expand All @@ -158,7 +159,7 @@ export function getItemByPath(path) {
return item && findChildWithSource(item)
}

export function getParentsListFromPath(path) {
function getParentsListFromPath(path) {
let currentPath = PATH_ROOT.slice(0, -1)

return path
Expand All @@ -172,4 +173,8 @@ export function getParentsListFromPath(path) {
})
}

export default normalizedSidebar
module.exports = {
structure: normalizedSidebar,
getItemByPath,
getParentsListFromPath
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ describe('SidebarMenu/helper', () => {
}
]

jest.doMock('../sidebar.json', () => rawData)
const sidebarData = require('./helper').default
jest.doMock('../../static/docs/sidebar.json', () => rawData)
const sidebarData = require('./sidebar').structure

expect(sidebarData).toEqual(result)
})
Expand All @@ -38,8 +38,8 @@ describe('SidebarMenu/helper', () => {
}
]

jest.doMock('../sidebar.json', () => rawData)
const sidebarData = require('./helper').default
jest.doMock('../../static/docs/sidebar.json', () => rawData)
const sidebarData = require('./sidebar').structure

expect(sidebarData).toEqual(result)
})
Expand All @@ -57,8 +57,8 @@ describe('SidebarMenu/helper', () => {
}
]

jest.doMock('../sidebar.json', () => rawData)
const sidebarData = require('./helper').default
jest.doMock('../../static/docs/sidebar.json', () => rawData)
const sidebarData = require('./sidebar').structure

expect(sidebarData).toEqual(result)
})
Expand All @@ -76,8 +76,8 @@ describe('SidebarMenu/helper', () => {
}
]

jest.doMock('../sidebar.json', () => rawData)
const sidebarData = require('./helper').default
jest.doMock('../../static/docs/sidebar.json', () => rawData)
const sidebarData = require('./sidebar').structure

expect(sidebarData).toEqual(result)
})
Expand Down Expand Up @@ -106,8 +106,8 @@ describe('SidebarMenu/helper', () => {
}
]

jest.doMock('../sidebar.json', () => rawData)
const sidebarData = require('./helper').default
jest.doMock('../../static/docs/sidebar.json', () => rawData)
const sidebarData = require('./sidebar').structure

expect(sidebarData).toEqual(result)
})
Expand Down Expand Up @@ -151,8 +151,8 @@ describe('SidebarMenu/helper', () => {
}
]

jest.doMock('../sidebar.json', () => rawData)
const sidebarData = require('./helper').default
jest.doMock('../../static/docs/sidebar.json', () => rawData)
const sidebarData = require('./sidebar').structure

expect(sidebarData).toEqual(result)
})
Expand Down Expand Up @@ -191,8 +191,8 @@ describe('SidebarMenu/helper', () => {
}
]

jest.doMock('../sidebar.json', () => rawData)
const sidebarData = require('./helper').default
jest.doMock('../../static/docs/sidebar.json', () => rawData)
const sidebarData = require('./sidebar').structure

expect(sidebarData).toEqual(result)
})
Expand Down Expand Up @@ -231,8 +231,8 @@ describe('SidebarMenu/helper', () => {
}
]

jest.doMock('../sidebar.json', () => rawData)
const sidebarData = require('./helper').default
jest.doMock('../../static/docs/sidebar.json', () => rawData)
const sidebarData = require('./sidebar').structure

expect(sidebarData).toEqual(result)
})
Expand Down Expand Up @@ -288,18 +288,18 @@ describe('SidebarMenu/helper', () => {
}
]

jest.doMock('../sidebar.json', () => rawData)
const sidebarData = require('./helper').default
jest.doMock('../../static/docs/sidebar.json', () => rawData)
const sidebarData = require('./sidebar').structure

expect(sidebarData).toEqual(result)
})

it("Throws error if item didn't have slug field", () => {
const rawData = [{}]

jest.doMock('../sidebar.json', () => rawData)
jest.doMock('../../static/docs/sidebar.json', () => rawData)

expect(() => require('./helper')).toThrow(
expect(() => require('./sidebar')).toThrow(
new Error("'slug' field is required in objects in sidebar.json")
)
})
Expand All @@ -308,9 +308,9 @@ describe('SidebarMenu/helper', () => {
it("Throws error if item has source: false and doesn't have children", () => {
const rawData = [{ slug: 'item-name', source: false }]

jest.doMock('../sidebar.json', () => rawData)
jest.doMock('../../static/docs/sidebar.json', () => rawData)

expect(() => require('./helper')).toThrow(
expect(() => require('./sidebar')).toThrow(
new Error(
"If you set 'source' to false, you had to add at least one child"
)
Expand All @@ -330,8 +330,8 @@ describe('SidebarMenu/helper', () => {
next: undefined
}

jest.doMock('../sidebar.json', () => rawData)
const { getItemByPath } = require('./helper')
jest.doMock('../../static/docs/sidebar.json', () => rawData)
const { getItemByPath } = require('./sidebar')

expect(getItemByPath('/doc')).toEqual(result)
})
Expand All @@ -355,8 +355,8 @@ describe('SidebarMenu/helper', () => {
next: undefined
}

jest.doMock('../sidebar.json', () => rawData)
const { getItemByPath } = require('./helper')
jest.doMock('../../static/docs/sidebar.json', () => rawData)
const { getItemByPath } = require('./sidebar')

expect(getItemByPath('/doc/item-name')).toEqual(result)
})
Expand All @@ -372,8 +372,8 @@ describe('SidebarMenu/helper', () => {
'/doc/item-name/nested-item/subnested-item'
]

jest.doMock('../sidebar.json', () => rawData)
const { getParentsListFromPath } = require('./helper')
jest.doMock('../../static/docs/sidebar.json', () => rawData)
const { getParentsListFromPath } = require('./sidebar')

expect(getParentsListFromPath(path)).toEqual(result)
})
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion static/docs/user-guide/contributing/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ To contribute documentation you need to know these locations:
- [Images](https://github.com/iterative/dvc.org/tree/master/static/img)
(`/static/img`): Add new images, gif, svg, etc here. Reference them from the
Markdown files like this: `![](/static/img/reproducibility.png)`.
- [Sections](https://github.com/iterative/dvc.org/tree/master/src/Documentation/sidebar.json)
- [Sections](https://github.com/iterative/dvc.org/tree/master/static/docs/sidebar.json)
(`.../sidebar.json`): Edit it to register a new section for the navigation
menu.

Expand Down