-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathnext.config.js
71 lines (60 loc) · 2.27 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
// @generated: @expo/next-adapter@2.1.0
// Learn more: https://github.com/expo/expo/blob/master/docs/pages/versions/unversioned/guides/using-nextjs.md#withexpo
const generateSiteMap = require("./utils/generateSiteMap");
const { withExpo } = require('@expo/next-adapter');
const withImages = require('next-optimized-images');
const withFonts = require('next-fonts');
const fetch = require('isomorphic-unfetch');
async function getListings() {
var masterRef = await fetch('https://spicygreenbook.cdn.prismic.io/api/v2');
var masterRef_json = await masterRef.json();
var master_ref;
masterRef_json.refs.forEach(line => {
if (line.id === 'master') {
master_ref = line.ref;
}
})
let url;
url = `https://spicygreenbook.cdn.prismic.io/api/v1/documents/search?ref=${master_ref}&q=%5B%5Bat(document.type%2C+%22listing%22)%5D%5D&orderings=%5Bmy.listing.home_page_order%20desc%5D&pageSize=100`;
if (url) {
let data = await fetch(url);
let parsed_data = [];
let getLoop = async (nextInfo) => {
nextInfo.results.map((doc, i) => {
parsed_data.push(doc);
})
if (nextInfo.next_page) {
console.log('fetching next page', nextInfo.next_page)
let data = await fetch(nextInfo.next_page);
getLoop(await data.json());
}
}
await getLoop(await data.json());
//console.log('parsed_data', parsed_data)
//console.log('parsed', parsed_data)
rows = parsed_data.map((doc, i) => {
let content = {
id: doc.id,
uid: doc.uid,
_slug: doc.uid,
created: new Date(doc.first_publication_date).getTime(),
updated: new Date(doc.last_publication_date).getTime(),
};
return content;
})
}
//console.log('rows', rows)
return rows
}
async function handle() {
let listings = await getListings();
let sitemap = await generateSiteMap(listings);
return {}
}
module.exports = withExpo(withFonts(withImages({
projectRoot: __dirname,
generaiteSiteMap: handle(),
images: {
domains: ['images.prismic.io', 'prismic-io.s3.amazonaws.com', 'res.cloudinary.com']
}
})));