diff --git a/.eslintrc.yml b/.eslintrc.yml index cef16c65f082d9f83aadbaf36f222882f9431c0b..bb4c8a916c61cade417a0550bcbd1f0b70360f41 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -11,6 +11,12 @@ parserOptions: # though that setting is only for ES6 modules, not CommonJS modules. sourceType: 'script' +overrides: + files: + - gatsby-browser.js + parserOptions: + sourceType: 'module' + plugins: - mocha - no-extension-in-require diff --git a/frontend/components/usage.js b/frontend/components/usage.js index 427353dd6c6b4994b664abdc4e0942f87a87a18e..363c7d333fc61051b7d845d006a87552f4699488 100644 --- a/frontend/components/usage.js +++ b/frontend/components/usage.js @@ -170,7 +170,7 @@ export default class Usage extends React.PureComponent { <section> <H2 id="your-badge">Your Badge</H2> - <H3 id="static-badge">Static</H3> + <H3>Static</H3> <StaticBadgeMaker baseUrl={baseUrl} /> <VerticalSpace /> @@ -215,7 +215,7 @@ export default class Usage extends React.PureComponent { /> </p> - <H3 id="endpoint">Endpoint (Beta)</H3> + <H3>Endpoint (Beta)</H3> <p> <Snippet diff --git a/frontend/pages/endpoint.js b/frontend/pages/endpoint.js index 71cc07282d5de84d16783e297a5ee52ccea6cb3d..0fdaafe7f8932b75a8908794f8de38f41d6af174 100644 --- a/frontend/pages/endpoint.js +++ b/frontend/pages/endpoint.js @@ -87,7 +87,7 @@ const EndpointPage = () => ( <GlobalStyle /> <Meta /> <Header /> - <H3 id="static-badge">Endpoint (Beta)</H3> + <H3>Endpoint (Beta)</H3> <Snippet snippet={`${baseUrl}/badge/endpoint.svg?url=...&style=...`} /> <p>Endpoint response:</p> <JsonExample diff --git a/gatsby-browser.js b/gatsby-browser.js new file mode 100644 index 0000000000000000000000000000000000000000..ad8b86ab076d852f8105681a9f5b509136fef80a --- /dev/null +++ b/gatsby-browser.js @@ -0,0 +1,16 @@ +// Adapted from https://github.com/gatsbyjs/gatsby/issues/8413 + +function scrollToElementId(id) { + const el = document.querySelector(id) + if (el) { + return window.scrollTo(0, el.offsetTop - 20) + } else { + return false + } +} + +export function onRouteUpdate({ location: { hash } }) { + if (hash) { + window.setTimeout(() => scrollToElementId(hash), 10) + } +}