Skip to content

Commit db26298

Browse files
authored
Use gatsby-remark-autolink-headers to get improved heading ids (brianc#85)
* Use gatsby-remark-autolink-headers to get improved heading ids Fixes formatted text (e.g. inline code) being rendered as “[object Object]” (brianc#84), and multiple text children (e.g. `new Pool([config: object])`, for some reason) being rendered with commas. Also now compatible with GitHub! Can be used to add link icons beside each heading later by removing `icon: false` from its configuration (but needs additional CSS). * Create right sidebar link from tableOfContents URL instead of title Fixes right sidebar for id changes after introduction of gatsby-remark-autolink-headers.
1 parent d1dba3a commit db26298

File tree

5 files changed

+55
-8
lines changed

5 files changed

+55
-8
lines changed

gatsby-config.js

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ module.exports = {
2929
resolve: 'gatsby-mdx',
3030
options: {
3131
gatsbyRemarkPlugins: [
32+
{
33+
resolve: 'gatsby-remark-autolink-headers',
34+
options: {
35+
icon: false
36+
}
37+
},
3238
{
3339
resolve: "gatsby-remark-images",
3440
options: {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"gatsby-plugin-react-helmet": "3.0.12",
2626
"gatsby-plugin-sharp": "^2.0.35",
2727
"gatsby-plugin-sitemap": "^2.0.12",
28+
"gatsby-remark-autolink-headers": "^2.3.5",
2829
"gatsby-remark-copy-linked-files": "^2.0.11",
2930
"gatsby-remark-images": "3.0.10",
3031
"gatsby-source-filesystem": "^2.0.29",

src/components/mdxComponents/index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import AnchorTag from "./anchor";
88

99
/* eslint-disable react/display-name */
1010
export default {
11-
h1: props => <Heading id={props.children} {...props} is="h1" fontSize={[5, 6]} />,
12-
h2: props => <Heading id={props.children} {...props} is="h2" fontSize={[4]} />,
13-
h3: props => <Heading id={props.children} {...props} is="h3" fontSize={3} />,
14-
h4: props => <Heading id={props.children} {...props} is="h4" fontSize={2} />,
15-
h5: props => <Heading id={props.children} {...props} is="h5" fontSize={1} />,
16-
h6: props => <Heading id={props.children} {...props} is="h6" fontSize={0} />,
11+
h1: props => <Heading {...props} is="h1" fontSize={[5, 6]} />,
12+
h2: props => <Heading {...props} is="h2" fontSize={[4]} />,
13+
h3: props => <Heading {...props} is="h3" fontSize={3} />,
14+
h4: props => <Heading {...props} is="h4" fontSize={2} />,
15+
h5: props => <Heading {...props} is="h5" fontSize={1} />,
16+
h6: props => <Heading {...props} is="h6" fontSize={0} />,
1717
p: props => <Text {...props} is="p" lineHeight={1.625} mt={3} mb={4} />,
1818
pre: Pre,
1919
code: CodeBlock,

src/components/rightSidebar.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const SidebarLayout = ({ location }) => (
9292
return (
9393
<ListItem
9494
key={index}
95-
to={`#${innerItem.title}`}
95+
to={innerItem.url}
9696
level={1}
9797
>
9898
{innerItem.title}

yarn.lock

+41-1
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,13 @@
745745
dependencies:
746746
regenerator-runtime "^0.13.2"
747747

748+
"@babel/runtime@^7.10.2":
749+
version "7.10.3"
750+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.10.3.tgz#670d002655a7c366540c67f6fd3342cd09500364"
751+
integrity sha512-RzGO0RLSdokm9Ipe/YD+7ww8X2Ro79qiXZF3HU9ljrM+qnJmH1Vqth+hbiQZy761LnMJTMitHDuKVYTk3k4dLw==
752+
dependencies:
753+
regenerator-runtime "^0.13.4"
754+
748755
"@babel/template@^7.1.0", "@babel/template@^7.4.4":
749756
version "7.4.4"
750757
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.4.4.tgz#f4b88d1225689a08f5bc3a17483545be9e4ed237"
@@ -5694,6 +5701,17 @@ gatsby-react-router-scroll@^2.1.3:
56945701
scroll-behavior "^0.9.9"
56955702
warning "^3.0.0"
56965703

5704+
gatsby-remark-autolink-headers@^2.3.5:
5705+
version "2.3.5"
5706+
resolved "https://registry.yarnpkg.com/gatsby-remark-autolink-headers/-/gatsby-remark-autolink-headers-2.3.5.tgz#039025254d9c6c9220e11ee77f54274262d301f2"
5707+
integrity sha512-r46S/zABOHdgI0SiCzm2b689y4YcXah0bAAQ0bhyv+opkTZ7vj+HSuoCPCZRV5K6ODZImv/pi2MMSJX1ajxs0A==
5708+
dependencies:
5709+
"@babel/runtime" "^7.10.2"
5710+
github-slugger "^1.3.0"
5711+
lodash "^4.17.15"
5712+
mdast-util-to-string "^1.1.0"
5713+
unist-util-visit "^1.4.1"
5714+
56975715
gatsby-remark-copy-linked-files@^2.0.11:
56985716
version "2.1.2"
56995717
resolved "https://registry.yarnpkg.com/gatsby-remark-copy-linked-files/-/gatsby-remark-copy-linked-files-2.1.2.tgz#6c7184d3668c779d3e46af6aae314b9731bb7a12"
@@ -6031,6 +6049,13 @@ github-slugger@^1.1.1, github-slugger@^1.2.1:
60316049
dependencies:
60326050
emoji-regex ">=6.0.0 <=6.1.1"
60336051

6052+
github-slugger@^1.3.0:
6053+
version "1.3.0"
6054+
resolved "https://registry.yarnpkg.com/github-slugger/-/github-slugger-1.3.0.tgz#9bd0a95c5efdfc46005e82a906ef8e2a059124c9"
6055+
integrity sha512-gwJScWVNhFYSRDvURk/8yhcFBee6aFjye2a7Lhb2bUyRulpIoek9p0I9Kt7PT67d/nUlZbFu8L9RLiA0woQN8Q==
6056+
dependencies:
6057+
emoji-regex ">=6.0.0 <=6.1.1"
6058+
60346059
glob-base@^0.3.0:
60356060
version "0.3.0"
60366061
resolved "https://registry.yarnpkg.com/glob-base/-/glob-base-0.3.0.tgz#dbb164f6221b1c0b1ccf82aea328b497df0ea3c4"
@@ -8134,6 +8159,11 @@ lodash@^4.11.1, lodash@^4.15.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.1
81348159
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.14.tgz#9ce487ae66c96254fe20b599f21b6816028078ba"
81358160
integrity sha512-mmKYbW3GLuJeX+iGP+Y7Gp1AiGHGbXHCOh/jZmrawMmsE7MS4znI3RL2FsjbqOyMayHInjOeykW7PEajUk1/xw==
81368161

8162+
lodash@^4.17.15:
8163+
version "4.17.15"
8164+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
8165+
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
8166+
81378167
log-update@^3.0.0:
81388168
version "3.2.0"
81398169
resolved "https://registry.yarnpkg.com/log-update/-/log-update-3.2.0.tgz#719f24293250d65d0165f4e2ec2ed805ff062eec"
@@ -8392,6 +8422,11 @@ mdast-util-to-string@^1.0.2, mdast-util-to-string@^1.0.4, mdast-util-to-string@^
83928422
resolved "https://registry.yarnpkg.com/mdast-util-to-string/-/mdast-util-to-string-1.0.6.tgz#7d85421021343b33de1552fc71cb8e5b4ae7536d"
83938423
integrity sha512-868pp48gUPmZIhfKrLbaDneuzGiw3OTDjHc5M1kAepR2CWBJ+HpEsm252K4aXdiP5coVZaJPOqGtVU6Po8xnXg==
83948424

8425+
mdast-util-to-string@^1.1.0:
8426+
version "1.1.0"
8427+
resolved "https://registry.yarnpkg.com/mdast-util-to-string/-/mdast-util-to-string-1.1.0.tgz#27055500103f51637bd07d01da01eb1967a43527"
8428+
integrity sha512-jVU0Nr2B9X3MU4tSK7JP1CMkSvOj7X5l/GboG1tKRw52lLF1x2Ju92Ms9tNetCcbfX3hzlM73zYo2NKkWSfF/A==
8429+
83958430
mdast-util-toc@^2.0.1:
83968431
version "2.1.0"
83978432
resolved "https://registry.yarnpkg.com/mdast-util-toc/-/mdast-util-toc-2.1.0.tgz#82b6b218577bb0e67b23abf5c3f7ac73a4b5389f"
@@ -10850,6 +10885,11 @@ regenerator-runtime@^0.13.2:
1085010885
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.2.tgz#32e59c9a6fb9b1a4aff09b4930ca2d4477343447"
1085110886
integrity sha512-S/TQAZJO+D3m9xeN1WTI8dLKBBiRgXBlTJvbWjCThHWZj9EvHK70Ff50/tYj2J/fvBY6JtFVwRuazHN2E7M9BA==
1085210887

10888+
regenerator-runtime@^0.13.4:
10889+
version "0.13.5"
10890+
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz#d878a1d094b4306d10b9096484b33ebd55e26697"
10891+
integrity sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA==
10892+
1085310893
regenerator-transform@^0.14.0:
1085410894
version "0.14.0"
1085510895
resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.14.0.tgz#2ca9aaf7a2c239dd32e4761218425b8c7a86ecaf"
@@ -12858,7 +12898,7 @@ unist-util-visit-parents@^2.0.0, unist-util-visit-parents@^2.0.1:
1285812898
dependencies:
1285912899
unist-util-is "^3.0.0"
1286012900

12861-
unist-util-visit@^1.0.0, unist-util-visit@^1.1.0, unist-util-visit@^1.3.0, unist-util-visit@^1.4.0:
12901+
unist-util-visit@^1.0.0, unist-util-visit@^1.1.0, unist-util-visit@^1.3.0, unist-util-visit@^1.4.0, unist-util-visit@^1.4.1:
1286212902
version "1.4.1"
1286312903
resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-1.4.1.tgz#4724aaa8486e6ee6e26d7ff3c8685960d560b1e3"
1286412904
integrity sha512-AvGNk7Bb//EmJZyhtRUnNMEpId/AZ5Ph/KUpTI09WHQuDZHKovQ1oEv3mfmKpWKtoMzyMC4GLBm1Zy5k12fjIw==

0 commit comments

Comments
 (0)