This repository was archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-config.js
More file actions
143 lines (137 loc) · 3.98 KB
/
gatsby-config.js
File metadata and controls
143 lines (137 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
require('dotenv').config({
path: `.env.${process.env.NODE_ENV}`,
})
const {languages, defaultLanguage} = require('./languages');
const contentfulConfig = {
spaceId: process.env.CONTENTFUL_SPACE_ID,
accessToken:
process.env.CONTENTFUL_ACCESS_TOKEN ||
process.env.CONTENTFUL_DELIVERY_TOKEN,
}
// If you want to use the preview API please define
// CONTENTFUL_HOST and CONTENTFUL_PREVIEW_ACCESS_TOKEN in your
// environment config.
//
// CONTENTFUL_HOST should map to `preview.contentful.com`
// CONTENTFUL_PREVIEW_ACCESS_TOKEN should map to your
// Content Preview API token
//
// For more information around the Preview API check out the documentation at
// https://www.contentful.com/developers/docs/references/content-preview-api/#/reference/spaces/space/get-a-space/console/js
//
// To change back to the normal CDA, remove the CONTENTFUL_HOST variable from your environment.
if (process.env.CONTENTFUL_HOST) {
contentfulConfig.host = process.env.CONTENTFUL_HOST
contentfulConfig.accessToken = process.env.CONTENTFUL_PREVIEW_ACCESS_TOKEN
}
const { spaceId, accessToken } = contentfulConfig
if (!spaceId || !accessToken) {
throw new Error(
'Contentful spaceId and the access token need to be provided.'
)
}
module.exports = {
siteMetadata: {
siteUrl: `http://localhost:8000`,
title: 'Gatsby Contentful Starter',
description: 'Official Contentful Gatsby Starter',
author: `ritthikrai.w`,
},
pathPrefix: '/gatsby-contentful-starter',
plugins: [
'gatsby-transformer-remark',
'gatsby-transformer-sharp',
'gatsby-plugin-react-helmet',
'gatsby-plugin-sharp',
'gatsby-plugin-image',
{
resolve: 'gatsby-source-contentful',
options: contentfulConfig,
},
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/locales`,
name: `locale`,
},
},
{
resolve: `gatsby-plugin-react-i18next`,
options: {
languages,
defaultLanguage,
localeJsonSourceName: `locale`,
localeJsonNodeName: `locales`,
fallbackLanguage: `th`,
redirect: true,
siteUrl: `http://localhost:8000`,
i18nextOptions: {
lowerCaseLng: true,
saveMissing: false,
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
},
keySeparator: false,
nsSeparator: false,
},
pages: [
{
matchPath: '/preview',
languages: ['en'],
},
],
},
},
{
resolve: 'gatsby-plugin-sitemap',
options: {
excludes: ['/**/404', '/**/404.html'],
query: `
{
site {
siteMetadata {
siteUrl
}
}
allSitePage(filter: {context: {i18n: {routed: {eq: false}}}}) {
edges {
node {
context {
i18n {
defaultLanguage
languages
originalPath
}
}
path
}
}
}
}
`,
serialize: ({ site, allSitePage }) => {
return allSitePage.edges.map((edge) => {
const { languages, originalPath, defaultLanguage } =
edge.node.context.i18n
const { siteUrl } = site.siteMetadata
const url = siteUrl + originalPath
const links = [
{ lang: defaultLanguage, url },
{ lang: 'x-default', url },
]
languages.forEach((lang) => {
if (lang === defaultLanguage) return
links.push({ lang, url: `${siteUrl}/${lang}${originalPath}` })
})
return {
url,
changefreq: 'daily',
priority: originalPath === '/' ? 1.0 : 0.7,
links,
}
})
},
},
},
],
}