Skip to content

Commit 85c5ece

Browse files
authored
Merge pull request #30 from Code-Hex/fix/build
fixed build
2 parents 2142752 + 3ffab16 commit 85c5ece

File tree

21 files changed

+9361
-15399
lines changed

21 files changed

+9361
-15399
lines changed

.babelrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"presets": ["next/babel"],
3-
"plugins": ["import-glob-array"]
2+
"presets": ["next/babel"]
43
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
components/Mdx.tsx

.eslintrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "next",
3+
"rules": {
4+
"react-hooks/exhaustive-deps": "off"
5+
}
6+
}

components/Note.tsx

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { MDXProvider } from '@mdx-js/react';
2+
import { Metadata } from 'mdx/config';
3+
import Head from 'next/head';
4+
import Link from 'next/link';
5+
import { useRouter } from 'next/router';
6+
import { ReactNode } from 'react';
7+
import { MDXComponents } from './Mdx';
8+
9+
interface NoteProps {
10+
meta: Metadata;
11+
children: ReactNode;
12+
}
13+
14+
const Note = (props: NoteProps) => {
15+
const { meta, children } = props;
16+
const router = useRouter();
17+
const title = meta.title;
18+
return (
19+
<main>
20+
<article className="py-16">
21+
<Head>
22+
<title>{title} – codehex note</title>
23+
{/* <meta name="description" content={meta.description}></meta> */}
24+
<meta name="twitter:card" content="summary_large_image" />
25+
<meta name="twitter:site" content="@codehex" />
26+
<meta name="twitter:creator" content="@codehex" />
27+
<meta name="twitter:title" content={`${title} – codehex note`} />
28+
{/* <meta name="twitter:description" content={description} /> */}
29+
<meta name="twitter:card" content="summary" />
30+
<meta
31+
name="twitter:image"
32+
content={`https://codehex.dev/assets/images/twitter-card-small.jpg`}
33+
/>
34+
<meta
35+
property="og:url"
36+
content={`https://codehex.dev${router.pathname}`}
37+
/>
38+
<meta property="og:type" content="article" />
39+
<meta property="og:title" content={`${title} – codehex note`} />
40+
{/* <meta property="og:description" content={description} /> */}
41+
<meta
42+
property="og:image"
43+
content={`https://codehex.dev/assets/images/twitter-card-small.jpg`}
44+
/>
45+
</Head>
46+
<div className={`w-full flex bg-white antialiased`}>
47+
<div className="min-w-0 flex-auto px-8 sm:px-10 xl:px-12 pt-10 pb-24 lg:pb-16">
48+
<div className="pb-10 border-b border-gray-200 mb-10">
49+
<div>
50+
<h1 className="inline-block text-3xl font-extrabold text-gray-900 tracking-tight">
51+
{title}
52+
</h1>
53+
</div>
54+
<p className="mt-1 text-lg text-gray-500">Detail</p>
55+
</div>
56+
57+
<MDXProvider components={{ ...MDXComponents }}>
58+
{children}
59+
</MDXProvider>
60+
<footer className="text-sm font-medium leading-5 divide-y divide-gray-200 xl:col-start-1 xl:row-start-2">
61+
<div className="pt-8">
62+
<Link href="/note">
63+
<a className="text-teal-500 hover:text-teal-600">
64+
← Back to the note
65+
</a>
66+
</Link>
67+
</div>
68+
</footer>
69+
</div>
70+
</div>
71+
</article>
72+
</main>
73+
);
74+
};
75+
76+
export default Note;

layouts/mdx/index.tsx

Lines changed: 0 additions & 80 deletions
This file was deleted.

mdx/config.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import emoji from 'remark-emoji';
2+
const withSyntaxHighlighting = require('remark/withSyntaxHighlighting');
3+
import slug from 'remark-slug';
4+
import autoLinkHeadings from 'remark-autolink-headings';
5+
import footnotes from 'remark-footnotes';
6+
7+
export interface Metadata {
8+
title: string;
9+
date: Date;
10+
tags: string[];
11+
}
12+
13+
export const isMetadata = (v: any): v is Metadata => {
14+
return (
15+
v &&
16+
typeof v.title === 'string' &&
17+
v.date instanceof Date &&
18+
Array.isArray(v.tags) &&
19+
v.tags.every((e: any) => typeof e === 'string')
20+
);
21+
};
22+
23+
24+
export const mdxConfig = {
25+
remarkPlugins: [
26+
withSyntaxHighlighting,
27+
footnotes,
28+
slug,
29+
[
30+
autoLinkHeadings,
31+
{
32+
content: {
33+
// https://heroicons.com/ Outline link
34+
type: 'element',
35+
tagName: 'svg',
36+
properties: {
37+
xmlns: 'http://www.w3.org/2000/svg',
38+
viewBox: '0 0 24 24',
39+
class: '-ml-6 h-5 w-5 hover:text-gray-500 text-transparent',
40+
fill: 'none',
41+
stroke: 'currentColor',
42+
},
43+
children: [
44+
{
45+
type: 'element',
46+
tagName: 'path',
47+
properties: {
48+
strokeLinecap: 'round',
49+
strokeLinejoin: 'round',
50+
strokeWidth: '2',
51+
d:
52+
'M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1',
53+
},
54+
},
55+
],
56+
},
57+
},
58+
],
59+
[emoji, { padSpaceAfter: true }],
60+
],
61+
};

mdx/utils.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import path from 'path';
2+
3+
const dateSortDesc = (a, b) => {
4+
if (a > b) return -1;
5+
if (a < b) return 1;
6+
return 0;
7+
};
8+
9+
const importAll = (r) => {
10+
return r
11+
.keys()
12+
.filter((fileName) => !fileName.includes('pages'))
13+
.map((fileName) => ({
14+
link: fileName.substr(2).replace(/\/index\.mdx$/, ''),
15+
module: r(fileName),
16+
}))
17+
.sort((a, b) => dateSortDesc(a.module.meta.date, b.module.meta.date));
18+
};
19+
20+
export const getAllNotes = () => {
21+
return importAll(require.context('../pages/note/?preview', true, /\.mdx$/));
22+
};

next-env.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/// <reference types="next" />
2-
/// <reference types="next/types/global" />
2+
/// <reference types="next/types/global" />
3+
/// <reference types="next/image-types/global" />

0 commit comments

Comments
 (0)