Skip to content

Commit 2bbcb08

Browse files
committed
update example
Signed-off-by: Dmitriy Nevzorov <jimmy.lugat@gmail.com>
1 parent a6dd48d commit 2bbcb08

File tree

4 files changed

+1057
-1489
lines changed

4 files changed

+1057
-1489
lines changed

example/gatsby-config.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
title: `Gatsby Default Starter`,
66
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
77
author: `@gatsbyjs`,
8-
pathPrefix: `/blog`
8+
siteUrl: 'https://5ecd0801489011000849a7db--kind-lichterman-5edcb4.netlify.app'
99
},
1010
plugins: [
1111
`gatsby-plugin-react-helmet`,
@@ -49,6 +49,56 @@ module.exports = {
4949
nsSeparator: false
5050
}
5151
}
52+
},
53+
{
54+
resolve: 'gatsby-plugin-sitemap',
55+
options: {
56+
exclude: ['/**/404', '/**/404.html'],
57+
query: `
58+
{
59+
site {
60+
siteMetadata {
61+
siteUrl
62+
}
63+
}
64+
allSitePage(filter: {context: {i18n: {routed: {eq: false}}}}) {
65+
edges {
66+
node {
67+
context {
68+
i18n {
69+
defaultLanguage
70+
languages
71+
originalPath
72+
}
73+
}
74+
path
75+
}
76+
}
77+
}
78+
}
79+
`,
80+
serialize: ({site, allSitePage}) => {
81+
return allSitePage.edges.map((edge) => {
82+
const {languages, originalPath, defaultLanguage} = edge.node.context.i18n;
83+
const {siteUrl} = site.siteMetadata;
84+
const url = siteUrl + originalPath;
85+
const links = [
86+
{lang: defaultLanguage, url},
87+
{lang: 'x-default', url}
88+
];
89+
languages.forEach((lang) => {
90+
if (lang === defaultLanguage) return;
91+
links.push({lang, url: `${siteUrl}/${lang}${originalPath}`});
92+
});
93+
return {
94+
url,
95+
changefreq: 'daily',
96+
priority: originalPath === '/' ? 1.0 : 0.7,
97+
links
98+
};
99+
});
100+
}
101+
}
52102
}
53103
// this (optional) plugin enables Progressive Web App + Offline functionality
54104
// To learn more, visit: https://gatsby.dev/offline

example/package.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@
55
"version": "0.1.0",
66
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
77
"dependencies": {
8-
"gatsby": "^2.23.0",
9-
"gatsby-image": "^2.4.6",
10-
"gatsby-plugin-manifest": "^2.4.10",
11-
"gatsby-plugin-offline": "^3.2.8",
12-
"gatsby-plugin-react-helmet": "^3.3.3",
13-
"gatsby-plugin-react-i18next": "^0.0.15",
14-
"gatsby-plugin-sharp": "^2.6.10",
15-
"gatsby-source-filesystem": "^2.3.10",
16-
"gatsby-transformer-sharp": "^2.5.4",
17-
"i18next": "^19.4.5",
8+
"gatsby": "^2.23.11",
9+
"gatsby-image": "^2.4.9",
10+
"gatsby-plugin-manifest": "^2.4.14",
11+
"gatsby-plugin-offline": "^3.2.13",
12+
"gatsby-plugin-react-helmet": "^3.3.6",
13+
"gatsby-plugin-react-i18next": "^0.0.22",
14+
"gatsby-plugin-sharp": "^2.6.14",
15+
"gatsby-plugin-sitemap": "^2.4.7",
16+
"gatsby-source-filesystem": "^2.3.14",
17+
"gatsby-transformer-sharp": "^2.5.7",
18+
"i18next": "^19.5.1",
1819
"prop-types": "^15.7.2",
1920
"react": "^16.12.0",
2021
"react-dom": "^16.12.0",
21-
"react-helmet": "^6.0.0",
22-
"react-i18next": "^11.5.0"
22+
"react-helmet": "^6.1.0",
23+
"react-i18next": "^11.7.0"
2324
},
2425
"devDependencies": {
25-
"@babel/cli": "^7.10.1",
26-
"@babel/core": "^7.10.2",
27-
"aws-sdk": "^2.689.0",
26+
"@babel/cli": "^7.10.3",
27+
"@babel/core": "^7.10.3",
28+
"aws-sdk": "^2.705.0",
2829
"babel-plugin-i18next-extract": "^0.7.2",
2930
"mkdirp": "^1.0.4",
3031
"prettier": "2.0.5"

example/src/components/header.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import './header.css';
44
import React from 'react';
55

66
const Header = ({siteTitle}) => {
7-
const {languages, changeLanguage} = useI18next();
7+
const {languages, originalPath} = useI18next();
88
return (
99
<header className="main-header">
1010
<h1 style={{margin: 0}}>
@@ -20,14 +20,9 @@ const Header = ({siteTitle}) => {
2020
<ul className="languages">
2121
{languages.map((lng) => (
2222
<li key={lng}>
23-
<a
24-
href="#"
25-
onClick={(e) => {
26-
e.preventDefault();
27-
changeLanguage(lng);
28-
}}>
23+
<Link to={originalPath} language={lng}>
2924
{lng}
30-
</a>
25+
</Link>
3126
</li>
3227
))}
3328
</ul>

0 commit comments

Comments
 (0)