Skip to content

Commit

Permalink
engine: improve /doc*/{item} redirect, move public/docs/ to public/st…
Browse files Browse the repository at this point in the history
…atic/docs/

and update all references accordingly, including a few previously-broken ones.
  • Loading branch information
jorgeorpinel committed Dec 29, 2019
1 parent 9b0f867 commit 4064aa7
Show file tree
Hide file tree
Showing 113 changed files with 50 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .restyled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ restylers:
include:
- './*.{js,md}'
- 'pages/**/*.js'
- 'public/docs/**/*.{js,md}'
- 'public/static/docs/**/*.{js,md}'
- 'src/**/*.js'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Please feel free to use it for your own sites and
We welcome contributions to the DVC docs by the community!

You can refer to our
[Contributing guide](https://dvc.org/doc/user-guide/contributing/docs/) for more
[Contributing guide](https://dvc.org/doc/user-guide/contributing/docs) for more
details. Thank you!

**If you need help:**
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"test": "jest",
"start": "NODE_ENV=production node server.js",
"format-staged": "pretty-quick --staged --no-restage --bail",
"format-check": "prettier --check '{.,pages/**,public/docs/**,src/**}/*.{js,md}'",
"format-check": "prettier --check '{.,pages/**,public/static/docs/**,src/**}/*.{js,md}'",
"lint-check": "eslint src pages",
"format-all": "prettier --write '{.,pages/**,public/docs/**,src/**}/*.{js,md}'",
"format-all": "prettier --write '{.,pages/**,public/static/docs/**,src/**}/*.{js,md}'",
"format": "prettier --write"
},
"repository": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To contribute documentation you need to know these locations:
- [Images](https://github.com/iterative/dvc.org/tree/master/img) (`/img`): Add
new images, gif, svg, etc here. Reference them from the Markdown files like
this: `![](/img/reproducibility.png)`.
- [Sections](https://github.com/iterative/dvc.org/tree/master/docs/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
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ operation:
- `.dvc/cache`: The [cache directory](#structure-of-cache-directory) will store
your data. The data files and directories in <abbr>DVC repositories</abbr>
will only contain links to the data files in the cache. (Refer to
[Large Dataset Optimization](/docs/user-guide/large-dataset-optimization). See
[Large Dataset Optimization](/doc/user-guide/large-dataset-optimization). See
`dvc config cache` for related configuration options.

> Note that DVC includes the cache directory in `.gitignore` during
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 7 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ app.prepare().then(() => {
)
})
res.end()
} else if (/^\/doc(?!s\/).*/i.test(pathname)) {
// path /doc*/... -> /doc/... except for /docs/* (static .md files)
let normalized_pathname = pathname.replace(/^\/doc[^?/]*/i, '/doc')
} else if (/^\/doc.*/i.test(pathname)) {
// path /doc*/{item} -> /doc/{item} and trim trailing / if present
let normalized_pathname = pathname.replace(
/^(\/doc[^/?]*)\/(.*[^/])?\/?/i,
'/doc/$2'
)

if (normalized_pathname !== pathname) {
res.writeHead(301, {
Location:
Expand Down
2 changes: 1 addition & 1 deletion src/Tooltip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { Component } from 'react'
import DesktopView from './desktop-view'
import MobileView from './mobile-view'
import PropTypes from 'prop-types'
import glossary from '../../public/docs/glossary'
import glossary from '../../public/static/docs/glossary'
import includes from 'lodash.includes'

class Tooltip extends Component {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env node */

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

/*
We will use this helper to normalize sidebar structure and create
Expand All @@ -12,7 +12,7 @@ const sidebar = require('../../public/docs/sidebar.json')
{
label: "Add Files or Directories",
path: "/doc/get-started/add-files",
source: "/docs/get-started/add-files.md",
source: "/static/docs/get-started/add-files.md",
prev: "/doc/get-started/configure",
next: "/doc/get-started/share-data",
tutorials: {
Expand All @@ -23,7 +23,7 @@ const sidebar = require('../../public/docs/sidebar.json')
*/

const PATH_ROOT = '/doc/'
const FILE_ROOT = '/docs/'
const FILE_ROOT = '/static/docs/'
const FILE_EXTENSION = '.md'

// Inner helpers
Expand Down
64 changes: 33 additions & 31 deletions src/utils/sidebar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ describe('SidebarMenu/helper', () => {
{
label: 'Item Name',
path: '/doc/item-name',
source: '/docs/item-name.md',
source: '/static/docs/item-name.md',
tutorials: {},
prev: undefined,
next: undefined
}
]

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

expect(sidebarData).toEqual(result)
Expand All @@ -31,14 +31,14 @@ describe('SidebarMenu/helper', () => {
{
label: 'Item Name',
path: '/doc/item-name',
source: '/docs/item-name.md',
source: '/static/docs/item-name.md',
tutorials: {},
prev: undefined,
next: undefined
}
]

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

expect(sidebarData).toEqual(result)
Expand All @@ -50,14 +50,14 @@ describe('SidebarMenu/helper', () => {
{
label: 'Custom Label',
path: '/doc/item-name',
source: '/docs/item-name.md',
source: '/static/docs/item-name.md',
tutorials: {},
prev: undefined,
next: undefined
}
]

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

expect(sidebarData).toEqual(result)
Expand All @@ -69,14 +69,14 @@ describe('SidebarMenu/helper', () => {
{
label: 'Item Name',
path: '/doc/item-name',
source: '/docs/item-name/index.md',
source: '/static/docs/item-name/index.md',
tutorials: {},
prev: undefined,
next: undefined
}
]

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

expect(sidebarData).toEqual(result)
Expand All @@ -96,7 +96,7 @@ describe('SidebarMenu/helper', () => {
{
label: 'Item Name',
path: '/doc/item-name',
source: '/docs/item-name.md',
source: '/static/docs/item-name.md',
tutorials: {
katacoda:
'https://www.katacoda.com/loodse/courses/dvc/dvc-01-install'
Expand All @@ -106,7 +106,7 @@ describe('SidebarMenu/helper', () => {
}
]

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

expect(sidebarData).toEqual(result)
Expand All @@ -123,23 +123,24 @@ describe('SidebarMenu/helper', () => {
{
label: 'Item Name',
path: '/doc/item-name',
source: '/docs/item-name.md',
source: '/static/docs/item-name.md',
tutorials: {},
prev: undefined,
next: '/doc/item-name/nested-item',
children: [
{
label: 'Nested Item',
path: '/doc/item-name/nested-item',
source: '/docs/item-name/nested-item.md',
source: '/static/docs/item-name/nested-item.md',
tutorials: {},
prev: '/doc/item-name',
next: '/doc/item-name/nested-item/subnested-item',
children: [
{
label: 'Subnested Item',
path: '/doc/item-name/nested-item/subnested-item',
source: '/docs/item-name/nested-item/subnested-item.md',
source:
'/static/docs/item-name/nested-item/subnested-item.md',
tutorials: {},
prev: '/doc/item-name/nested-item',
next: undefined
Expand All @@ -150,7 +151,7 @@ describe('SidebarMenu/helper', () => {
}
]

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

expect(sidebarData).toEqual(result)
Expand All @@ -165,15 +166,15 @@ describe('SidebarMenu/helper', () => {
{
label: 'First Item',
path: '/doc/first-item',
source: '/docs/first-item.md',
source: '/static/docs/first-item.md',
tutorials: {},
prev: undefined,
next: '/doc/first-item/nested-item',
children: [
{
label: 'Nested Item',
path: '/doc/first-item/nested-item',
source: '/docs/first-item/nested-item.md',
source: '/static/docs/first-item/nested-item.md',
tutorials: {},
prev: '/doc/first-item',
next: '/doc/second-item'
Expand All @@ -183,14 +184,14 @@ describe('SidebarMenu/helper', () => {
{
label: 'Second Item',
path: '/doc/second-item',
source: '/docs/second-item.md',
source: '/static/docs/second-item.md',
tutorials: {},
prev: '/doc/first-item/nested-item',
next: undefined
}
]

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

expect(sidebarData).toEqual(result)
Expand All @@ -205,7 +206,7 @@ describe('SidebarMenu/helper', () => {
{
label: 'First Item',
path: '/doc/first-item',
source: '/docs/first-item.md',
source: '/static/docs/first-item.md',
tutorials: {},
prev: undefined,
next: '/doc/second-item'
Expand All @@ -221,7 +222,7 @@ describe('SidebarMenu/helper', () => {
{
label: 'Nested Item',
path: '/doc/second-item/nested-item',
source: '/docs/second-item/nested-item.md',
source: '/static/docs/second-item/nested-item.md',
tutorials: {},
prev: '/doc/first-item',
next: undefined
Expand All @@ -230,7 +231,7 @@ describe('SidebarMenu/helper', () => {
}
]

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

expect(sidebarData).toEqual(result)
Expand All @@ -251,7 +252,7 @@ describe('SidebarMenu/helper', () => {
{
label: 'First Item',
path: '/doc/first-item',
source: '/docs/first-item.md',
source: '/static/docs/first-item.md',
tutorials: {},
prev: undefined,
next: '/doc/second-item'
Expand All @@ -275,7 +276,8 @@ describe('SidebarMenu/helper', () => {
{
label: 'Subnested Item',
path: '/doc/second-item/nested-item/subnested-item',
source: '/docs/second-item/nested-item/subnested-item.md',
source:
'/static/docs/second-item/nested-item/subnested-item.md',
tutorials: {},
prev: '/doc/first-item',
next: undefined
Expand All @@ -286,7 +288,7 @@ describe('SidebarMenu/helper', () => {
}
]

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

expect(sidebarData).toEqual(result)
Expand All @@ -295,7 +297,7 @@ describe('SidebarMenu/helper', () => {
it("Throws error if item didn't have slug field", () => {
const rawData = [{}]

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

expect(() => require('./sidebar')).toThrow(
new Error("'slug' field is required in objects in sidebar.json")
Expand All @@ -306,7 +308,7 @@ 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('../../public/docs/sidebar.json', () => rawData)
jest.doMock('../../public/static/docs/sidebar.json', () => rawData)

expect(() => require('./sidebar')).toThrow(
new Error(
Expand All @@ -322,13 +324,13 @@ describe('SidebarMenu/helper', () => {
const result = {
label: 'Item Name',
path: '/doc/item-name',
source: '/docs/item-name.md',
source: '/static/docs/item-name.md',
tutorials: {},
prev: undefined,
next: undefined
}

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

expect(getItemByPath('/doc')).toEqual(result)
Expand All @@ -347,13 +349,13 @@ describe('SidebarMenu/helper', () => {
const result = {
label: 'Subnested Item',
path: '/doc/item-name/nested-item/subnested-item',
source: '/docs/item-name/nested-item/subnested-item.md',
source: '/static/docs/item-name/nested-item/subnested-item.md',
tutorials: {},
prev: undefined,
next: undefined
}

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

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

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

expect(getParentsListFromPath(path)).toEqual(result)
Expand Down

0 comments on commit 4064aa7

Please sign in to comment.