2. Nuxt Usage

Nuxt
JAMStart uses Nuxt.js as the front-end framework. Nuxt is a framework built on top of Vue.js that provides static site generation, server-side rendering, and powerful routing capabilities out of the box. It simplifies the development of Vue.js applications by providing a structured way to organize your code and handle common tasks.
JAMStart leverages Nuxt static site generation feature to create a site that is fast, SEO-friendly, author friendly, and easy to maintain. By design, JAMStart does not use the server or server-side features of Nuxt which allows you to host the website statically and cheaply. If you need the Nuxt server or server-side features, you can always add them later.
The use of Nuxt Content module allows for seamless authoring of blog posts and/or articles in Markdown. Each blog, article, or page is authored in a single Markdown file (with .md extension) and stored in the /content directory. Each Markdown file can include front-matter YAML metadata for titles, descriptions, thumbnails, dates, tags, and other custom data for SEO and social media sharing. The Markdown files are automatically converted into HTML pages with site CSS by Nuxt Content in the static generation phase. This adheres to the separation of content and presentation principle of web design.
Example Markdown Page
---
title: Hello World
description: When I first learned to code, I was told that I should always write a 'Hello, World!' module first.
dateCreated: 2024-05-03
author: John Pennock
keywords: [c_language, hello_world]
isManualImage: true
image: /images/blog/C_KandR.jpg
imageAlt: Front cover of "The C Programming Language" by Kernighan and Ritchie
---
Hello, World!
```c
#include <stdio.h>
int main()
{
printf("Hello World");
return 0;
}
```
Nuxt 3 Directory Structure
Nuxt 4 has been released. JAMStart used Nuxt 3 but chooses to use the Nuxt 4 with minimal changes needed.
Key Files and Directories
| File or Folder | Description |
|---|---|
| /app/app.vue | starting app |
| /app/pages | pages *.vue folder |
| /content | pages *.md folder |
| /app/layouts | layouts folder |
| /app/components | vue custom components folder |
| /app/router.options.js | router options file |
Nuxt 4 Compatibility
Nuxt 4 is imminent and the current Nuxt 3 has a mode that will allow you to future proof the directory structure. Opt-in to the v4 directory structure which means they are going to move the client code from the root to the app folder. You can enable Nuxt 4 compatibility adding the future key in the nuxt.config.ts file.
export default defineNuxtConfig({
future: {
compatibilityVersion: 4,
}
})
Nuxt 4 Changes
| Nuxt 3 | Nuxt 4 |
|---|---|
| /app.vue | /app/app.vue |
| /pages | /app/pages |
| /layouts | /app/layouts |
| /components | /app/components |
Nuxt 4 Unchanged
| Nuxt 3 | Nuxt 4 |
|---|---|
| /content | /content |
| /app/router.options.js | /app/router.options.js |
Nuxt Routing
- A route is created automatically for each page in the
pagesdirectory. A subdirectory will add a level to the route parameter. - Use
<NuxtPage />where you want to pages to appear based on route. Typically, this is in theapp.vuefile, within the<NuxtLayout />element - Add a routing page with a parameter you add
[]to the filename! - Add the parameter name inside the brackets like
[...slug].vue slugmeans where spaces are dash characters - blog post short name
Nuxt Modules
You can browse Nuxt modules here. You install a Nuxt specific package according to the instructions.
Component Names
When a component has a compound name you can either name the file as either
compound-name.vueorCompoundName.vue(my preferred) In either case, when coding the component in the<template></template>section of a page the reference would be<CompoundName></CompoundName>
Data fetching
Nuxt has three built in data fetching methods
useFetchcomposableuseAsyncDatacomposable$fetch
NPM Dependencies
After cloning, you should examine the NPM dependencies and:
- understand what the role of each dependency is in the project and where the documentation is for it
- update any dependencies, at least the minor and patch updates.
- optionally, remove any dependencies you do not need for your project
- get for security updates
Understand the Dependencies
You can do this by using npm outdated'. editing the package.jsonfile and changing the version numbers to the latest versions, or you can use a tool likenpm-check-updates` to automatically update the versions for you.
Key Files and Folders
| Folder | Description |
|---|---|
/ | root folder |
/app | Nuxt.js client folder (v4 compatibility) |
/server | Nuxt.js server folder |
/app/pages | Nuxt.js client pages root folder |
/content | NuxtContent Markdown pages folder |
/app/layouts | Nuxt.js layouts folder |
/app/components | Vue.js custom components folder |
/app/components/content | NuxtContent components folder |
/public | Images and files served live |
/shared/utils | JavaScript shared (client&server) |
Files
| Options and Script Files | Description |
|---|---|
.gitignore | Git ignore options file |
nuxt.config.ts | Nuxt.js options file |
content.config.ts | NuxtContent options file |
tailwind.config.js | Tailwind CSS options |
package.json | NPM package dependency file |
buildspec.yml | AWS CodeBuild script |
tsconfig.json | Typescript options file (not used) |
LICENSE.txt | License file for repo |
README.md | README file for git repo |
| Site Files | Description |
|---|---|
error.vue | Vue page for ERRORS |
/app/app.vue | Vue.js application entry |
/app/pages/*.vue | Nuxt.js pages |
/content/*.md | NuxtContent Content pages |
/content/license.md | License page for website |
/app/layouts/*.vue | Nuxt.js layouts components |
/app/components/*.vue | Vue.js custom components |
/app/components/content | NuxtContent custom components |
/app/router.options.js | Vue.js router options file |
/shared/utils/*.[js,ts] | JavaScript shared (client&server) |
Content Pages
at /content
| Page | File | Description/Purpose |
|---|---|---|
| Home | /index.md | show code/pre blocks with styling |
| About | /about.md | no frills content page |
| Articles Home | /articles/index.md | longer form content |
| Articles | /articles/*.md | a set of articles |
| Git Repo | gitprojects.md | shows external API usage |
| Blog Home | blog/index.md | blog list |
| Blog Posts | blog/202x/*.md | a set of posts |
NuxtContent Controls
at /app/components/content
| Custom Control File | Description/Purpose |
|---|---|
CollectionList.vue | parent list of posts, used in both articles and blog |
FigureCaption.vue | A centered full-width block image with a caption |
GitList.vue | retrieves a list of GitHub repos |
MonkInset.vue | Floats an image or text with content flowing around it. |
TocLinks.vue | Creates a table of contents for page. |
Vue Controls
at /app/components
| Custom Control File | Description/Purpose |
|---|---|
ColorModeSelector.vue | control to toggle dark modes |
Footer.vue | bottom menu |
TopMenu.vue | top menu |
Dependencies
from /package.json
"dependencies": {
"@nuxt/content": "^3.1.1",
"@stefanobartoletti/nuxt-social-share": "^1.2.0",
"nuxt": "^3.6.0",
"nuxt-cloudflare-analytics": "^1.0.8",
"remark-unwrap-images": "^4.0.0",
"vue": "^3.4.21",
"vue-router": "^4.3.0"
},
"devDependencies": {
"@nuxt/devtools": "^0.0.1",
"@nuxtjs/color-mode": "^3.3.3",
"@nuxtjs/tailwindcss": "^6.11.4",
"@tailwindcss/typography": "^0.5.13"
}
}
Essentially, the dependencies are:
- Nuxt.js v3
- Nuxt Content v3
- Nuxt Devtools - (for debugging)
- Nuxt Color Mode - (for dark modes)
- Nuxt Tailwind CSS - style
- Tailwind Prose and Typography - Content Readability
- Nuxt Social Share buttons
- Nuxt CloudFlare Analytics - Cookie-free CloudFlare Analytics for static site