Skip to content

Commit

Permalink
doc: nuxt seo stable
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Oct 21, 2024
1 parent 61a907f commit a97c4aa
Show file tree
Hide file tree
Showing 32 changed files with 346 additions and 409 deletions.
15 changes: 15 additions & 0 deletions docs/content/0.getting-started/0.introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: 'Nuxt Sitemap'
description: 'Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.'
navigation:
title: 'Introduction'
---

## Features

- 🌴 Single /sitemap.xml or multiple /posts-sitemap.xml, /pages-sitemap.xml
- 📊 Fetch your sitemap URLs from anywhere
- 😌 Automatic lastmod, image discovery and best practice sitemaps
- 🔄 SWR caching, route rules support
- 🎨 Debug using the Nuxt DevTools integration or the XML Stylesheet
- 🤝 Integrates seamlessly with Nuxt I18n and Nuxt Content
49 changes: 10 additions & 39 deletions docs/content/0.getting-started/1.installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,25 @@ navigation:
title: 'Installation'
---

1. Install `@nuxtjs/sitemap` dependency to your project:
## Module Setup

```bash
npx nuxi@latest module add sitemap
```
:ModuleInstall{name="@nuxtjs/sitemap"}

2. Set Site Config
## Previewing Your Sitemap

It's recommended to always set a canonical site URL to avoid duplicate content issues.
After you've set up the module with the minimal config, you should be able to visit [`/sitemap.xml`](http://localhost:3000/sitemap.xml) to see the generated sitemap.

You can set your site URL in [many ways](/site-config/guides/setting-site-config), the easiest is `nuxt.config` or `.env`:
All pages preset are discovered from your [Application Sources](/sitemap/getting-started/data-sources), for dynamic URLs see [Dynamic URLs](/sitemap/guides/dynamic-urls).

While optional, it's also recommended to set a `name` as this will be displayed on your sitemap.
You can debug this further in Nuxt DevTools under the Sitemap tab.

::code-group
## Next Steps

```ts [nuxt.config.ts]
export default defineNuxtConfig({
site: {
url: 'https://example.com',
name: 'My Awesome Website'
},
})
```
It's recommended to use this module with Nuxt Robots so that the sitemap paths are automatically added to your robots.txt file.

```bash [.env]
NUXT_PUBLIC_SITE_URL=https://example.com
```
::
:ModuleCard{slug="robots" class="w-1/2"}

