Skip to content

Commit

Permalink
Merge pull request #522 from newrelic/jerel/related-resources
Browse files Browse the repository at this point in the history
Related resources
  • Loading branch information
zstix authored Aug 3, 2020
2 parents 579a500 + 15e26a6 commit 9fe095f
Show file tree
Hide file tree
Showing 15 changed files with 301 additions and 100 deletions.
9 changes: 9 additions & 0 deletions STYLE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ The value that is assigned to the key slug is used in order to navigate to your
- `redirects`:
- url you wish to redirect from
- another url you wish to redirect from
- `resources`:
- `title`: title of related resource. This resource will show up in the "Resources" section to the right of the main content.
- `url`: URL of related resource. Can be absolute or relative.

### GuideTemplate Frontmatter example

Expand All @@ -306,6 +309,12 @@ tileShorthand:
redirects:
- /build-tools/new-relic-one-applications/intro-to-sdk
- /client-side-sdk/index.html
resources:
- title: Introduction to New Relic NerdGraph
url: https://docs.newrelic.com/docs/apis/nerdgraph/get-started/introduction-new-relic-nerdgraph

- title: Deploy an app
url: /build-apps/publish-deploy
---
```

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@emotion/styled": "^10.0.27",
"@mdx-js/mdx": "^1.6.6",
"@mdx-js/react": "^1.6.6",
"@newrelic/gatsby-theme-newrelic": "^1.2.4",
"@newrelic/gatsby-theme-newrelic": "^1.4.0",
"classnames": "^2.2.6",
"date-fns": "^2.14.0",
"eslint-plugin-react-hooks": "^4.0.6",
Expand Down
2 changes: 1 addition & 1 deletion src/components/PageLayout/PageLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const LAYOUTS = {
grid-template-areas:
'page-header page-header'
'content related-content';
grid-template-columns: minmax(0, 1fr) auto;
grid-template-columns: minmax(0, 1fr) 300px;
grid-gap: 2rem;
@media (max-width: 1240px) {
Expand Down
88 changes: 7 additions & 81 deletions src/components/PageLayout/RelatedContent.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import { css } from '@emotion/core';
import { graphql, useStaticQuery } from 'gatsby';
import { Button, ExternalLink, Icon } from '@newrelic/gatsby-theme-newrelic';
import usePageContext from '../../hooks/usePageContext';

const RelatedContent = ({ page }) => {
const { site } = useStaticQuery(graphql`
query {
site {
siteMetadata {
repository
}
}
}
`);
const { fileRelativePath } = usePageContext();

const {
fields: { gitAuthorTime },
} = page;

const {
siteMetadata: { repository },
} = site;
const RelatedContent = ({ page, modules }) => {
const pageContext = usePageContext();

return (
<aside
Expand All @@ -38,71 +19,16 @@ const RelatedContent = ({ page }) => {
border-radius: 0.25rem;
`}
>
<h4>Contribute</h4>
<Button
as={ExternalLink}
href={`${repository}/issues/new/choose`}
css={css`
margin-right: 0.5rem;
`}
variant={Button.VARIANT.PRIMARY}
size={Button.SIZE.SMALL}
>
<Icon
name={Icon.TYPE.GITHUB}
css={css`
margin-right: 0.5rem;
`}
/>
File an issue
</Button>
<Button
as={ExternalLink}
href={`${repository}/tree/main/${fileRelativePath}`}
variant={Button.VARIANT.NORMAL}
size={Button.SIZE.SMALL}
>
<Icon
name={Icon.TYPE.EDIT}
css={css`
margin-right: 0.5rem;
`}
/>
Edit this page
</Button>

<div
css={css`
font-size: 0.875rem;
font-style: italic;
margin-top: 1rem;
color: var(--color-neutrals-500);
.dark-mode & {
color: var(--color-dark-500);
}
`}
>
{`Page last modified on ${gitAuthorTime}`}
</div>
{modules.map((Module, idx) => (
<Module key={idx} page={page} pageContext={pageContext} />
))}
</aside>
);
};

RelatedContent.propTypes = {
page: PropTypes.shape({
fields: PropTypes.shape({
gitAuthorTime: PropTypes.string,
}),
}),
modules: PropTypes.arrayOf(PropTypes.elementType).isRequired,
page: PropTypes.object.isRequired,
};

export const query = graphql`
fragment RelatedContent_page on Mdx {
fields {
gitAuthorTime(formatString: "MMMM DD, YYYY")
}
}
`;

export default RelatedContent;
70 changes: 70 additions & 0 deletions src/components/RelatedContentModules/Contribute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React from 'react';
import PropTypes from 'prop-types';
import { css } from '@emotion/core';
import { Button, ExternalLink, Icon } from '@newrelic/gatsby-theme-newrelic';
import { graphql, useStaticQuery } from 'gatsby';
import Section from './Section';
import Title from './Title';

