Markdown
This blog uses Markdown, with GitHub's flavor1. To parse the markdown it uses some remark and rehype (unified) packages like next-mdx-remote
and next-prism
.
https://github.com/timlrx/tailwind-nextjs-starter-blog
Table of Contents
Title 1
Title 2
Title 3
Title 4
Title 5
This is normal text.
This is bold text.
This is italics text.
This is a footnote reference 2
- Item 1
- Item 2
- Item 3
- Item 1
- Item 2
- Item 3
This is inline code
.
Next is a code block in Python 🐍:
def fib():
a, b = 0, 1
while True: # First iteration:
yield a # yield 0 to start with and then
a, b = b, a + b # a will now be 1, and b will also be 1, (0 + 1)
for index, fibonacci_number in zip(range(10), fib()):
print('{i:3}: {f:3}'.format(i=index, f=fibonacci_number))
In the new computer age the proliferation of typefaces and type manipulations represents a new level of visual pollution threatening our culture. Out of thousands of typefaces, all we need are a few basic ones, and trash the rest.
— Massimo Vignelli
Next is the author of the bible:
GitHub flavor
This is an autolink: https://www.example.com/
This is an automail: example@example.com
This was mistaken text
This text is extremely important
All this text is important
First Header | Second Header |
---|---|
Content from cell 1 | Content from cell 2 |
Content in the first column | Content in the second column |
- Finish my changes
- Push my commits to GitHub
- Open a pull request
Images
For images it uses the next/Image
react component, for convenience a script replaces the markdown img
tag to the correct Image
component. You can also call it directly inside MDX but need to specify width and height.
<Image src="/static/images/avatar.jpg" alt="Picture of the author" width={500} height={500} />
We use this react component because it:
- Optimizes images (30% more than jpeg).
- Makes them responsive.
- Applies lazy loading (loads them on demand).
- Easy to organize using flexbox and tailwind css.
This comes at the cost of a call to a CDN highly optimized image server that only Vercel hosting fully supports. You could use another package like next-optimized-images
however most of them use webpack and with higher load times, you could use other hosting options like Imgix or Cloudinary or you could disable the processing entirely by deleting lib/img-to-jsx.js
and it's references. Also some browsers will treat the image with the webp
format.
Example Gallery:
Math
We can parse and display math equations with remark-math
and rehype-katex
that use KaTeX. Both are enabled in _document.js
for every page.
For inline math use the $
symbol like this.
For math code blocks use the $$
symbol.
Result:
Given:
Finally:
Template
This template is a Next.js and Tailwind CSS 2.0 starter. You can see the demo a real example or the inspiration behind it. The design is mostly a copy of the Tailwind Blog. It has most of the features of the popular Beautiful Jekyll starter, including: Good lighthouse score, lightweight with preact
, responsive, dark theme, MDX for JSX code, syntax highlighting using rehype-prism
, math with KaTeX, image optimization with next/image
, data retrieval with next-mdx-remote
, SEO, RSS, Sitemap, and Heroicons.
Quick start
npx degit https://github.com/timlrx/tailwind-nextjs-starter-blog.git
- Personalize
siteMetadata.json
,projectsData.js
,headerNavLinks.js
- Run
npm install
,npm rebuild
. - Add mdx or md blog posts to
Pages/Blog
. - Run
npm run build
,npm run dev
. Deploy to Vercel. - Style it with
css/tailwind.css
. - Pass JSX or React components by adding them to
components/MDXComponents.js
Posts use the Hugo Standard frontmatter meaning they require a title (string), date (YY-MM-DD) and tags (array). Optional fields are lastmod (YY-MM-DD), draft (boolean), summary (string), images (array). Also the script compose.js
creates a prefilled frontmatter post, use it by running node ./scripts/compose.js "PostTitle".md
Footnotes
Markdown is a plain text format developed by John Gruber in 2004 as a syntax and Perl script to convert MD to HTML. The main goal was to develop a way to write readable plan text that could be used as HTML. Many implementations of the script or flavors of the syntax have been made like the popular GitHub's flavor. ↩
Footnote reference text or link. ↩