In this post I will walk you through how I created this blog
Nuxt.js is a free and open source web application framework based on Vue.js, Node.js, Webpack and Babel.js. You can also create Static sites and server side rendered webapp with nuxt. It abstracts most of the complex configuration involved in managing things like asynchronous data, middleware, and routing.
Create nuxt app using below command
yarn create nuxt-app <project-name>
You can choose to add nuxt content module while project create. Or you can add it manually https://content.nuxtjs.org/installation
yarn add @nuxt/content
Navigate to https://tailblocks.cc/
Choose any header footer and content blocks you like.
Add these blocks to nuxt layouts/default.vue
file
<div>
<Header></Header>
<Nuxt/>
<Footer></Footer>
</div>
<Nuxt/>
will render pages as per routes.
Add pages/index.vue
and pages/blog/index.vue
they will serve on /
and /blog
route.
Put homepage content in pages/index.vue
and blog layout in pages/blog/index.vue
create a content/
directory in your project:
content/
blogs/
article-1.md
article-2.md
home.md
In Each article.md
file you can add your content as below
---
title: Introduction
description: Learn how to use @nuxt/content.
---
## Markdown content
more details...
You need to fetch all posts as below and display in your vue template
async asyncData({ $content }) {
const posts = await $content('blog').fetch()
return {
posts,
}
},
posts
variable will have all posts from that folder, you can loop over and display them in any format. There are various ready to use blocks here https://tailblocks.cc/
Further you can create a pages/blog/_slug.vue
this will show content for route /blog/article-1
.
You need to fetch individual post as below and display in your vue template
async asyncData({ $content, params }) {
const post = await $content('blog', params.slug).fetch()
return { post }
},
After you have created the blog setup, static build can be generated by using below command
nuxt generate //or
npm run generate
You can easily host project from github on netlify.
npm run generate
dist
.