-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
85 lines (78 loc) · 3 KB
/
next.config.js
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
/* eslint-env node */
/* eslint-disable @typescript-eslint/no-var-requires */
const withTM = require("next-transpile-modules")(["@bloom-housing"])
const withSass = require("@zeit/next-sass")
const withMDX = require("@next/mdx")()
const axios = require("axios")
if (process.env.NODE_ENV !== "production") {
require("dotenv").config()
}
const LISTING_SERVICE_URL = process.env.LISTING_SERVICE_URL || "http://localhost:3001"
const MAPBOX_TOKEN =
process.env.MAPBOX_TOKEN ||
"pk.eyJ1IjoibWplZHJhcyIsImEiOiJjazI2OHA5YzQycTBpM29xdDVwbXNyMDlwIn0.XS5ilGzTh_yVl3XY-8UKeA"
const HOUSING_COUNSELOR_SERVICE_URL = process.env.HOUSING_COUNSELOR_SERVICE_URL
const bloomTheme = require("./tailwind.config.js")
const tailwindVars = require("@bloom-housing/ui-components/tailwind.tosass.js")(bloomTheme)
// Tell webpack to compile the ui components package
// https://www.npmjs.com/package/next-transpile-modules
module.exports = withMDX(
withSass(
withTM({
env: {
listingServiceUrl: LISTING_SERVICE_URL,
mapBoxToken: MAPBOX_TOKEN,
housingCounselorServiceUrl: HOUSING_COUNSELOR_SERVICE_URL
},
sassLoaderOptions: {
prependData: tailwindVars
},
// exportPathMap adapted from https://github.com/zeit/next.js/blob/canary/examples/with-static-export/next.config.js
async exportPathMap() {
// we fetch our list of listings, this allow us to dynamically generate the exported pages
let listings = []
try {
const response = await axios.get(LISTING_SERVICE_URL)
listings = response.data.listings
} catch (error) {
console.log(error)
}
// tranform the list of posts into a map of pages with the pathname `/post/:id`
const listingPaths = listings.reduce(
(listingPaths, listing) =>
Object.assign({}, listingPaths, {
[`/listing/${listing.id}`]: {
page: "/listing",
query: { id: listing.id }
}
}),
{}
)
// define page paths for various available languages
const translatablePaths = Object.assign({}, listingPaths, {
"/": { page: "/" },
"/listings": { page: "/listings" },
"/housing-counselors": { page: "/HousingCounselors" }
})
const languages = ["es"] // add new language codes here
const languagePaths = {}
Object.entries(translatablePaths).forEach(([key, value]) => {
languagePaths[key] = value
languages.forEach(language => {
const query = Object.assign({}, value.query)
query.language = language
languagePaths[`/${language}${key.replace(/^\/$/, "")}`] = {
...value,
query: query
}
})
})
// combine the map of all various types of page paths
return Object.assign({}, languagePaths, {
"/disclaimer": { page: "/disclaimer" },
"/privacy": { page: "/privacy" }
})
}
})
)
)