11import { useEffect } from 'react'
2+ import { useRouter } from 'next/router'
23import hljs from 'highlight.js/lib/core'
34import json from 'highlight.js/lib/languages/json'
5+ import javascript from 'highlight.js/lib/languages/javascript'
6+ import hljsCurl from 'highlightjs-curl'
47
58// Add as needed. It's pretty cheap to add but please don't use
69// highlight.js import that loads all and everything.
710hljs . registerLanguage ( 'json' , json )
8- const SUPPORTED_LANGUAGES = [ 'json' ]
11+ hljs . registerLanguage ( 'javascript' , javascript )
12+ hljs . registerLanguage ( 'curl' , hljsCurl )
13+ const SUPPORTED_LANGUAGES = [ 'json' , 'javascript' , 'curl' ]
914
1015// This is the selector we use for the first document.querySelectorAll()
1116// to find the containers for `<code>` tags. Because it's s dataset
@@ -24,6 +29,8 @@ const CODE_ELEMENTS_PARENT_SELECTOR = '[data-highlight]'
2429const CODE_SELECTOR = 'pre code'
2530
2631export default function ClientSideHighlightJS ( ) {
32+ const { asPath } = useRouter ( )
33+
2734 useEffect ( ( ) => {
2835 // Hi Internet Explorer!
2936 // https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#browser_compatibility
@@ -59,7 +66,7 @@ export default function ClientSideHighlightJS() {
5966 intersectionObserver . observe ( element )
6067 }
6168 }
62- } , [ ] )
69+ } , [ asPath ] )
6370
6471 return null
6572}
0 commit comments