forked from jk715/docs.hackerone.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle.js
More file actions
103 lines (86 loc) · 2.61 KB
/
Copy patharticle.js
File metadata and controls
103 lines (86 loc) · 2.61 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import React from 'react'
import Helmet from 'react-helmet'
import { Link, withPrefix } from 'gatsby-link'
import GatsbyConfig from '../../../gatsby-config'
import Sidebar from '../../components/sidebar/sidebar'
import ArticleSelect from '../../components/article_select/article_select'
import './article.scss'
const findActiveSectionByPath = (pathname, sections) => {
let match
let activeSection
sections.forEach(section => {
const match = section.items.some(
item =>
pathname === withPrefix(item.path) ||
(item.items &&
item.items.some(subitem => pathname === withPrefix(subitem.path)))
)
if (match) {
activeSection = section
}
})
return activeSection
}
const findActiveChildByPath = (pathname, sections) => {
let match
let activeChild
sections.forEach(section => {
section.items.some(item => {
if (item.items) {
match =
item.items.some(subitem => {
return pathname === withPrefix(subitem.path)
}) || pathname === withPrefix(item.path)
if (match) {
activeChild = item.items
}
}
})
})
return activeChild
}
class IndexRoute extends React.Component {
render() {
const { links, path, title, children, description } = this.props
const githubRepo =
'https://github.com/Hacker0x01/docs.hackerone.com/blob/master/docs/'
const globalWindow =
typeof window !== 'undefined'
? window.location.pathname
: withPrefix(path)
return (
<div className="article">
<Helmet
title={`${title} | ${GatsbyConfig.siteMetadata.title}`}
meta={[
description ? {
name: 'description',
content: description
} : {}
]}
/>
<Sidebar
activeSection={findActiveSectionByPath(globalWindow, links)}
activeChild={findActiveChildByPath(globalWindow, links)}
links={links}
/>
<article className="article__inner">
<ArticleSelect links={links} currentPath={globalWindow} />
{this.props.children}
{this.props.docOnGithub ? (
<div className="footer__inner">
<a href={githubRepo + this.props.docOnGithub} className="pull-left">
Edit this page on GitHub
</a>
<a href="https://www.hackerone.com" target="_blank" className="pull-right">
Back to HackerOne
</a>
<div className="clearfix" />
</div>
) : null}
</article>
</div>
)
}
}
export default IndexRoute