Cookie Consent by Free Privacy Policy Generator Aktuallisiere deine Cookie Einstellungen ๐Ÿ“Œ NextJS Add XML Sitemap


๐Ÿ“š NextJS Add XML Sitemap


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

An XML sitemap is a file that lists all the URLs for your site, it helps search engines discover and index your content. In this post, we'll add an XML sitemap to our NextJS blog.

There are 2 ways you can add an XML sitemap to your blog, you can either add it manually to the public folder or you can generate it dynamically.

As we're working with a NextJS blog that is going to change content from markdown files we don't want to manually change the sitemap every time we add a new post. Instead, we'll generate the sitemap dynamically.

To do this create a sitemap.tsx file inside your app directory. First we need to import the Next MetadataRoute type. This will allow us to define the sitemap route.

Then we'll need to fetch all the posts for the blog and return the slugs for them.

import { MetadataRoute } from 'next'
import { getPosts } from "@/lib/blog/api";
import { SITE_URL } from "@/lib/constants";

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const posts = getPosts();

  const home = {
    url: SITE_URL,
    lastModified: new Date().toString(),
  };

  const postUrls = posts.map(({ slug, createdAt }) => ({
    url: `${SITE_URL}/${slug}`,
    lastModified: createdAt,
  }));

  return [home, ...postUrls]
}

This will generate a sitemap with the home page and all the blog posts. To test this is working you can run the following command:

npx next start

Then navigate to http://localhost:3000/sitemap.xml and you should see the sitemap.

Next we can make sure that search engines can find the sitemap by adding it to the robots.txt file. Create a robots.txt file in the public directory and add the following:

User-agent: *
Allow: /

Sitemap: http://localhost:3000/sitemap.xml
...



๐Ÿ“Œ NextJS Add XML Sitemap


๐Ÿ“ˆ 50.29 Punkte

๐Ÿ“Œ Mambo sitemap 2.0.0 sitemap.xml.php mosConfig_absolute_path privilege escalation


๐Ÿ“ˆ 47.65 Punkte

๐Ÿ“Œ Generate sitemap.xml and robots.txt in Nextjs


๐Ÿ“ˆ 43.37 Punkte

๐Ÿ“Œ Content*Builder sitemap/sitemap.inc.php path[cb] privilege escalation


๐Ÿ“ˆ 39.71 Punkte

๐Ÿ“Œ NextJS examples: 60 popular websites built with NextJS and headless CMS


๐Ÿ“ˆ 31.15 Punkte

๐Ÿ“Œ 3 Exciting Improvements Between NextJS 14 And NextJS 13


๐Ÿ“ˆ 31.15 Punkte

๐Ÿ“Œ What is NextJs?ย  Why Should You Use it in 2023?ย  NextJs Pros and Cons Guide


๐Ÿ“ˆ 31.15 Punkte

๐Ÿ“Œ What is sitemap.xml, and Why a Pentester Should Care, (Mon, Dec 11th)


๐Ÿ“ˆ 27.8 Punkte

๐Ÿ“Œ Add Sitemap in Next.js 14 [Static & Dynamic]


๐Ÿ“ˆ 26.78 Punkte

๐Ÿ“Œ Add a Dynamic Sitemap to Next.js Website Using Pages or App Directory


๐Ÿ“ˆ 26.78 Punkte

๐Ÿ“Œ PHP up to 5.5.34/5.6.20/7.0.5 XML ext/xml/xml.c xml_parse_into_struct second memory corruption


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ Zabbix up to 1.8.20/2.0.12/2.2.4/2.3.1 XML Data XML Request XML External Entity


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ Redwood SAP Business Process Automation XML Data XML Document XML External Entity


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ PHP bis 5.5.34/5.6.20/7.0.5 XML Handler ext/xml/xml.c xml_parse_into_struct second Pufferรผberlauf


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ IBM WebSphere DataPower Appliance up to 7.6 XML XML Data XML External Entity


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ LoboEvolution XML Parser XML File XML External Entity


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ Fortify Software Security Center 17.1/17.2/18.1 XML Data XML Request XML External Entity


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ Stroom up to 5.4.4 XML Parser XML File XML External Entity


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ UML Designer up to 8.0.0 XML Parser XML File XML External Entity


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ PHP bis 5.5.34/5.6.20/7.0.5 XML Handler ext/xml/xml.c xml_parse_into_struct second Pufferรผberlauf


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ SAP HANA Extended Application Services 1 XML Validation XML Document XML External Entity


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ PrinterOn 4.1.4 XML Data XML Request XML External Entity


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ Dell EMC OpenManage Server Administrator up to 9.1.0.2/9.2.0.3 XML Data XML Request XML External Entity


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ Axentra Firmware XML Data xml XML External Entity


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ Jeesite 1.2.7 XML Data ActProcessService.java convertToModel() XML File XML External Entity


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ CVE-2022-45397 | OSF Builder Suite XML Linter Plugin up to 1.0.2 on Jenkins XML Parser xml external entity reference


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ CVE-2019-18213 | Red Hat XML Language Support up to 0.9.0 LSPXMLParserConfiguration.java XML Document xml injection


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ CVE-2013-4857 | D-Link DIR-865L /router_info.xml XML File xml injection (OSVDB-97757)


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ CVE-2019-14678 | SAS XML Mapper 9.45 XML Data xml external entity reference


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ CVE-2018-20687 | Raritan CommandCenter Secure Gateway up to 7.x XML Data .* XML Request xml external entity reference (ID 155359)


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ CVE-2019-19702 | modoboa-dmarc Plugin 1.1.0 on Modoboa XML Data XML Document xml injection (Issue 38)


๐Ÿ“ˆ 23.83 Punkte

๐Ÿ“Œ Add rate limits to NextJS APIs


๐Ÿ“ˆ 22.5 Punkte

๐Ÿ“Œ How to add YouTube Analytics Api to get the channel statistics with React and nextJs?


๐Ÿ“ˆ 22.5 Punkte

๐Ÿ“Œ NextJS Add RSS Feed to Blog


๐Ÿ“ˆ 22.5 Punkte

๐Ÿ“Œ NextJS Add Metadata


๐Ÿ“ˆ 22.5 Punkte











matomo