├── .eslintrc.json
├── .gitignore
├── CONTRIBUTING.md
├── README.md
├── articles
├── post-one.mdx
├── post-three.mdx
└── post-two.mdx
├── jsconfig.json
├── next.config.js
├── package-lock.json
├── package.json
├── pages
├── [slug].js
├── _app.js
├── _document.js
└── index.js
├── public
├── favicon.ico
└── vercel.svg
├── src
├── components
│ └── BlogCard
│ │ ├── index.js
│ │ └── style
│ │ └── blogcard.styled.js
└── utils
│ └── mdx.js
└── styles
├── globals.scss
└── variables.scss
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "next/core-web-vitals"
3 | }
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # next.js
12 | /.next/
13 | /out/
14 |
15 | # production
16 | /build
17 |
18 | # misc
19 | .DS_Store
20 | *.pem
21 |
22 | # debug
23 | npm-debug.log*
24 | yarn-debug.log*
25 | yarn-error.log*
26 | .pnpm-debug.log*
27 |
28 | # local env files
29 | .env*.local
30 |
31 | # vercel
32 | .vercel
33 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## Contributing.
2 |
3 | Hey there, thank you for taking interest in this project. I'd list the steps you can follow to get started in contributing.
4 |
5 | - First, you have to fork this repository. When you do that, you're creating a copy of this repository under your own github account.
6 | - Clone the repository (your own forked version), by doing this...
7 |
8 | ```bash
9 | git clone https://github.com/kaf-lamed-beyt/nextjs-blog-template.git
10 | ```
11 |
12 | - Set the remote upstream of your forked repository to the base respository (i.e. the original repository)
13 |
14 | ```bash
15 | git remote add upstream https://github.com/kaf-lamed-beyt/nextjs-blog-template.git
16 | ```
17 |
18 | - Create a branch and start working your feature.
19 |
20 | ```bash
21 | git checkout -b [branch-name]
22 | ```
23 |
24 | - Save and commit your changes
25 |
26 | ```bash
27 | git add --all
28 |
29 | git commit -m "your message"
30 | ```
31 |
32 | - Push to your branch, create a pull request and wait for it to be merged.
33 |
34 | ```bash
35 | git push origin [branch name]
36 | ```
37 |
38 | ## Happy Hacking!
39 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | If you've always wanted to have a dev blog of your own, this repository is a blog template that I built with Next.js and MDX.
2 |
3 | You can fork or clone the repository and use it and use it as you want.
4 |
5 | ## Overview of the folders and files
6 |
7 | - articles: this directory is where you'll be putting your articles. In it currently are some dummy files `post-one.mdx`, `post-two.mdx`, `post-three.mdx`.
8 |
9 | - src: Is where the magic happens. In it, there are two folders, `components` and `utils`.
10 |
11 | - In the `components` directory, general components like the `BlogCard` component can sit in the root directory of this folder. But,
12 |
13 | - The custom components that are meant for the articles should go into the `mdx-components` directory. This pattern is just so you can keep track of components that can be used without mixing them up.
14 |
15 | You can have components like the custom `codeblock` that holds your code snippets
16 |
17 | ```jsx
18 | import React from "react";
19 | import propTypes from "prop-types";
20 | import { Block } from "./style/codeblock.styled.js";
21 |
22 | const CodeBlock = ({ children, ...props }) => {
23 | return {children};
24 | };
25 |
26 | export default CodeBlock;
27 | ```
28 |
29 | You can add as many custom components that you want in the `src/components/mdx-components` directory.
30 |
31 | The custom MDX components can be imported in `[slug].js` which would eventaully make it available for use in all the `.mdx` files you create in the "articles" directory.
32 |
33 | the generic styles for the codeblock and the unique article itself can be found in `styles/globals.scss`
34 |
35 | - utils: this folder houses the main logic behind this blog template
36 |
37 | - jsconfig.json: gives you the flexibility that doesn't come with traversing the directories in your codebase. With this config file I've been able to create file mappings based on the `baseUrl` of this project.
38 |
39 | So instead of doing something like the snippet below
40 |
41 | ```jsx
42 | import SomeComponent from "./../../path/to/directory/";
43 | ```
44 |
45 | You can simply do this.
46 |
47 | ```jsx
48 | import SomeComponent from "@componentDir/component-name";
49 | ```
50 |
51 | You can also tweak the config file to your taste.
52 |
53 | ```json
54 | {
55 | "compilerOptions": {
56 | "baseUrl": "./",
57 | "paths": {
58 | "@components/*": ["src/components/*"],
59 | "@mdx-components/*": ["src/components/mdx-components/*"],
60 | "@styles/*": ["/styles/*"],
61 | "@utils/*": ["src/utils/*"]
62 | // you can add your file path mappings here
63 | }
64 | }
65 | }
66 | ```
67 |
68 | ### The tools used in building this template
69 |
70 | - gray-matter: parses the content in the .mdx files to readable HTML content.
71 |
72 | ```bash
73 | npm install gray-matter
74 | ```
75 |
76 | - reading-time: assigns an approximate time to read a blog post or article based on the word count.
77 |
78 | ```bash
79 | npm install reading-time
80 | ```
81 |
82 | - next-mdx-remote: does the background compilation of the MDX files by allowing them to be loaded within Next.js' `getStaticProps` or `getServerSideProps` data-fetching method, and hydrated properly on the client.
83 |
84 | ```bash
85 | npm install next-mdx-remote@3.0.8
86 | ```
87 |
88 | Check this [github issue](https://github.com/vercel/next.js/issues/36646) to understand why you shouldn't install the latest version
89 |
90 | - glob: gives us access to match the file patterns in data/articles, which we'll be using as the slug of the article.
91 |
92 | ```bash
93 | npm install glob
94 | ```
95 |
96 | - dayjs: a JavaScript library that helps to parse, manipulate, validate, and display dates that we would be adding to the metadata of each article.
97 |
98 | ```bash
99 | npm install dayjs
100 | ```
101 |
102 | - rehype-highlight: adds syntax highlighting to our code blocks
103 |
104 | ```bash
105 | npm install rehype-highlight
106 | ```
107 |
108 | - rehype-autolink-headings: is a plugin that adds links to headings from h1 to h6
109 |
110 | ```bash
111 | npm install rehype-autolink-headings
112 | ```
113 |
114 | - rehype-code-titles: adds language/file titles to your code snippets
115 |
116 | ```bash
117 | npm install rehype-code-titles
118 | ```
119 |
120 | - rehype-slug is a plugin that adds an id attributes to headings
121 |
122 | ```bash
123 | npm install rehype-slug
124 | ```
125 |
126 | ### Want to contribute?
127 |
128 | Read this [guide](CONTRIBUTING.md) to see how you can contribute to this project.
129 |
--------------------------------------------------------------------------------
/articles/post-one.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Example post one"
3 | publishedAt: "2022-02-16"
4 | excerpt: "example post one"
5 | cover_image: "path/to/where/image/is/stored"
6 | ---
7 |
8 | rest of the content falls here
9 |
--------------------------------------------------------------------------------
/articles/post-three.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Example post three"
3 | publishedAt: "2022-04-22"
4 | excerpt: "example post three"
5 | cover_image: "path/to/where/image/is/stored"
6 | ---
7 |
8 | rest of the content falls here
9 |
10 | This is an `inline code`
11 |
12 | Below is an example of a codeblock
13 |
14 | ```js
15 | let name = "MDX Blog";
16 |
17 | console.log(name);
18 | ```
19 |
--------------------------------------------------------------------------------
/articles/post-two.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Example post two"
3 | publishedAt: "2022-04-20"
4 | excerpt: "example post two"
5 | cover_image: "path/to/where/image/is/stored"
6 | ---
7 |
8 | rest of the content falls here
9 |
10 | ```jsx
11 | import React from "react";
12 |
13 | const Hello = ({ text }) => {
14 | return