Skip to content

Commit

Permalink
feat: add extractSectionsFromArticleEdges to lux (#117)
Browse files Browse the repository at this point in the history
* defaultProps public

* stuff
  • Loading branch information
nathanmsmith authored Nov 19, 2018
1 parent 2157259 commit 9f3cd28
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"emotion": "^9.2.12",
"emotion-server": "^9.2.12",
"gatsby-plugin-emotion": "^2.0.5",
"lodash.uniq": "^4.5.0",
"plyr": "^3.4.4",
"react": "16.5.2",
"react-dom": "16.5.2",
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
export { default as ArticleGrid } from './components/ArticleGrid'
export { default as Article } from './components/Article'
export { default as Byline } from './components/Byline'
export { default as CoverPhoto } from './components/CoverPhoto'
export {
default as CoverPhoto,
XPosition,
YPosition,
} from './components/CoverPhoto'
export { default as Footer } from './components/Footer'
export { default as Head } from './components/Head'
export { default as Headline } from './components/Headline'
Expand All @@ -19,3 +23,6 @@ export {
default as convertEdgesToArticles,
ArticleCardData,
} from './utils/convertEdgesToArticles'
export {
default as extractSectionsFromArticleEdges,
} from './utils/extractSectionsFromArticleEdges'
28 changes: 28 additions & 0 deletions src/utils/extractSectionsFromArticleEdges/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as uniq from 'lodash.uniq'

/**
* A function that takes in a string and capitalizes the first letter of each word.
* @author Dustin Newman
* @export
* @param {string} The string.
* @returns {string} A capitalized string.
*/
function capitalizeSection(section: string): string {
if (section.length === 0) {
return ''
}

if (section === 'prime') {
return 'prime'
}

return section
.toLowerCase()
.split(' ')
.map(word => word.charAt(0).toUpperCase() + word.substring(1))
.join(' ')
}

export default function extractSectionsFromArticleEdges(edges: any): string[] {
return uniq(edges.map(edge => capitalizeSection(edge.node.section)))
}

0 comments on commit 9f3cd28

Please sign in to comment.