const Contribute = ({ pageContext }) => {
const { site } = useStaticQuery(graphql`
query {
site {
siteMetadata {
repository
}
}
}
`);

const { fileRelativePath } = pageContext;

const {
siteMetadata: { repository },
} = site;

return (
<Section>
<Title>Contribute</Title>
<Button
as={ExternalLink}
href={`${repository}/issues/new/choose`}
css={css`
margin-right: 0.5rem;
`}
variant={Button.VARIANT.PRIMARY}
size={Button.SIZE.SMALL}
>
<Icon
name={Icon.TYPE.GITHUB}
css={css`
margin-right: 0.5rem;
`}
/>
File an issue
</Button>
<Button
as={ExternalLink}
href={`${repository}/tree/main/${fileRelativePath}`}
variant={Button.VARIANT.NORMAL}
size={Button.SIZE.SMALL}
>
<Icon
name={Icon.TYPE.EDIT}
css={css`
margin-right: 0.5rem;
`}
/>
Edit this page
</Button>
</Section>
);
};

Contribute.propTypes = {
pageContext: PropTypes.shape({
fileRelativePath: PropTypes.string,
}),
};

export default Contribute;
45 changes: 45 additions & 0 deletions src/components/RelatedContentModules/PageUpdated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import PropTypes from 'prop-types';
import { css } from '@emotion/core';
import { graphql } from 'gatsby';
import Section from './Section';

const PageUpdated = ({ page }) => {
const {
fields: { gitAuthorTime },
} = page;

return (
<Section
css={css`
font-size: 0.875rem;
font-style: italic;
color: var(--color-neutrals-500);
.dark-mode & {
color: var(--color-dark-500);
}
`}
>
{`Page last modified on ${gitAuthorTime}`}
</Section>
);
};

PageUpdated.propTypes = {
page: PropTypes.shape({
fields: PropTypes.shape({
gitAuthorTime: PropTypes.string,
}),
}),
};

export const query = graphql`
fragment PageUpdated_page on Mdx {
fields {
gitAuthorTime(formatString: "MMMM DD, YYYY")
}
}
`;

export default PageUpdated;
116 changes: 116 additions & 0 deletions src/components/RelatedContentModules/Resources.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import React from 'react';
import PropTypes from 'prop-types';
import { css } from '@emotion/core';
import { graphql, Link } from 'gatsby';
import { ExternalLink, Icon, Tag } from '@newrelic/gatsby-theme-newrelic';
import Section from './Section';
import Title from './Title';

const SITE_TAGS = {
developer: 'https://developer.newrelic.com',
'open source': 'https://opensource.newrelic.com',
docs: 'https://docs.newrelic.com',
};

const findTag = (resource) =>
resource.url.startsWith('/')
? 'developer'
: Object.keys(SITE_TAGS).find((tag) =>
resource.url.startsWith(SITE_TAGS[tag])
);

const normalizeDeveloperUrl = (url) =>
url.replace('https://developer.newrelic.com', '');

const Resources = ({ page }) => {
const {
frontmatter: { resources },
} = page;

return resources?.length > 0 ? (
<Section>
<Title>Resources</Title>
<nav>
<ul
css={css`
list-style: none;
margin: 0;
padding: 0;
`}
>
{resources.map((resource) => {
const tag = findTag(resource);
const isDeveloperSite = tag === 'developer';
const LinkElement = isDeveloperSite ? Link : ExternalLink;
const props = isDeveloperSite
? { to: normalizeDeveloperUrl(resource.url) }
: { href: resource.url };

return (
<li
key={resource.url}
css={css`
margin-bottom: 1rem;
`}
>
<LinkElement
{...props}
css={css`
display: block;
margin-bottom: 0.25rem;
`}
>
<span
css={css`
vertical-align: middle;
`}
>
{resource.title}
</span>

{!isDeveloperSite && (
<Icon
name={Icon.TYPE.EXTERNAL_LINK}
css={css`
margin-left: 0.25rem;
vertical-align: middle;
`}
/>
)}
</LinkElement>

<Tag>{tag}</Tag>
</li>
);
})}
</ul>
</nav>
</Section>
) : null;
};

Resources.propTypes = {
page: PropTypes.shape({
frontmatter: PropTypes.shape({
resources: PropTypes.arrayOf(
PropTypes.shape({
title: PropTypes.string,
url: PropTypes.string,
})
),
}).isRequired,
}).isRequired,
};

export const query = graphql`
fragment Resources_page on Mdx {
frontmatter {
resources {
title
url
}
}
}
`;

export default Resources;
Loading

0 comments on commit 9fe095f

Please sign in to comment.