-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathgridsome.server.js
143 lines (129 loc) · 3.47 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
131
132
133
134
135
136
137
138
139
140
141
142
143
const fs = require('fs');
const translateBlogPost = require('./functions/translations');
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.loadSource(async (actions) => {
const collection = actions.getCollection('Post');
// Detect updated files from the UPDATED_FILES environment variable
const updatedFiles = process.env.UPDATED_FILES
? process.env.UPDATED_FILES.split('\n')
: null;
collection.data().filter((e) => {
if (e.locale === 'en') {
// Filter posts if incremental build is enabled
if (
!updatedFiles || // If UPDATED_FILES is null, include all posts
updatedFiles.some((filePath) =>
filePath.endsWith(`${e.fileInfo.name}.md`)
)
) {
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 }) => {
// Define locales
const locales = [
'ar',
'de',
'el',
'en',
'es',
'fr',
'it',
'ja',
'ko',
'nl',
'pt',
'ru',
'uk',
'zh',
];
// Static redirects
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',
},
});
// Localized redirects
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',
},
});
});
// Blog posts and translations
allPossiblePaths.forEach((node) => {
// For blog post translations
// translateBlogPost(fs, path);
// Create pages for missing translations
locales.forEach((locale) => {
if (fs.existsSync(`content/posts/${locale}/${node.name}.md`)) {
console.log('exists');
} else {
createPage({
path: `/blog/${locale}/${node.name}/`,
component: 'src/pages/redirect.vue',
context: {
redirect: `/blog/${node.name.toLowerCase()}/`,
},
});
}
});
});
});
};