Browse Source

Merge pull request #688 from raunofreiberg/fix/footer-nav-links-title

fix: NavigationFooter links pull paginated title from nav metadata
main
Alex Krolick 7 years ago
committed by GitHub
parent
commit
8006e2dc8e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      src/components/MarkdownPage/MarkdownPage.js
  2. 21
      src/templates/components/NavigationFooter/NavigationFooter.js

24
src/components/MarkdownPage/MarkdownPage.js

@ -31,6 +31,18 @@ type Props = {
titlePostfix: string, titlePostfix: string,
}; };
const getPageById = (sectionList: Array<Object>, templateFile: ?string) => {
if (!templateFile) {
return null;
}
const sectionItems = sectionList.map(section => section.items);
const flattenedSectionItems = [].concat.apply([], sectionItems);
const linkId = templateFile.replace('.html', '');
return flattenedSectionItems.find(item => item.id === linkId);
};
const MarkdownPage = ({ const MarkdownPage = ({
authors = [], authors = [],
createLink, createLink,
@ -45,6 +57,9 @@ const MarkdownPage = ({
const hasAuthors = authors.length > 0; const hasAuthors = authors.length > 0;
const titlePrefix = markdownRemark.frontmatter.title || ''; const titlePrefix = markdownRemark.frontmatter.title || '';
const prev = getPageById(sectionList, markdownRemark.frontmatter.prev);
const next = getPageById(sectionList, markdownRemark.frontmatter.next);
return ( return (
<Flex <Flex
direction="column" direction="column"
@ -123,13 +138,8 @@ const MarkdownPage = ({
</Container> </Container>
</div> </div>
{/* TODO Read prev/next from index map, not this way */} {(next || prev) && (
{(markdownRemark.frontmatter.next || markdownRemark.frontmatter.prev) && ( <NavigationFooter location={location} next={next} prev={prev} />
<NavigationFooter
location={location}
next={markdownRemark.frontmatter.next}
prev={markdownRemark.frontmatter.prev}
/>
)} )}
</Flex> </Flex>
); );

21
src/templates/components/NavigationFooter/NavigationFooter.js

@ -45,8 +45,8 @@ const NavigationFooter = ({next, prev, location}) => {
css={{ css={{
paddingTop: 10, paddingTop: 10,
}}> }}>
<PrimaryLink location={location} to={prev}> <PrimaryLink location={location} to={`${prev.id}.html`}>
{linkToTitle(prev)} {prev.title}
</PrimaryLink> </PrimaryLink>
</div> </div>
</div> </div>
@ -66,8 +66,8 @@ const NavigationFooter = ({next, prev, location}) => {
css={{ css={{
paddingTop: 10, paddingTop: 10,
}}> }}>
<PrimaryLink location={location} to={next}> <PrimaryLink location={location} to={`${next.id}.html`}>
{linkToTitle(next)} {next.title}
</PrimaryLink> </PrimaryLink>
</div> </div>
</div> </div>
@ -80,14 +80,18 @@ const NavigationFooter = ({next, prev, location}) => {
}; };
NavigationFooter.propTypes = { NavigationFooter.propTypes = {
next: PropTypes.string, next: PropTypes.shape({
prev: PropTypes.string, id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
}),
prev: PropTypes.shape({
id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
}),
}; };
export default NavigationFooter; export default NavigationFooter;
const linkToTitle = link => link.replace(/-/g, ' ').replace('.html', '');
const PrimaryLink = ({children, to, location}) => { const PrimaryLink = ({children, to, location}) => {
// quick fix // quick fix
// TODO: replace this with better method of getting correct full url // TODO: replace this with better method of getting correct full url
@ -97,7 +101,6 @@ const PrimaryLink = ({children, to, location}) => {
<Link <Link
css={{ css={{
display: 'inline', display: 'inline',
textTransform: 'capitalize',
borderColor: colors.subtle, borderColor: colors.subtle,
transition: 'border-color 0.2s ease', transition: 'border-color 0.2s ease',
fontSize: 30, fontSize: 30,

Loading…
Cancel
Save