Sitemap URLs will have their [trailing slashes](/nuxt-seo/guides/trailing-slashes) removed by default. If you want to keep them, you can set the `trailingSlash` option to `true`:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
site: {
// optional: only if you have trailing slashes enabled
trailingSlash: true
},
})
```

3. Preview your Sitemap

After you've set up the module, if you visit `/sitemap.xml` you can see the generated sitemap.

This has been generated with [Application Sources](/sitemap/getting-started/data-sources).

4. Next Steps
Other suggestions:

- You may want to add your own sources, see [Dynamic URLs](/sitemap/guides/dynamic-urls).
- Have 1000's of pages? Consider using [Multiple Sitemaps](/sitemap/guides/multi-sitemaps).
Expand Down
15 changes: 0 additions & 15 deletions docs/content/0.getting-started/3.stackblitz.md

This file was deleted.

59 changes: 59 additions & 0 deletions docs/content/0.getting-started/3.troubleshooting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: "Troubleshooting Nuxt Sitemap"
description: Create minimal reproductions for Nuxt Sitemap or just experiment with the module.
navigation:
title: 'Troubleshooting'
---

## Debugging

### Nuxt DevTools

The best tool for debugging is the Nuxt DevTools integration with Nuxt Sitemap.

This will show you all of your sitemaps and the sources used to generate it.

### Debug Endpoint

If you prefer looking at the raw data, you can use the debug endpoint. This is only enabled in
development unless you enable the `debug` option.

Visit `/__sitemap__/debug.json` within your browser, this is the same data used by Nuxt DevTools.

### Debugging Prerendering

If you're trying to debug the prerendered sitemap, you should enable the `debug` option and check your output
for the file `.output/public/__sitemap__/debug.json`.

## Submitting an Issue

When submitting an issue, it's important to provide as much information as possible.

The easiest way to do this is to create a minimal reproduction using the Stackblitz playgrounds:

- [Dynamic URLs](https://stackblitz.com/edit/nuxt-starter-dyraxc?file=server%2Fapi%2F_sitemap-urls.ts)
- [i18n](https://stackblitz.com/edit/nuxt-starter-jwuie4?file=app.vue)
- [Manual Chunking](https://stackblitz.com/edit/nuxt-starter-umyso3?file=nuxt.config.ts)
- [Nuxt Content Document Driven](https://stackblitz.com/edit/nuxt-starter-a5qk3s?file=nuxt.config.ts)

## Troubleshooting FAQ

### Why is my browser not rendering the XML properly?

When disabling the [XSL](/sitemap/guides/customising-ui#disabling-the-xls) (XML Stylesheet) in, the XML will
be rendered by the browser.

If you have a i18n integration, then it's likely you'll see your sitemap look raw text instead of XML.

![Broken XML because of xhtml namespace.](/sitemap/formatting-error.png)

This is a [browser bug](https://bugs.chromium.org/p/chromium/issues/detail?id=580033) in parsing the `xhtml` namespace which is required to add localised URLs to your sitemap.
There is no workaround besides re-enabled the XSL.

### Google Search Console shows Error when submitting my Sitemap?

Seeing "Error" when submitting a new sitemap is common. This is because Google previously
crawled your site for a sitemap and found nothing.

If your sitemap is [validating](https://www.xml-sitemaps.com/validate-xml-sitemap.html) correctly, then you're all set.
It's best to way a few days and check back. In nearly all cases, the error will resolve itself.
24 changes: 0 additions & 24 deletions docs/content/0.getting-started/4.faq.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/content/0.getting-started/_dir.yml

This file was deleted.

13 changes: 0 additions & 13 deletions docs/content/1.integrations/2.robots.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/content/1.integrations/_dir.yml

This file was deleted.

File renamed without changes.
54 changes: 0 additions & 54 deletions docs/content/2.guides/0.lastmod.md

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
---
title: Nuxt I18n
description: How to use the Nuxt Sitemap module with Nuxt I18n.
title: I18n
description: Setting up a sitemap with Nuxt I18n and Nuxt I18n Micro.
---

Out of the box, the sitemap module will integrate directly with [@nuxtjs/i18n](https://i18n.nuxtjs.org/).
You will need to use v8+ of the i18n module.
## Introduction

I18n configuration can get quite complicated, so it's important to figure out what mode you're using.
Out of the box, the module integrates with [@nuxtjs/i18n](https://i18n.nuxtjs.org/) and [nuxt-i18n-micro](https://github.com/s00d/nuxt-i18n-micro)
without any extra configuration.

## Modes
However, I18n is tricky, you may need to tinker with a few options to get the best results.

## I18n Modes

### Automatic I18n Multi Sitemap

Expand Down
48 changes: 45 additions & 3 deletions docs/content/2.guides/2.images-videos.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Images & Videos
description: Learn how to add images and videos in your sitemap.
title: Images, Videos, News
description: Learn how to add images, videos and news in your sitemap.
---

Generated sitemaps are given the `image` and `video` namespaces by default. This allows you to add images and videos to your sitemap.
Expand Down Expand Up @@ -179,7 +179,48 @@ Each format would be added to your sitemap in the following format:
</video:video>
```

## Opt-out
## News

To add news to your sitemap, you can use the `news` property on the sitemap entry. Only [Google's News sitemap](https://developers.google.com/search/docs/crawling-indexing/sitemaps/news-sitemap) extension is supported.

The TypeScript interface for news is as follows:

```ts
export interface GoogleNewsEntry {
title: string
publication_date: Date | string
publication: {
name: string
language: string
}
}
```

You can implement this as follows:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
sitemap: {
urls: [
{
loc: '/news/nuxt-sitemap-turns-6',
news: [
{
title: 'Nuxt Sitemap Turns 6',
publication_date: '2021-01-01',
publication: {
name: 'Nuxt Sitemap',
language: 'en',
},
}
]
}
]
}
})
```

## Image & Video Opt-out

To opt-out of this behaviour, you can set the `discoverImages` and `discoverVideos` config to `false` respectively.

Expand All @@ -191,3 +232,4 @@ export default defineNuxtConfig({
}
})
```

42 changes: 0 additions & 42 deletions docs/content/2.guides/3.cache.md

This file was deleted.

Loading

0 comments on commit a97c4aa

Please sign in to comment.