-
Notifications
You must be signed in to change notification settings - Fork 20
/
gridsome.server.js
130 lines (103 loc) · 3.29 KB
/
gridsome.server.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
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
// Server API makes it possible to hook into various parts of Gridsome
// on server-side and add custom data to the GraphQL data layer.
// Learn more: https://gridsome.org/docs/server-api/
// Changes here require a server restart.
// To restart press CTRL + C in terminal and run `gridsome develop`
const fs = require('fs');
const translateBlogPost = require("./functions/translations");
const proxy = require("http-proxy-middleware")
let allPossiblePaths = [];
module.exports = function (api) {
// Use the Data Store API here: https://gridsome.org/docs/data-store-api/
api.loadSource(async store => {
store.addMetadata('home', 'https://robonomics.network')
store.addMetadata('discord', 'https://discord.gg/JpaN2XAmqY')
store.addMetadata('twitter', 'https://twitter.com/AIRA_Robonomics')
})
api.configureServer(app => {
app.use("/api", proxy({
target: 'https://api.unisender.com/ru/',
changeOrigin: true
}))
})
api.loadSource(async (actions) => {
const collection = actions.getCollection('Post');
collection.data().filter((e) => {
if(e.locale === 'en')
allPossiblePaths.push({path: e.path, name: e.fileInfo.name, content: e.content, title: e.title, description: e.description, cover_image: e.cover_image, abstract: e.abstract, author: e.author, tags: e.tags, related: e.related, published: e.published, id: e.id})
})
})
// Use the Pages API here: https://gridsome.org/docs/pages-api/
api.createManagedPages( ({ createPage }) => {
// all locales
const locales = ["ar","de","el","en","es","fr","it","ja","ko","nl","pt","ru","uk","zh"];
createPage(
{
path: '/en/',
component: 'src/pages/redirect.vue',
context: {
redirect: '/'
}
}
)
createPage(
{
path: `/white-paper-2022`,
component: 'src/pages/redirect.vue',
context: {
redirect: '/white-paper'
}
}
)
createPage(
{
path: `/shop`,
component: 'src/pages/redirect.vue',
context: {
redirect: '/merch'
}
}
)
createPage({
path: `/robonomics_white_paper_en.pdf/`,
component: 'src/pages/redirect.vue',
context: {
redirect: '/white-paper'
}
})
locales.forEach(l => {
createPage(
{
path: `/${l}/white-paper-2022`,
component: 'src/pages/redirect.vue',
context: {
redirect: '/white-paper'
}
}
)
createPage({
path: `/${l}/shop`,
component: 'src/pages/redirect.vue',
context: {
redirect: '/merch'
}
})
})
allPossiblePaths.forEach(node => {
const path = node.path.slice(0, -1).split("/").pop();
// for blog posts translations
// translateBlogPost(fs, path)
// pages for not existing translations
locales.forEach(locale => {
if (fs.existsSync(`content/posts/${locale}/${node.name}.md`)) {
console.log('exists');
} else {
createPage({
path: `/blog/${locale}/${path}`,
component: './src/templates/BlogTranslations.vue',
})
}
});
})
})
}