Skip to content

Commit 0c0b415

Browse files
committed
Better sorting of sidebar
1 parent 0420b2b commit 0c0b415

File tree

6 files changed

+236
-124
lines changed

6 files changed

+236
-124
lines changed

config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const config = {
22
gatsby: {
3-
pathPrefix: '/',
3+
pathPrefix: '/node-postgres-docs/',
44
siteUrl: 'https://learn.hasura.io',
55
gaTrackingId: null,
66
},

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"emotion": "^10.0.9",
1717
"emotion-server": "^10.0.9",
1818
"emotion-theming": "^10.0.10",
19-
"gatsby": "2.4.2",
19+
"gatsby": "2.13.23",
2020
"gatsby-link": "^2.1.1",
2121
"gatsby-mdx": "^0.6.2",
2222
"gatsby-plugin-emotion": "3.0.1",
@@ -46,10 +46,12 @@
4646
"main": "n/a",
4747
"scripts": {
4848
"start": "gatsby develop",
49-
"build": "gatsby build --prefix-paths"
49+
"build": "gatsby build --prefix-paths",
50+
"deploy": "yarn build && gh-pages -d public"
5051
},
5152
"devDependencies": {
5253
"gatsby-plugin-remove-trailing-slashes": "^2.0.11",
54+
"gh-pages": "2.0.1",
5355
"prism-react-renderer": "^0.1.6"
5456
},
5557
"prettier": {

src/components/Header.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ const Header = ({ location }) => (
5656
</Link>
5757
<div>
5858
<span className="sponsor">
59-
sponsored by <a className="sponsor-name">Timescale</a>
59+
sponsored by{' '}
60+
<a className="sponsor-name" href="https://www.timescale.com">
61+
Timescale
62+
</a>
6063
</span>
6164
</div>
6265
</div>

src/components/sidebar.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ExternalLink } from 'react-feather'
55
import Link from './link'
66
import './styles.css'
77
import config from '../../config'
8+
import { DH_NOT_SUITABLE_GENERATOR } from 'constants'
89

910
const forcedNavOrder = config.sidebar.forcedNavOrder
1011

@@ -15,7 +16,6 @@ const Sidebar = styled('aside')`
1516
height: 100vh;
1617
overflow: auto;
1718
position: fixed;
18-
padding-left: 24px;
1919
position: -webkit-sticky;
2020
position: -moz-sticky;
2121
position: sticky;
@@ -48,6 +48,14 @@ const Sidebar = styled('aside')`
4848
}
4949
`
5050

51+
const ListSection = styled('li')`
52+
color: white;
53+
padding-left: 1rem;
54+
font-weight: lighter;
55+
font-size: 14px;
56+
padding: 0.45rem 0 0.45rem 1rem;
57+
`
58+
5159
// eslint-disable-next-line no-unused-vars
5260
const ListItem = styled(({ className, active, level, ...props }) => {
5361
if (level === 0) {
@@ -153,13 +161,22 @@ const SidebarLayout = ({ location }) => (
153161
{ items: [] }
154162
)
155163

164+
const allFields = allMdx.edges.map(({ node }) => node.fields || {})
156165
const nav = forcedNavOrder
157166
.reduce((acc, cur) => {
158167
return acc.concat(navItems[cur])
159168
}, [])
160169
.concat(navItems.items)
161170
.map(slug => {
162171
const { node } = allMdx.edges.find(({ node }) => node.fields.slug === slug)
172+
const containingSlug = allFields.find(({ slug: otherSlug }) => {
173+
// is this slug contained within another one (e.g. is this a 'header' slug?)
174+
return slug !== '/' && slug !== otherSlug && otherSlug.indexOf(slug) === 0
175+
})
176+
if (containingSlug) {
177+
// nested path
178+
return <ListSection key={node.fields.slug}>{node.fields.title}</ListSection>
179+
}
163180

164181
let isActive = false
165182
if (

src/components/styles.css

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ pre {
177177

178178
.sideBarUL {
179179
margin-top: 32px;
180+
white-space: nowrap;
180181
}
181182

182183
.sideBarUL li {

0 commit comments

Comments
 (0)