diff --git a/package.json b/package.json index 5d50f414..d87b003d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index 9a9a2917..1a1c1c5c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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' @@ -19,3 +23,6 @@ export { default as convertEdgesToArticles, ArticleCardData, } from './utils/convertEdgesToArticles' +export { + default as extractSectionsFromArticleEdges, +} from './utils/extractSectionsFromArticleEdges' diff --git a/src/utils/extractSectionsFromArticleEdges/index.ts b/src/utils/extractSectionsFromArticleEdges/index.ts new file mode 100644 index 00000000..573cd9bf --- /dev/null +++ b/src/utils/extractSectionsFromArticleEdges/index.ts @@ -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))) +}