Skip to content

Commit c7bbc61

Browse files
committed
Added code highlighting
1 parent de89d44 commit c7bbc61

File tree

7 files changed

+137
-606
lines changed

7 files changed

+137
-606
lines changed

.babelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"presets": ["next/babel"],
3+
"plugins": [
4+
[
5+
"prismjs",
6+
{
7+
"languages": ["javascript", "jsx", "json", "html", "bash"]
8+
}
9+
]
10+
]
11+
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@
1616
"dependencies": {
1717
"buffer": "^5.5.0",
1818
"gray-matter": "^4.0.2",
19+
"marksy": "^8.0.0",
1920
"next": "^9.3.3",
2021
"node-glob": "^1.2.0",
2122
"path-browserify": "^1.0.1",
23+
"prism-themes": "^1.3.0",
24+
"prismjs": "^1.19.0",
2225
"react": "^16.13.1",
2326
"react-dom": "^16.13.1",
24-
"react-markdown": "^4.3.1",
2527
"semantic-ui-css": "^2.4.1",
2628
"semantic-ui-react": "^0.88.2"
2729
},
2830
"devDependencies": {
31+
"babel-plugin-prismjs": "^2.0.1",
2932
"raw-loader": "^4.0.0",
3033
"sass": "^1.26.3"
3134
},

src/pages/_app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import React from 'react';
2+
3+
import 'prism-themes/themes/prism-vs.css';
24
import 'semantic-ui-css/semantic.min.css';
35

46
import '../styles/bootstrap.css';

src/pages/blog/[slug].js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
import * as React from 'react'
2-
import matter from "gray-matter";
3-
import ReactMarkdown from "react-markdown";
2+
import Prism from 'prismjs';
3+
import matter from 'gray-matter';
4+
import marksy from 'marksy/jsx';
5+
6+
const compile = marksy({
7+
createElement: React.createElement,
8+
highlight(language, code) {
9+
return Prism.highlight(code, Prism.languages[language], language);
10+
},
11+
});
12+
413

514
import ArticlePage from '../../components/article-page';
615
import navItems from '../../nav-items';
716

17+
// function reformatDate(fullDate) {
18+
// const date = new Date(fullDate)
19+
// return date.toDateString().slice(4);
20+
// }
21+
822
export default function BlogTemplate(props) {
9-
// function reformatDate(fullDate) {
10-
// const date = new Date(fullDate)
11-
// return date.toDateString().slice(4);
12-
// }
1323
const markdownBody = props.content
1424
const frontmatter = props.data
1525

26+
const body = compile(markdownBody);
27+
1628
return (
1729
<ArticlePage
1830
menuItems={navItems.menuItems}
1931
secondaryMenuItems={navItems.secondaryMenuItems}
2032
title={frontmatter.title}
2133
secondaryTitle={frontmatter.secondary_title}
2234
>
23-
<ReactMarkdown source={markdownBody} />
35+
<article className="center-images">
36+
{body.tree}
37+
</article>
2438
</ArticlePage>
2539
);
2640
}

src/pages/get-started.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import Router from 'next/router';
3+
4+
export default function GetStartedRedirect() {
5+
React.useEffect(() => {
6+
Router.replace('/blog/get-started');
7+
}, []);
8+
9+
return <p>Redirecting....</p>;
10+
}

src/styles/bootstrap.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ body,
99
display: none !important;
1010
}
1111
}
12+
13+
.center-images img {
14+
display: block;
15+
margin-left: auto;
16+
margin-right: auto;
17+
max-width: 100%;
18+
}

0 commit comments

Comments
 (0)