Skip to content

Commit f3f827b

Browse files
authored
Merge pull request microapps#167
attempt to fix sitemap error
2 parents c7230ad + 37a0d18 commit f3f827b

File tree

6 files changed

+17579
-17142
lines changed

6 files changed

+17579
-17142
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,6 @@ dist/
7474

7575
**/.yalc
7676
**/yalc.lock
77+
78+
# Package-lock.json
79+
**/*/package-lock.json

example/gatsby-config.js

+31-35
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const {languages, defaultLanguage} = require('./languages');
2+
const siteUrl = process.env.URL || `https://fallback.net`;
23

34
module.exports = {
45
siteMetadata: {
@@ -67,48 +68,43 @@ module.exports = {
6768
options: {
6869
excludes: ['/**/404', '/**/404.html'],
6970
query: `
70-
{
71-
site {
72-
siteMetadata {
73-
siteUrl
74-
}
71+
{
72+
site {
73+
siteMetadata {
74+
siteUrl
7575
}
76-
allSitePage(filter: {context: {i18n: {routed: {eq: false}}}}) {
77-
edges {
78-
node {
79-
context {
80-
i18n {
81-
defaultLanguage
82-
languages
83-
originalPath
84-
}
85-
}
86-
path
76+
}
77+
allSitePage(filter: {context: {i18n: {routed: {eq: false}}}}) {
78+
nodes {
79+
context {
80+
i18n {
81+
defaultLanguage
82+
languages
83+
originalPath
8784
}
8885
}
86+
path
8987
}
9088
}
89+
}
9190
`,
92-
serialize: ({site, allSitePage}) => {
93-
return allSitePage.edges.map((edge) => {
94-
const {languages, originalPath, defaultLanguage} = edge.node.context.i18n;
95-
const {siteUrl} = site.siteMetadata;
96-
const url = siteUrl + originalPath;
97-
const links = [
98-
{lang: defaultLanguage, url},
99-
{lang: 'x-default', url}
100-
];
101-
languages.forEach((lang) => {
102-
if (lang === defaultLanguage) return;
103-
links.push({lang, url: `${siteUrl}/${lang}${originalPath}`});
104-
});
105-
return {
106-
url,
107-
changefreq: 'daily',
108-
priority: originalPath === '/' ? 1.0 : 0.7,
109-
links
110-
};
91+
serialize: (node) => {
92+
const {languages, originalPath, defaultLanguage} = node.context.i18n;
93+
const url = siteUrl + originalPath;
94+
const links = [
95+
{lang: defaultLanguage, url},
96+
{lang: 'x-default', url}
97+
];
98+
languages.forEach((lang) => {
99+
if (lang === defaultLanguage) return;
100+
links.push({lang, url: `${siteUrl}/${lang}${originalPath}`});
111101
});
102+
return {
103+
url,
104+
changefreq: 'daily',
105+
priority: originalPath === '/' ? 1.0 : 0.7,
106+
links
107+
};
112108
}
113109
}
114110
}

example/gatsby-node.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Workaround for missing sitePage.context:
3+
* Used for generating sitemap with `gatsby-plugin-react-i18next` and `gatsby-plugin-sitemap` plugins
4+
* https://www.gatsbyjs.com/docs/reference/release-notes/migrating-from-v3-to-v4/#field-sitepagecontext-is-no-longer-available-in-graphql-queries
5+
*/
6+
exports.createSchemaCustomization = ({actions}) => {
7+
const {createTypes} = actions;
8+
createTypes(`
9+
type SitePage implements Node {
10+
context: SitePageContext
11+
}
12+
type SitePageContext {
13+
i18n: i18nContext
14+
}
15+
type i18nContext {
16+
language: String,
17+
languages: [String],
18+
defaultLanguage: String,
19+
originalPath: String
20+
routed: Boolean
21+
}
22+
`);
23+
};

0 commit comments

Comments
 (0)