summaryrefslogtreecommitdiff
path: root/deps/npm/docs/src/components/DocLinks.js
blob: 3d43b9c92f74987720e04ae2c015a952fc5d01d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React from 'react'
import styled from 'styled-components'
import {StaticQuery, graphql} from 'gatsby'
import {Flex} from 'rebass'
import {SidebarLink} from './links'
import Accordion from './Accordion'

const IS_STATIC = process.env.GATSBY_IS_STATIC

const LinkDesc = styled.span`
  font-size: 11px;
  line-height: 1.5;
  text-transform: lowercase;
  display: block;
  font-weight: 400;
  color: ${(props) => props.theme.colors.darkGray};
`

const DocLinks = ({data}) => {
  const linkInfo = data.allMarkdownRemark.nodes
  const sections = ['cli-commands', 'configuring-npm', 'using-npm']
  let sortedData = {}

  sections.map((section) => (
    sortedData[section] = linkInfo.filter(function (item) {
      return item.frontmatter.section === section
    })
  ))

  return sections.map((section, index) => (
    <Accordion key={index} section={section}>
      {sortedData[section].map((linkData, index) => {
        const title = section === 'cli-commands'
          ? linkData.frontmatter.title.replace(/(npm-)+([a-zA-Z\\.-]*)/, 'npm $2')
          : linkData.frontmatter.title

        return (
          <Flex flexDirection='column' key={index}>
            <SidebarLink
              to={`${linkData.fields.slug}${IS_STATIC ? '/index.html' : ''}`}
              activeClassName='active-sidebar-link'
            >
              {title}
              <LinkDesc>{linkData.frontmatter.description}</LinkDesc>
            </SidebarLink>
          </Flex>
        )
      })
      }
    </Accordion>
  ))
}

export default props => (
  <StaticQuery
    query={graphql`
      query sortedLinkData {
        allMarkdownRemark(sort: {fields: frontmatter___title}) {
          nodes {
            fields {
              slug
            }
            frontmatter {
              description
              section
              title
            }
          }
        }
      }
    `}
    render={data => <DocLinks data={data} {...props} />}
  />
)