• Stars
    star
    1,053
  • Rank 43,788 (Top 0.9 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 2 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The complete SEO solution for Nuxt.

๐Ÿฑ Nuxt SEO Kit

NPM version NPM Downloads GitHub stars

The All-In-One SEO Layer for Nuxt 3.


Status: v1 Released
Please report any issues ๐Ÿ›
Made possible by my Sponsor Program ๐Ÿ’–
Follow me @harlan_zw ๐Ÿฆ โ€ข Join Discord for help

Background

Configuring SEO for Nuxt is a lot of work; it requires installing many modules, configuring them all separately and then figuring out all the meta tags.

What if there was an easier way?

Introducing Nuxt SEO Kit, the all-in-one SEO module for Nuxt 3. Combining all of my SEO modules and the best practices into one, it's the easiest and quickest way to improve your apps SEO.

Modules

Features

๐Ÿค– Search engine visibility solved

  • Get the right content crawled with robot rules (robots.txt, HTTP header, meta tags)
  • Let search engines find your content (sitemap.xml)
  • Structured data for rich search results (Schema.org)
  • Automatic canonical URLs

๐Ÿ”— Enhanced Social Sharing

  • Generate dynamic or static screen social share images
  • Automatic opengraph and twitter meta tags

๐Ÿ˜Œ Find issues before they become a problem

  • Trailing Slashes automatically handled correctly
  • Discover broken links

โœจ And much more

  • Runtime Config Template Tokens
  • Use route rules to manage custom config
  • Use definePageMeta for title, description and image
  • <Breadcrumbs /> - Generate Schema.org compliant breadcrumbs with zero-config
  • More coming soon!

Install

npm install --save-dev nuxt-seo-kit

# Using yarn
yarn add --dev nuxt-seo-kit

Requires Nuxt >= 3.1.0.

Register Layer

nuxt.config.ts

export default defineNuxtConfig({
  extends: [
    'nuxt-seo-kit'
  ]
})

Usage

1. Define Config

For configuration to be accessibility to both the Nuxt App, modules and server, config should be provided in the runtime config.

This also allows you to easily override config for different environments.

nuxt.config.ts

export default defineNuxtConfig({
  runtimeConfig: {
    public: {
      siteUrl: process.env.NUXT_PUBLIC_SITE_URL || 'https://example.com',
      siteName: 'Awesome Site',
      siteDescription: 'Welcome to my awesome site!',
      language: 'en', // prefer more explicit language codes like `en-AU` over `en`
    }
  },
})

2. Add Components

SeoKit

To make the most of Nuxt SEO Kit, you should use the SeoKit component somewhere in your app layout.

This component will set the default meta tags for your app. It's important to have this run before any page-specific meta tags are set.

app.vue

<template>
  <div>
    <SeoKit />
    <NuxtPage />
  </div>
</template>

Done! ๐Ÿฅณ

You have the essentials all set up!

Next steps:

  1. Choose a Schema.org identity
  2. Read the guides below
  3. Scan your site with Unlighthouse to validate any SEO issues

Guide

Modify Title Template

The default title template for your site will be %s %titleSeparator %siteName, unless you change it.

Please read the Runtime Config Template Tokens guide on using the tokens.

If you'd like to change the title separator (the default is โ€“), you can provide the runtime config.

export default defineNuxtConfig({
  runtimeConfig: {
    public: {
      titleSeparator: '|'
    }
  },
})

Otherwise, you can modify the titleTemplate to your liking with nuxt config or using useHead.

export default defineNuxtConfig({
  app: {
    head: {
      titleTemplate: '%pageTitle %titleSeparator %siteName'
    }
  }
})

Generating default OG Images

You can provide all your routes with OG Image generation by simply adding one of the OG Image components or composables to your app.vue.

Please check the Nuxt Og Image docs for full usage.

<template>
  <div>
    <SeoKit />
    <!-- a. Generates browser screenshots for every page -->
    <OgImageScreenshot />
    <!-- b. Generate saotir images for every page (uses the default template) -->
    <OgImageStatic />
    <NuxtPage />
  </div>
</template>

Enabling Trailing Slash

Nuxt SEO Kit allows you to enable global trailing slashes using the runtime config.

This will automatically add trailing slashes to your sitemap and add it as canonical URL.

Note: You will need to still manually write your <NuxtLink> with trailing slashes.

export default defineNuxtConfig({
  runtimeConfig: {
    public: {
      trailingSlash: true,
    }
  },
})

Avoid deploying broken links

By default, Nuxt SEO Kit won't block your builds if 404 links are discovered.

To enable this, you can provide the linkChecker.failOn404 option.

export default defineNuxtConfig({
  linkChecker: {
    failOn404: true,
  }
})

Using .env

It can be useful to change the host name based on which environment you have the nuxt App running on.

You can do this with an .env file and the following keys.

NUXT_PUBLIC_SITE_URL="https://harlanzw.com"
NUXT_INDEXABLE=true

Disabling site indexing

By default, Nuxt SEO Kit will allow search engines to index your site in production environments.

If you want to disable this, you can set indexable to false in your config.

export default defineNuxtConfig({
  runtimeConfig: {
    indexable: false
  },
})

Alternatively, you can set the NUXT_INDEXABLE=false environment variable.

Using the Breadcrumbs component

The Breadcrumbs component is a Schema.org compliant breadcrumbs component.

<template>
  <Breadcrumbs>
    <template #breadcrumb="{ to, title }">
      <NuxtLink :to="to">
        {{ title }}
      </NuxtLink>
    </template>
  </Breadcrumbs>
</template>

It will automatically infer the routes and labels from your Nuxt router.

Firstly, it will check the breadcrumbTitle property on the route meta. If that is not present, it will use the title property.

<script lang="ts" setup>
definePageMeta({
  breadcrumbTitle: 'Breadcrumbs are cool',
})
</script>

Providing page meta

To provide page meta, you can make use of the Nuxt 3.1 feature useSeoMeta, which allows you provide reactive meta tags.

<script lang="ts" setup>
useSeoMeta({
  title: 'Home',
  description: 'Welcome to my website',
  // reactive example
  ogImage: () => someData.value?.image
})
</script>

Alternatively, you can use the definePageMeta function to set page-specific meta tags. Note that this data can not be reactive.

<script lang="ts" setup>
definePageMeta({
  title: 'Home',
  description: 'Welcome to my website',
  image: '/images/home.jpg',
})
</script>

Setting a og:title template

By default, the package sets a template for the og:title that matches the title.

That is %s ${config.titleSeparator} ${config.siteName}.

You can override this by setting a ogTitleTemplate in your config.

export default defineNuxtConfig({
  unhead: {
    ogTitleTemplate: '%s | My Website',
  }
})

FAQ

Why isn't there twitter:* meta tags?

The twitter: prefixed meta tags are only needed when they differ from the og: prefixes, except for the twitter:card tag.

You are welcome to modify the twitter:* meta tags using definePageMeta or useSeoMeta.

Why are pages missing from my sitemap.xml?

This module currently relies on pre-rendering to figure out all of your site routes. If your route isn't being pre-rendered then you will either need to manually add it to the sitemap.xml using hooks or pre-render it.

export default defineNuxtConfig({
  // option a. Add routes to pre-render
  nitro: {
    prerender: {
      routes: [
        '/',
        '/my-hidden-url'
      ]
    }
  },
  // option b. use hooks
  hooks: {
    'sitemap:generate': (ctx) => {
      // add custom URLs
      ctx.urls.push({
        url: '/my-hidden-url',
      })
    }
  }
})

Live Examples

Sponsors

License

MIT License ยฉ 2022-PRESENT Harlan Wilton

More Repositories

1

unlighthouse

Scan your entire site with Google Lighthouse in 2 minutes (on average). Open source, fully configurable with minimal setup.
JavaScript
3,840
star
2

nuxt-delay-hydration

Delayed hydration for progressively enhanced apps. Reduced blocking time and improved Google Lighthouse scores. โšก๏ธ
TypeScript
369
star
3

request-indexing

Find your missing on pages Google and request them to be indexed using the Web Search Indexing API.
TypeScript
313
star
4

nuxt-webpack-optimisations

Make your Nuxt.js webpack builds faster โšก
TypeScript
269
star
5

nuxt-og-image

Enlightened runtime images generated with Vue templates.
TypeScript
268
star
6

harlanzw.com

My personal website built with Nuxt 3 and Nuxt Content 2.
Vue
195
star
7

nuxt-simple-sitemap

Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.
TypeScript
166
star
8

nuxt-schema-org

The quickest and easiest way to build Schema.org graphs for Nuxt.
TypeScript
145
star
9

zhead

All of the TypeScript definitions for <head>.
TypeScript
122
star
10

nuxt-simple-robots

(Migrated to @nuxtjs/robots) Tame the robots crawling and indexing your Nuxt site.
TypeScript
114
star
11

nuxt-link-checker

Find and magically fix links that may be negatively effecting your Nuxt sites SEO.
TypeScript
87
star
12

nuxt-seo-utils

SEO utilities to improve your Nuxt sites discoverability and shareability.
TypeScript
75
star
13

unrouted

Unrouted is a minimal, composable router built for speed, portability and DX
TypeScript
67
star
14

nuxt-site-config

Unifying site config with powerful and flexible APIs, for module authors and users.
TypeScript
65
star
15

harlanzw.com-vitepress

My personal blog built using VitePress and TailwindCSS
Vue
44
star
16

vue-cli-plugin-import-components

๐Ÿ”Œ Automatically import components in your Vue CLI apps.
TypeScript
39
star
17

packrup

Simple utils to pack arrays, objects and strings to a flat object (and back again).
TypeScript
17
star
18

schema-org-graph

Build Schema.org graphs for JavaScript Runtimes (Browser, Node, etc). Improve your sites SEO with quick and easy Rich Results.
TypeScript
16
star
19

laradock-cli

[Unmaintained] Your new best friend for Laradock.
Dockerfile
16
star
20

changelogd

๐Ÿชต Aggressively find a packages changelog (or releases) between versions.
TypeScript
9
star
21

wp-keystone

A Wordpress Boilerplate combining the best libraries and practices
PHP
8
star
22

laravel-swiftype

Swiftype Integration for Laravel
PHP
7
star
23

nuxt-mycelium

๐Ÿ„ TBA ๐Ÿคซ
TypeScript
7
star
24

to-vite-and-beyond-a-history-and-future-of-bundling

Vue
6
star
25

WP-Development-Environment

WorldPress Plugin - Development Environment
PHP
5
star
26

nuxt-seo-ui

Deprecated - Nuxt components with Schema.org and SEO integrations
TypeScript
5
star
27

talk-supercharged-head-management

NuxtNation 2022 Talk - VueUse Head v1
Vue
3
star
28

laravel-modern-mail

TBA
PHP
2
star
29

static

TypeScript
1
star
30

blockfolio-php

Blockfolio SDK for PHP - Unofficial
PHP
1
star
31

penguin-pass

Laravel / PHP Package for kid friendly passwords
PHP
1
star
32

nuxt-og-image-playground

Testing out nitro deployments with nuxt-og-imge.
Vue
1
star