Both slash stripper and internationalization plugins need to mash up so as to meet both common SEO and multilingual requirements. The ordering of the plugins in this case is important. If trailing slashes is first the browser URL is more correct but SEO is potentially dinged.
For best results, internationalization should follow stripper. Did not realize that the plugins were order sensitive in gatsby-config.js. As long as the URL has at least two levels, this is fairly close but may still have the trailing slash.
Steps to reproduce
Begin with the "my-blog-starter"
gatsby new my-blog-starter https://github.com/gatsbyjs/gatsby-starter-blog
cd my-blog-starter
Install the "gatsby-plugin-remote-trailing-slashes"
Update the main project's blog-post.js file as follows to include international text:
import React from "react"
// TKTKTK
// import { Link, graphql } from "gatsby"
import { graphql } from "gatsby"
import { FormattedMessage, Link, injectIntl } from "gatsby-plugin-intl"
import Bio from "../components/bio"
import Layout from "../components/layout"
import SEO from "../components/seo"
import { rhythm, scale } from "../utils/typography"
class BlogPostTemplate extends React.Component {
render() {
const post = this.props.data.markdownRemark
const siteTitle = this.props.data.site.siteMetadata.title
const { previous, next } = this.props.pageContext
export const pageQuery = graphql query BlogPostBySlug($slug: String!) { site { siteMetadata { title author } } markdownRemark(fields: { slug: { eq: $slug } }) { id excerpt(pruneLength: 160) html frontmatter { title date(formatString: "MMMM DD, YYYY") description } } }
7. From the main project directory, execute the following command to start Gatsby:
clear && rm -rf .cache public && gatsby develop
### Expected and Actual result
When order in gatsby-config.js:
1. gatsby-plugin-intl
2. gatsby-plugin-remove-trailing-slashes
http://localhost ==>
http://localhost/en/ ==>
Actual: http://localhost/en/en/ with English text
Expected: http://localhost/en with English text
http://localhost/ ==>
http://localhost/en/ ==>
Actual: http://localhost/en/en/ with English text
Expected: http://localhost/en with English text
http://localhost/de ==>
Actual: http://localhost/en/de with English text
Expected: http://localhost/de with German text
http://localhost/de/ ==>
Actual: http://localhost/en/de/ with English text
Expected: http://localhost/de with German text
http://localhost/my-second-post ==>
Actual: http://localhost/en/en/my-second-post with English text
Expected: http://localhost/en/my-second-post English text
http://localhost/my-second-post/ ==>
Actual: http://localhost/en/en/my-second-post/ with English text
Expected: http://localhost/en/my-second-post with English text
http://localhost/de/my-second-post ==>
Actual: http://localhost/en/de/my-second-post with English text
Expected: http://localhost/de/my-second-post with German text
http://localhost/de/my-second-post/ ==>
Actual: http://localhost/en/de/my-second-post/ with English text
Expected: http://localhost/de/my-second-post with German text
When order in gatsby-config.js:
1. gatsby-plugin-remove-trailing-slashes
2. gatsby-plugin-intl
http://localhost ==>
http://localhost/en/ ==>
Actual: http://localhost/en/en/ with English text
Expected: http://localhost/en with English text
http://localhost/ ==>
http://localhost/en/ ==>
Actual: http://localhost/en/en/ with English text
Expected: http://localhost/en with English text
http://localhost/de ==>
Actual: http://localhost/en/de with English text
Expected: http://localhost/de with German text
http://localhost/de/ ==>
Actual: http://localhost/en/de/ with English text
Expected: http://localhost/de with German text
http://localhost/my-second-post ==>
Actual: http://localhost/en/my-second-post with English text
Expected: Successful URL with English text
http://localhost/my-second-post/ ==>
Actual: http://localhost/en/my-second-post/ with English text
Expected: http://localhost/en/my-second-post with English text
http://localhost/de/my-second-post ==>
Actual: http://localhost/de/my-second-post with German text
Expected: Successful URL with German text
http://localhost/de/my-second-post/ ==>
Actual: http://localhost/de/my-second-post/ with German text
Expected: http://localhost/de/my-second-post with German text
Only gatsby-plugin-intl enabled in gatsby-config.js:
http://localhost ==>
Actual: http://localhost/en/ with English text
Expected: Successful URL with English text
http://localhost/ ==>
Actual: http://localhost/en/ with English text
Expected: Successful URL with English text
http://localhost/de ==>
Actual: http://localhost/de with German text
Expected: Successful URL with German text
http://localhost/de/ ==>
Actual: http://localhost/de/ with German text
Expected: Successful URL with German text
http://localhost/my-second-post ==>
Actual: http://localhost/en/my-second-post with English text
Expected: Successful URL with English text
http://localhost/my-second-post/ ==>
Actual: http://localhost/en/my-second-post/ with English text
Expected: Successful URL with English text
http://localhost/de/my-second-post ==>
Actual: http://localhost/de/my-second-post with German text
Expected: Successful URL with German text
http://localhost/de/my-second-post/ ==>
Actual: http://localhost/de/my-second-post/ with German text
Expected: Successful URL with German text
### Errata
Maybe these two plugins would benefit from being combined together. The addition of the stripping slashes feature into international would seem pretty straight forward and might result in better performance.
~~Tomorrow, I plan to run the tests with just international. I will update with my findings.~~ Updated.
### Environment
System:
OS: macOS 10.14.5
CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
Shell: 5.0.2 - /usr/local/bin/bash
Binaries:
Node: 10.15.2 - /usr/local/bin/node
Yarn: 1.15.2 - ~/.yarn/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
Languages:
Python: 2.7.10 - /usr/bin/python
Browsers:
Chrome: 74.0.3729.169
Safari: 12.1.1
npmPackages:
gatsby: ^2.7.5 => 2.7.5
gatsby-image: ^2.1.2 => 2.1.2
gatsby-plugin-feed: ^2.2.1 => 2.2.1
gatsby-plugin-google-analytics: ^2.0.20 => 2.0.20
gatsby-plugin-intl: ^0.1.7 => 0.1.7
gatsby-plugin-manifest: ^2.1.1 => 2.1.1
gatsby-plugin-offline: ^2.1.1 => 2.1.1
gatsby-plugin-react-helmet: ^3.0.12 => 3.0.12
gatsby-plugin-remove-trailing-slashes: ^2.0.11 => 2.0.11
gatsby-plugin-sharp: ^2.1.2 => 2.1.2
gatsby-plugin-typography: ^2.2.13 => 2.2.13
gatsby-remark-copy-linked-files: ^2.0.13 => 2.0.13
gatsby-remark-images: ^3.0.14 => 3.0.14
gatsby-remark-prismjs: ^3.2.9 => 3.2.9
gatsby-remark-responsive-iframe: ^2.1.1 => 2.1.1
gatsby-remark-smartypants: ^2.0.9 => 2.0.9
gatsby-source-filesystem: ^2.0.37 => 2.0.37
gatsby-transformer-remark: ^2.3.12 => 2.3.12
gatsby-transformer-sharp: ^2.1.20 => 2.1.20
npmGlobalPackages:
gatsby-cli: 2.6.3
AdvThanksance!!!
Description
Both slash stripper and internationalization plugins need to mash up so as to meet both common SEO and multilingual requirements. The ordering of the plugins in this case is important. If trailing slashes is first the browser URL is more correct but SEO is potentially dinged.
For best results, internationalization should follow stripper. Did not realize that the plugins were order sensitive in gatsby-config.js. As long as the URL has at least two levels, this is fairly close but may still have the trailing slash.
Steps to reproduce
import Bio from "../components/bio" import Layout from "../components/layout" import SEO from "../components/seo" import { rhythm, scale } from "../utils/typography"
class BlogPostTemplate extends React.Component { render() { const post = this.props.data.markdownRemark const siteTitle = this.props.data.site.siteMetadata.title const { previous, next } = this.props.pageContext
} }
// TKTKTK // export default BlogPostTemplate export default injectIntl(BlogPostTemplate)
export const pageQuery = graphql
query BlogPostBySlug($slug: String!) { site { siteMetadata { title author } } markdownRemark(fields: { slug: { eq: $slug } }) { id excerpt(pruneLength: 160) html frontmatter { title date(formatString: "MMMM DD, YYYY") description } } }
clear && rm -rf .cache public && gatsby develop