mirror of
https://github.com/LukeHagar/unicorn-utterances.git
synced 2025-12-10 04:22:06 +00:00
Initial work to add Gatsby remarked plugin to keep headings
This commit is contained in:
@@ -102,6 +102,7 @@ module.exports = {
|
||||
enableCustomId: true
|
||||
}
|
||||
},
|
||||
`remarked-autolink-headers-and-add-id`,
|
||||
{
|
||||
resolve: `gatsby-remark-prismjs`,
|
||||
options: {
|
||||
|
||||
50
package-lock.json
generated
50
package-lock.json
generated
@@ -1281,11 +1281,18 @@
|
||||
}
|
||||
},
|
||||
"@babel/runtime": {
|
||||
"version": "7.3.4",
|
||||
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.3.4.tgz",
|
||||
"integrity": "sha512-IvfvnMdSaLBateu0jfsYIpZTxAc2cKEXEMiezGGN75QcBcecDUKd3PgLAncT0oOgxKy8dd8hrJKj9MfzgfZd6g==",
|
||||
"version": "7.8.4",
|
||||
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.4.tgz",
|
||||
"integrity": "sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==",
|
||||
"requires": {
|
||||
"regenerator-runtime": "^0.12.0"
|
||||
"regenerator-runtime": "^0.13.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"regenerator-runtime": {
|
||||
"version": "0.13.3",
|
||||
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz",
|
||||
"integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@babel/template": {
|
||||
@@ -20571,9 +20578,9 @@
|
||||
}
|
||||
},
|
||||
"mdast-util-to-string": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/mdast-util-to-string/-/mdast-util-to-string-1.0.6.tgz",
|
||||
"integrity": "sha512-868pp48gUPmZIhfKrLbaDneuzGiw3OTDjHc5M1kAepR2CWBJ+HpEsm252K4aXdiP5coVZaJPOqGtVU6Po8xnXg=="
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/mdast-util-to-string/-/mdast-util-to-string-1.0.7.tgz",
|
||||
"integrity": "sha512-P+gdtssCoHOX+eJUrrC30Sixqao86ZPlVjR5NEAoy0U79Pfxb1Y0Gntei0+GrnQD4T04X9xA8tcugp90cSmNow=="
|
||||
},
|
||||
"mdast-util-toc": {
|
||||
"version": "2.1.0",
|
||||
@@ -24091,6 +24098,17 @@
|
||||
"prop-types": "15.7.2",
|
||||
"react-fast-compare": "2.0.4",
|
||||
"shallowequal": "1.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": {
|
||||
"version": "7.3.4",
|
||||
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.3.4.tgz",
|
||||
"integrity": "sha512-IvfvnMdSaLBateu0jfsYIpZTxAc2cKEXEMiezGGN75QcBcecDUKd3PgLAncT0oOgxKy8dd8hrJKj9MfzgfZd6g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"regenerator-runtime": "^0.12.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"react-hot-loader": {
|
||||
@@ -24556,7 +24574,8 @@
|
||||
"regenerator-runtime": {
|
||||
"version": "0.12.1",
|
||||
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz",
|
||||
"integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg=="
|
||||
"integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==",
|
||||
"dev": true
|
||||
},
|
||||
"regenerator-transform": {
|
||||
"version": "0.14.0",
|
||||
@@ -28437,6 +28456,21 @@
|
||||
"unist-util-is": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"unist-util-flat-filter": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/unist-util-flat-filter/-/unist-util-flat-filter-1.0.0.tgz",
|
||||
"integrity": "sha512-zjTmbMgyL1V7iUCnFaGLms9HtGbqK4d3YINqzu+wiMbau93GdiDGtJiB8lMhAyxAaxIAK2rOCeBCldF0FUreKQ==",
|
||||
"requires": {
|
||||
"unist-util-is": "^4.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"unist-util-is": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-4.0.1.tgz",
|
||||
"integrity": "sha512-7NYjErP4LJtkEptPR22wO5RsCPnHZZrop7t2SoQzjvpFedCFer4WW8ujj9GI5DkUX7yVcffXLjoURf6h2QUv6Q=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"unist-util-generated": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/unist-util-generated/-/unist-util-generated-1.1.4.tgz",
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
"react-helmet": "^5.2.1",
|
||||
"react-paginate": "^6.3.0",
|
||||
"react-pose": "^4.0.9",
|
||||
"unist-util-visit": "^1.4.1"
|
||||
"unist-util-flat-filter": "^1.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@reach/router": "^1.1.1"
|
||||
@@ -106,6 +106,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gatsby build",
|
||||
"debug": "gatsby clean && node --nolazy --inspect-brk ./node_modules/.bin/gatsby develop",
|
||||
"develop": "gatsby develop",
|
||||
"format": "run-s format:**",
|
||||
"format:js": "eslint --fix ./src",
|
||||
|
||||
26
plugins/remarked-autolink-headers-and-add-id/index.js
Normal file
26
plugins/remarked-autolink-headers-and-add-id/index.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const flatFilter = require("unist-util-flat-filter");
|
||||
|
||||
module.exports = ({ markdownAST, actions, markdownNode }) => {
|
||||
const { createNodeField } = actions;
|
||||
|
||||
const values = flatFilter(markdownAST, node => node.type === "heading");
|
||||
|
||||
const headings = values.children.map(node => {
|
||||
const last = node.children[node.children.length - 1];
|
||||
|
||||
return {
|
||||
value: last.value,
|
||||
depth: node.depth,
|
||||
// This is added by the `gatsby-remark-autolink-headers` plugin, we're just using it here
|
||||
// This means that it must come after that plugin in your config file
|
||||
slug: node.data.id
|
||||
};
|
||||
});
|
||||
|
||||
createNodeField({
|
||||
name: `headingsWithId`,
|
||||
node: markdownNode,
|
||||
value: headings
|
||||
});
|
||||
return markdownAST;
|
||||
};
|
||||
46
plugins/remarked-autolink-headers-and-add-id/package.json
Normal file
46
plugins/remarked-autolink-headers-and-add-id/package.json
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "remarked-autolink-headers-and-add-id",
|
||||
"description": "Gatsby plugin to autolink headers in markdown processed by Remark",
|
||||
"version": "2.1.24",
|
||||
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
||||
"bugs": {
|
||||
"url": "https://github.com/gatsbyjs/gatsby/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.7.6",
|
||||
"github-slugger": "^1.2.1",
|
||||
"lodash": "^4.17.15",
|
||||
"mdast-util-to-string": "^1.0.7",
|
||||
"unist-util-visit": "^1.4.1",
|
||||
"unist-util-flatmap": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.7.5",
|
||||
"@babel/core": "^7.7.5",
|
||||
"babel-preset-gatsby-package": "^0.2.16",
|
||||
"cross-env": "^5.2.1"
|
||||
},
|
||||
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-remark-autolink-headers#readme",
|
||||
"keywords": [
|
||||
"gatsby",
|
||||
"gatsby-plugin",
|
||||
"remark"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"peerDependencies": {
|
||||
"gatsby": "^2.0.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/gatsbyjs/gatsby.git",
|
||||
"directory": "packages/gatsby-remark-autolink-headers"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel src --out-dir . --ignore **/__tests__",
|
||||
"watch": "babel -w src --out-dir . --ignore **/__tests__"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.0.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user