This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgatsby-node.js
54 lines (44 loc) · 1.57 KB
/
gatsby-node.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
const Prism = require('prismjs')
const loadLanguages = require('prismjs/components/')
const terminalSlides = require('./content/home-slides')
loadLanguages(['bash', 'python'])
const getBashHtml = bashText =>
Prism.highlight(bashText, Prism.languages.bash, 'bash')
const getPythonHtml = pythonText =>
Prism.highlight(pythonText, Prism.languages.python, 'python')
const formattedTerminalLines = terminalSlides.map(string => {
const lines = string.split(/\r?\n/).map(line => {
const l = line.trim()
const commandPromptReg = /^(\$|>{3}|\.{3})/
if (commandPromptReg.test(l)) {
const prompt = l.match(commandPromptReg)[0]
const text = l.replace(commandPromptReg, '')
return {
promptString: prompt,
text: prompt === '$' ? getBashHtml(text) : getPythonHtml(text)
}
} else {
return { text: l, promptString: null }
}
})
return lines[0].text === '' ? lines.slice(1) : lines
})
exports.sourceNodes = ({ actions, createNodeId, createContentDigest }) => {
const { createNode } = actions
formattedTerminalLines.forEach((terminalLines, i) => {
const formattedTerminalSlide = { lines: terminalLines }
const nodeContent = JSON.stringify(formattedTerminalSlide)
const nodeMeta = {
id: createNodeId(`terminal-slide-${i}`),
parent: null,
children: [],
internal: {
type: 'TerminalSlide',
content: nodeContent,
contentDigest: createContentDigest(formattedTerminalSlide)
}
}
const node = Object.assign({}, formattedTerminalSlide, nodeMeta)
createNode(node)
})
}