-
Notifications
You must be signed in to change notification settings - Fork 2
/
gridsome.server.js
94 lines (89 loc) · 2.72 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
const fs = require("fs-extra")
const generateCover = require("./src/functions/generate-cover")
const coverOptions = {
imgWidth: "1024",
imgHeight: "576",
types: [
{
name: "Posts",
typeName: "Post",
path: "blog"
}
],
// Set Colours
colours: [
"#559BFF",
"#FFD948",
"#CD1FFF",
"#41FFA7",
"#FF6336",
"#FF4576"
]
}
module.exports = function (api) {
api.loadSource(({ addMetadata, addCollection }) => {
// Use the Data Store API here: https://gridsome.org/docs/data-store-api/
addMetadata(
'siteTitle', 'Competitive Programming - Workshop & Riset Informatika'
)
addMetadata('siteAuthor', 'CP-WRI')
addMetadata(
'siteAuthorUrl', 'https://www.github.com/cp-wri'
)
addMetadata(
'archive_title',
'NOTE: THIS ARTICLE IS PART OF OUR ARCHIVE AND IS LIKELY OUT OF DATE.'
)
addMetadata(
'archive_text',
'(LINKS MAY NOT WORK, DOWNLOADS HAVE NOT BEEN RECENTLY TESTED FOR SAFETY)'
)
const category = addCollection('Category')
category.addReference('categories', 'Category')
})
api.createPages(({ createPage }) => {
// Use the Pages API here: https://gridsome.org/docs/pages-api/
})
api.loadSource(({ addSchemaResolvers }) => {
// Schema API here: https://gridsome.org/docs/schema-api/
// Create a default value for "sidebar" to prevent Cannot query errors if not used
addSchemaResolvers({
Post: {
sidebar: {
type: 'String',
resolve(obj) {
return (obj.sidebar === undefined ? 'Default' : obj.sidebar)
}
}
}
})
})
api.loadSource(async (actions) => {
if (process.env.AUTO_GENERATE_COVER) {
// Loop through each type to create a cover image for
coverOptions.types.forEach(function (type) {
console.log("Generating cover images for " + type.name)
const collection = actions.getCollection(type.typeName)
const outputPath = `${type.path}`
fs.ensureDirSync(outputPath)
collection.data().forEach(function (node) {
if (node.internal.typeName === type.typeName) {
if (node.thumbnail !== undefined) {
const output = `${node.thumbnail}`
fs.access(output, (error) => {
if (error) {
console.log(`Creating ${output}`)
generateCover(output, node.cover_title ?? node.title, coverOptions)
} else {
console.log(`${output} already exists`)
}
})
}
}
})
})
} else {
console.log("If you would like to automatically generate cover images, set AUTO_GENERATE_COVER in your env file to true.")
}
})
}