Adding HTML lang attribute and description metadata
This commit is contained in:
parent
325f01f034
commit
c7ea0659f4
@ -1,3 +1,5 @@
|
|||||||
|
const pkg = require('./package.json');
|
||||||
|
|
||||||
const buildId = [
|
const buildId = [
|
||||||
process.env.CI_COMMIT_REF_SLUG || 'prerelese',
|
process.env.CI_COMMIT_REF_SLUG || 'prerelese',
|
||||||
(process.env.CI_COMMIT_SHA || 'gitsha').slice(0, 7)
|
(process.env.CI_COMMIT_SHA || 'gitsha').slice(0, 7)
|
||||||
@ -8,6 +10,7 @@ const banner = process.env.BANNER || (process.env.NODE_ENV === 'production'
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
siteMetadata: {
|
siteMetadata: {
|
||||||
|
description: pkg.description,
|
||||||
buildId,
|
buildId,
|
||||||
banner,
|
banner,
|
||||||
defaultSyntax: 'js',
|
defaultSyntax: 'js',
|
||||||
|
@ -4,6 +4,11 @@ exports[`Metadata rendering 1`] = `
|
|||||||
<HelmetWrapper
|
<HelmetWrapper
|
||||||
defer={true}
|
defer={true}
|
||||||
encodeSpecialCharacters={true}
|
encodeSpecialCharacters={true}
|
||||||
|
htmlAttributes={
|
||||||
|
Object {
|
||||||
|
"lang": "test-lang",
|
||||||
|
}
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<title>
|
<title>
|
||||||
Regexper
|
Regexper
|
||||||
@ -11,13 +16,22 @@ exports[`Metadata rendering 1`] = `
|
|||||||
</HelmetWrapper>
|
</HelmetWrapper>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Metadata rendering with a title 1`] = `
|
exports[`Metadata rendering with a title and description 1`] = `
|
||||||
<HelmetWrapper
|
<HelmetWrapper
|
||||||
defer={true}
|
defer={true}
|
||||||
encodeSpecialCharacters={true}
|
encodeSpecialCharacters={true}
|
||||||
|
htmlAttributes={
|
||||||
|
Object {
|
||||||
|
"lang": "test-lang",
|
||||||
|
}
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<title>
|
<title>
|
||||||
Regexper - Testing
|
Regexper - Testing
|
||||||
</title>
|
</title>
|
||||||
|
<meta
|
||||||
|
content="Test description"
|
||||||
|
name="description"
|
||||||
|
/>
|
||||||
</HelmetWrapper>
|
</HelmetWrapper>
|
||||||
`;
|
`;
|
||||||
|
@ -1,15 +1,29 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import { withNamespaces } from 'react-i18next';
|
||||||
import { Helmet } from 'react-helmet';
|
import { Helmet } from 'react-helmet';
|
||||||
|
|
||||||
const Metadata = ({ title }) => (
|
class Metadata extends React.PureComponent {
|
||||||
<Helmet>
|
static propTypes = {
|
||||||
<title>{ title ? `Regexper - ${ title }` : 'Regexper' }</title>
|
title: PropTypes.string,
|
||||||
</Helmet>
|
description: PropTypes.string,
|
||||||
);
|
i18n: PropTypes.shape({
|
||||||
|
language: PropTypes.string.isRequired
|
||||||
|
}).isRequired
|
||||||
|
}
|
||||||
|
|
||||||
Metadata.propTypes = {
|
render() {
|
||||||
title: PropTypes.string
|
const { title, description, i18n } = this.props;
|
||||||
};
|
const htmlAttributes = {
|
||||||
|
lang: i18n.language
|
||||||
|
};
|
||||||
|
|
||||||
export default Metadata;
|
return <Helmet htmlAttributes={ htmlAttributes }>
|
||||||
|
<title>{ title ? `Regexper - ${ title }` : 'Regexper' }</title>
|
||||||
|
{ description && <meta name="description" content={ description } /> }
|
||||||
|
</Helmet>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Metadata };
|
||||||
|
export default withNamespaces()(Metadata);
|
||||||
|
@ -1,19 +1,26 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import Metadata from 'components/Metadata';
|
import { Metadata } from 'components/Metadata';
|
||||||
|
|
||||||
|
const commonProps = {
|
||||||
|
i18n: { language: 'test-lang' }
|
||||||
|
};
|
||||||
|
|
||||||
describe('Metadata', () => {
|
describe('Metadata', () => {
|
||||||
test('rendering', () => {
|
test('rendering', () => {
|
||||||
const component = shallow(
|
const component = shallow(
|
||||||
<Metadata />
|
<Metadata { ...commonProps } />
|
||||||
);
|
);
|
||||||
expect(component).toMatchSnapshot();
|
expect(component).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('rendering with a title', () => {
|
test('rendering with a title and description', () => {
|
||||||
const component = shallow(
|
const component = shallow(
|
||||||
<Metadata title="Testing" />
|
<Metadata
|
||||||
|
title="Testing"
|
||||||
|
description="Test description"
|
||||||
|
{ ...commonProps } />
|
||||||
);
|
);
|
||||||
expect(component).toMatchSnapshot();
|
expect(component).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
exports[`Error Page rendering 1`] = `
|
exports[`Error Page rendering 1`] = `
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<Metadata
|
<LoadNamespace(Metadata)
|
||||||
title="TRANSLATE(Page Not Found)"
|
title="TRANSLATE(Page Not Found)"
|
||||||
/>
|
/>
|
||||||
<Message
|
<Message
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
exports[`Index Page rendering 1`] = `
|
exports[`Index Page rendering 1`] = `
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<Metadata />
|
<LoadNamespace(Metadata)
|
||||||
|
description="Test description"
|
||||||
|
/>
|
||||||
<noscript>
|
<noscript>
|
||||||
<Message
|
<Message
|
||||||
heading="JavaScript Required"
|
heading="JavaScript Required"
|
||||||
@ -44,7 +46,9 @@ exports[`Index Page rendering 1`] = `
|
|||||||
|
|
||||||
exports[`Index Page rendering with an expression on the URL 1`] = `
|
exports[`Index Page rendering with an expression on the URL 1`] = `
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<Metadata />
|
<LoadNamespace(Metadata)
|
||||||
|
description="Test description"
|
||||||
|
/>
|
||||||
<noscript>
|
<noscript>
|
||||||
<Message
|
<Message
|
||||||
heading="JavaScript Required"
|
heading="JavaScript Required"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
exports[`Privacy Page rendering 1`] = `
|
exports[`Privacy Page rendering 1`] = `
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<Metadata
|
<LoadNamespace(Metadata)
|
||||||
title="TRANSLATE(Privacy Policy)"
|
title="TRANSLATE(Privacy Policy)"
|
||||||
/>
|
/>
|
||||||
<Message
|
<Message
|
||||||
|
@ -11,6 +11,7 @@ export const query = graphql`
|
|||||||
query IndexPageQuery {
|
query IndexPageQuery {
|
||||||
site {
|
site {
|
||||||
siteMetadata {
|
siteMetadata {
|
||||||
|
description
|
||||||
defaultSyntax
|
defaultSyntax
|
||||||
syntaxList { id, label }
|
syntaxList { id, label }
|
||||||
}
|
}
|
||||||
@ -43,7 +44,7 @@ export const IndexPage = ({
|
|||||||
location,
|
location,
|
||||||
data: { site: { siteMetadata } }
|
data: { site: { siteMetadata } }
|
||||||
}) => <>
|
}) => <>
|
||||||
<Metadata/>
|
<Metadata description={ siteMetadata.description } />
|
||||||
<noscript>
|
<noscript>
|
||||||
<Message type="error" heading="JavaScript Required">
|
<Message type="error" heading="JavaScript Required">
|
||||||
<p>You need JavaScript to use Regexper.</p>
|
<p>You need JavaScript to use Regexper.</p>
|
||||||
@ -61,6 +62,7 @@ IndexPage.propTypes = {
|
|||||||
data: PropTypes.shape({
|
data: PropTypes.shape({
|
||||||
site: PropTypes.shape({
|
site: PropTypes.shape({
|
||||||
siteMetadata: PropTypes.shape({
|
siteMetadata: PropTypes.shape({
|
||||||
|
description: PropTypes.string,
|
||||||
defaultSyntax: PropTypes.string,
|
defaultSyntax: PropTypes.string,
|
||||||
syntaxList: PropTypes.arrayOf(PropTypes.shape({
|
syntaxList: PropTypes.arrayOf(PropTypes.shape({
|
||||||
id: PropTypes.string,
|
id: PropTypes.string,
|
||||||
|
@ -6,6 +6,7 @@ import { IndexPage } from 'pages/index';
|
|||||||
const queryResult = {
|
const queryResult = {
|
||||||
site: {
|
site: {
|
||||||
siteMetadata: {
|
siteMetadata: {
|
||||||
|
description: 'Test description',
|
||||||
defaultSyntax: 'testJs',
|
defaultSyntax: 'testJs',
|
||||||
syntaxList: [
|
syntaxList: [
|
||||||
{ id: 'testJS', name: 'Testing JS' },
|
{ id: 'testJS', name: 'Testing JS' },
|
||||||
|
Loading…
Reference in New Issue
Block a user