Skip to content

Commit

Permalink
feat: add rehype plugins for linkable content
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Won committed Sep 24, 2020
1 parent 87e6cc6 commit 71d00bc
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
7 changes: 6 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const withMdxEnhanced = require('next-mdx-enhanced');
var link = require('rehype-autolink-headings');
var slug = require('rehype-slug');
const linkOptions = {
behavior: 'wrap',
};

const nextConfig = {
distDir: 'nextjs',
Expand All @@ -14,7 +19,7 @@ module.exports = withMdxEnhanced({
defaultLayout: true,
fileExtensions: ['mdx'],
remarkPlugins: [],
rehypePlugins: [],
rehypePlugins: [slug, [link, linkOptions]],
usesSrc: true,
extendFrontMatter: {
process: (mdxContent, frontMatter) => {},
Expand Down
48 changes: 48 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-icons": "^3.11.0",
"rehype-autolink-headings": "^4.0.0",
"rehype-slug": "^3.0.0",
"remark": "^12.0.1",
"remark-html": "^12.0.0",
"swr": "^0.2.0"
Expand Down
9 changes: 8 additions & 1 deletion src/layouts/Mdx.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { fromUnixTime } from 'date-fns';
import * as React from 'react';
import { MDXProvider } from '@mdx-js/react';
import MDXComponents from 'src/components/MdxComponents';
import Layout from './Layout';
import { Heading } from '@chakra-ui/core';
import { even, useRouter } from 'next/router';
import { useEffect, useState } from 'react';

export interface IMdxProps {
children?: React.ReactNode;
frontMatter;
}

export default function Mdx({ frontMatter, children }: IMdxProps) {
const router = useRouter();

useEffect(() => {
router.push(window.location.hash);
}, []);

return (
<Layout>
<Heading mb="1rem">{frontMatter.title}</Heading>
Expand Down

0 comments on commit 71d00bc

Please sign in to comment.