mirror of
https://github.com/fabe/gatsby-starter-deck.git
synced 2024-10-05 16:07:19 +03:00
Add typedefs for Slide, remove unused deps, use createContentDige… (#20)
This commit is contained in:
parent
185d985f7b
commit
12e9e5c438
@ -19,7 +19,7 @@ module.exports = {
|
||||
resolve: `gatsby-transformer-remark`,
|
||||
options: {
|
||||
plugins: [
|
||||
`gatsby-remark-copy-images`,
|
||||
`gatsby-remark-copy-linked-files`,
|
||||
{
|
||||
resolve: `gatsby-remark-images`,
|
||||
options: {
|
||||
|
@ -1,10 +1,5 @@
|
||||
const path = require('path');
|
||||
const { createFilePath } = require('gatsby-source-filesystem')
|
||||
const remark = require('remark');
|
||||
const recommended = require('remark-preset-lint-recommended');
|
||||
const html = require('remark-html');
|
||||
const crypto = require('crypto');
|
||||
const _ = require('lodash')
|
||||
const _ = require('lodash');
|
||||
|
||||
// Remove trailing slash
|
||||
exports.onCreatePage = ({ page, actions }) => {
|
||||
@ -28,7 +23,7 @@ exports.onCreatePage = ({ page, actions }) => {
|
||||
};
|
||||
|
||||
// Create pages from markdown nodes
|
||||
exports.createPages = ({ actions, createNodeId, graphql }) => {
|
||||
exports.createPages = ({ actions, createContentDigest, createNodeId, graphql }) => {
|
||||
const { createPage, createNode } = actions;
|
||||
const slideTemplate = path.resolve(`src/templates/slide.js`);
|
||||
|
||||
@ -37,7 +32,7 @@ exports.createPages = ({ actions, createNodeId, graphql }) => {
|
||||
allMarkdownRemark {
|
||||
edges {
|
||||
node {
|
||||
fileAbsolutePath,
|
||||
fileAbsolutePath
|
||||
html
|
||||
}
|
||||
}
|
||||
@ -52,26 +47,21 @@ exports.createPages = ({ actions, createNodeId, graphql }) => {
|
||||
slides.sort((a, b) => a.node.fileAbsolutePath > b.node.fileAbsolutePath ? 1 : -1)
|
||||
const nodes = slides.flatMap((s) => s.node.html.split('<hr>').map((html) => ({
|
||||
node: s.node, html
|
||||
})))
|
||||
})));
|
||||
|
||||
nodes.forEach(({ node, html }, index) => {
|
||||
const digest = crypto
|
||||
.createHash(`md5`)
|
||||
.update(html)
|
||||
.digest(`hex`);
|
||||
|
||||
createNode({
|
||||
id: createNodeId(`${node.id}_${index + 1} >>> Slide`),
|
||||
parent: node.id,
|
||||
children: [],
|
||||
internal: {
|
||||
type: `Slide`,
|
||||
contentDigest: digest,
|
||||
contentDigest: createContentDigest(html),
|
||||
},
|
||||
html: html,
|
||||
index: index + 1,
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
nodes.forEach((slide, index) => {
|
||||
createPage({
|
||||
@ -85,3 +75,12 @@ exports.createPages = ({ actions, createNodeId, graphql }) => {
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.sourceNodes = ({ actions }) => {
|
||||
actions.createTypes(`
|
||||
type Slide implements Node {
|
||||
html: String
|
||||
index: Int
|
||||
}
|
||||
`);
|
||||
};
|
||||
|
13
package.json
13
package.json
@ -4,26 +4,21 @@
|
||||
"version": "2.0.0",
|
||||
"author": "Fabian Schultz <desk@fabianschultz.com>",
|
||||
"dependencies": {
|
||||
"gatsby": "^2.0.33",
|
||||
"gatsby": "^2.2.0",
|
||||
"gatsby-plugin-layout": "^1.0.1",
|
||||
"gatsby-plugin-offline": "^2.0.5",
|
||||
"gatsby-plugin-react-helmet": "^3.0.0",
|
||||
"gatsby-plugin-sharp": "^2.0.14",
|
||||
"gatsby-remark-copy-images": "^0.2.1",
|
||||
"gatsby-remark-copy-linked-files": "^2.0.7",
|
||||
"gatsby-remark-images": "^3.0.1",
|
||||
"gatsby-remark-relative-images": "^0.2.1",
|
||||
"gatsby-source-filesystem": "^2.0.1",
|
||||
"gatsby-transformer-remark": "^2.1.15",
|
||||
"gatsby-transformer-sharp": "^2.1.9",
|
||||
"react": "^16.5.1",
|
||||
"react-dom": "^16.5.1",
|
||||
"react": "^16.6.0",
|
||||
"react-dom": "^16.6.0",
|
||||
"react-helmet": "^5.2.0",
|
||||
"react-swipeable": "^4.3.0",
|
||||
"react-transition-group": "^2.4.0",
|
||||
"remark": "^9.0.0",
|
||||
"remark-html": "^8.0.0",
|
||||
"remark-preset-lint-recommended": "^3.0.2"
|
||||
"react-transition-group": "^2.4.0"
|
||||
},
|
||||
"keywords": [
|
||||
"gatsby",
|
||||
|
Loading…
Reference in New Issue
Block a user