GithubHelp home page GithubHelp logo

dylanmeivis / nextjs13-starter-markdoc Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 0.0 72 KB

Next.js 13 starter using Markdoc and TailwindCSS

JavaScript 8.11% TypeScript 91.00% CSS 0.89%
markdoc markdown nextjs nextjs-starter nextjs13 tailwindcss

nextjs13-starter-markdoc's Introduction

This is a Next.js project bootstrapped with create-next-app, Markdoc and Tailwind CSS.

Getting Started

First, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev

Open http://localhost:3000/blog/firstpost with your browser to see the result.

Folder structure

The app/blog/(articles) directory is mapped to /blog/*. Markdown files in this directory are treated as pages.

So simply add a markdown file in app/blog/(articles) and start writing your content.

Different folder for markdown content

You can change the folder you want your markdown content to be in by also changing the ARTICLES_PATH variable in app/blog/[slug]/page.tsx.

Changing rendering of markdown types

You can change the way an markdown element renders by creating an component and linking it to the type in the config.markdoc.tsx. Markdown elements are seen as nodes. See Markdoc Nodes for more information. In this example an custom rendering is created for the heading element with some Tailwind styling, and custom rendering of the paragraph element inside the config.markdoc.tsx file.

Creating custom elements to use inside the markdown file

You can also create custom tags seen als components to use in your markdown file. See Markdoc Tags for more information. This example has en callout component with a title attribute that is passed to the component and used.

frontmatter variables

On the top of your markdown file you can define frontmatter variables.

---
title: TitleVariable
---

These can be used inside your content by referencing them like {% $frontmatter.title %}. In this example these variables are used to dynamically set the metadata of the page. By using the generateMetaData method and gray-matter to retrieve the variables from the markdown file.

Static generation

The method generateStaticParams is used to statically generate the routes at build time. Using Glob to search for all the possible routes by scanning the markdown files in the folder specified in the ARTICLES_PATH variable. Exporting the variable dynamicParams inside [slug]/page.tsx determines if the page tries to dynamically tries to render a page when it was not statically created at build time if the value is TRUE, and redirects the user to the 404 page when the value is FALSE.

Learn More

To learn more about Markdoc, take a look at the following resources:

nextjs13-starter-markdoc's People

Contributors

dylanmeivis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.