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
5 changes: 4 additions & 1 deletion docs/src/components/ComponentReadme.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import kebabCase from '../utils/kebabCase'
import ComponentBlock from './ComponentBlock'
import AppearanceOption from './ApppearanceOption'
import PlaygroundExampleGroup from './PlaygroundExampleGroup'
Expand Down Expand Up @@ -41,7 +42,9 @@ export default class ComponentReadme extends PureComponent {
{subTitle}{' '}
<a
className="ComponentReadme-githubLink"
href={`https://github.com/segmentio/evergreen/tree/master/src/${name}`}
href={`https://github.com/segmentio/evergreen/tree/master/src/${kebabCase(
name
)}`}
target="_blank"
>
View on GitHub
Expand Down
25 changes: 25 additions & 0 deletions docs/src/utils/kebabCase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Credit to https://gist.github.com/tdukart/b87afb278c41245741ae7a0c355a0a0b
*
* @param {*} string
*/

export default function kebabCase(string) {
let result = string

// Convert camelCase capitals to kebab-case.
result = result.replace(/([a-z][A-Z])/g, match => {
return match.substr(0, 1) + '-' + match.substr(1, 1).toLowerCase()
})

// Convert non-camelCase capitals to lowercase.
result = result.toLowerCase()

// Convert non-alphanumeric characters to hyphens
result = result.replace(/[^-a-z0-9]+/g, '-')

// Remove hyphens from both ends
result = result.replace(/^-+/, '').replace(/-$/, '')

return result
}