There seems to be an issue with the next-sitemap image location showing as undefined in the sitemap

I am having an issue with creating a sitemap in image:loc. When I view my xml in the browser, loc is showing as undefined. The goal is to display images present in blogs. Additionally, when I use console.log, the link displays in the terminal but shows as undefined in the browser.

Currently, in the code, I have inserted a string in loc just for testing purposes. Once loc is displayed correctly in the browser, I will update it accordingly.

Note: I attempted using the custom Transform function (next-sitemap.config.js) provided by the next-sitemap library but encountered the same issue of image: loc showing up as undefined.

Blogs Sitemap: enter image description here

Blogs Object: (need the image shown in the data object)

{
  status: 200,
  data: [
    {
      _id: '6511c2cbc3ae7d1923a19a52',
      slug: 'buying-gold-in-toronto:-tips-for-local-investors',
      status: 'Publish',
      meta: [Object],
      image: 'Chapters_GTA-Page.png',
      title: 'Buying Gold in Toronto: Tips for Local AU Bullion',
      categories: [Array],
      createdAt: '2023-09-25T17:26:35.580Z'
    },
    {
      _id: '6511d646c3ae7d1923a19f5f',
      slug: 'the-2024-1-oz-gold-kangaroo-coin-from-the-perth-mint',
      status: 'Publish',
      meta: [Object],
      image: '024-kangaroo-gold-coin.jpeg',
      title: 'The 2024 1 Oz Gold Kangaroo Coin from The Perth Mint',
      categories: [Array],
      createdAt: '2023-09-25T18:49:42.943Z'
    },
  ],
  totalBlogs: 3
}

Index.js


import { getServerSideSitemapLegacy } from "next-sitemap";
import { GetServerSideProps } from "next";
import axiosInstance from "../../helper";
import { siteUrl, transform } from "../../next-sitemap.config";

export const getServerSideProps = async (ctx) => {

  const response = await fetch(
    `${axiosInstance.defaults.baseURL}/getallblogs`,
    { next: { revalidate: 3600 } }
  );
  const blogs = await response.json();
  
  console.log(blogs);

  const fields = blogs.data.map(({ slug }) => {
    return {
      loc: `${siteUrl}/blogs/${slug}`,
      lastmod: new Date().toISOString(),
      images: [{ loc: "image.jpg" }],
    };
  });

  return getServerSideSitemapLegacy(ctx, fields);
};

// Default export to prevent next.js errors
export default function Sitemap() {}

next-sitemap.config.js

// const siteUrl = "http://localhost:3000";

module.exports = {
  siteUrl: process.env.SITE_URL || "http://localhost:3000",
  generateRobotsTxt: true,
  sitemapSize: 7000,
  exclude: [
    "/blogs-sitemap.xml",
    "/products-sitemap.xml",
    "/checkout",
    "/cart",
    "/account",
    "/orderplaced",
    "/profile",
  ],
  transform: async (config, path) => {
    return {
      loc: path, // => this will be exported as http(s)://<config.siteUrl>/<path>
      lastmod: config.autoLastmod ? new Date().toISOString() : undefined,
      images: [{ loc: "image.jpg" }],
    };
  },
  sitemapSize: 7000,
  robotsTxtOptions: {
    policies: [
      {
        userAgent: "*",
        allow: "/",
      },
      {
        userAgent: "test-bot",
        allow: ["/path", "/path-2"],
      },
      {
        userAgent: "black-listed-bot",
        disallow: ["/sub-path-1", "/path-2"],
      },
    ],

  },
};

If you can provide guidance on how to properly display the image in image:loc in the sitemap, that would be greatly appreciated.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Chrome developer tools are unable to locate the HttpRequest

While working in Python, I am utilizing the requests library to make a POST request to a specific URL. However, upon clicking the button, it seems that nothing is happening as per Chrome Developer Tools. No XHR requests are being made and no data is being ...

Utilizing Zoomdata data in conjunction with echarts index.js to create a dynamic stacked line chart

I am currently working on integrating Zoomdata with an echarts javascript chart to visualize data from 20 different computers in a stacked line chart format. While I can manually code this setup, I am looking for a way to dynamically link the data from Zoo ...

What is the best way to ensure the checkbox functions correctly in this specific situation?

I am utilizing PHP, Smarty, and jQuery in the development of my website. Currently, I am working on implementing checkboxes within a Smarty template. Below is a snippet of my Smarty code related to checkboxes: <table cellpadding="5" cellspacing="0" bor ...

What is the best approach to modifying array elements using onChange and hooks in React?

I'm struggling to implement something simple, and the solutions I've found so far don't quite address my specific issue. Here's the state in question: const [formFields, setFormFields ] = useState({ formTitle: '', fiel ...

PHP can be executed and accessed directly from JavaScript without the need for any form submission

While I have come across a lot of information on PHP post/get methods for transmitting data, I find myself stuck with an interesting issue that requires some assistance. My HTML page contains data in different inputs, and I run algorithms on the JavaScrip ...

What is the best way to create dynamic locales in NextJS?

My current project involves implementing dynamic routes in a NextJS project. The language options for these routes are generated dynamically, as shown in the following examples: localhost:3000/en/route1 --> English language support is available for Rou ...

Exploring a custom hook with Jest testing

I have developed a custom hook that can display a notification message and automatically remove it after 2 seconds. I am looking to write a test for this functionality, but as someone new to writing tests, I'm unsure of the best approach. Can anyone p ...

The Javascript function is designed to function exclusively with onclick events or setTimeout functions

I am currently working on a website that I want to be responsive to the window size. However, I am facing an issue with vertical alignment. I have created a jQuery function to handle this, and it works well for divs with images but not so well for a div wi ...

Is there a way to ensure that a "catch all other" route in the Vue Router will also capture the URL if a portion of it matches a predefined route?

After following the suggestion to implement a catch all route from this article, I realized that it does not capture URLs that partially match a defined route. routes: [ { path: "/album/:album", name: "album", component: Album, } ...

I am unable to access Angular $scope in the HTML Template, although I can view it in the console log

I have been following some online tutorials and using the angularjs-template to start learning Angular. However, I am facing an issue where the page (html template) is not updating with the controller. It seems like there is a problem in how I've set ...

Targeting props within a Class Component: A Step-by-Step Guide

I am currently working on a MultiStep Form project. On the final page of the form, my goal is to push all the collected data to Firebase. I have been utilizing props and states to pass values from one page to another. However, I'm facing an issue in t ...

Unfortunately, I am unable to utilize historical redirection in React

When an axios request is successfully completed, I want to redirect. However, I am encountering an error that looks like this: Below is the code snippet: import React, { useState, Fragment } from "react"; import Sidebar from "../../User/Sid ...

Creating a connection to an external website through a JavaScript function within an Angular application

I am currently working on an Angular application. Within the index.html file, there is a header that contains links to external websites. <a href="#" onclick="getExternalUrl('about.html');">Click here </a> <scr ...

ways to verify ng-if post modification occurrence

Currently, my project is utilizing Angular 6. In the code, there is a div element with *ng-if="edited" as shown below: <div *ngIf="edited"> {{langText}} </div> Initially, when the page loads, edited is set to false and the div is not vis ...

Looping through multiple AJAX calls

I have come across numerous questions on this topic, but I am still struggling to find a solution that will make my code function correctly. There is a specific function for calling AJAX that I am unable to modify due to security restrictions. Here is how ...

What is the process for appending a file extension to a Next.js URL?

For instance, I am attempting to redirect the URL : https://example.com/data/publications to this : https://example.com/data/publications.json I made an attempt using Next.js redirection, but encountered difficulty when trying to add a string that does no ...

The getImageData function is returning undefined RGB values

I am trying to create a feature where by clicking on an image, I can retrieve the RGB values of that specific pixel. Below is the code snippet I have implemented: <html> <body> <canvas id="kartina" width="500" height="500"></canvas&g ...

Setting up a NextJS development server in a docker environment with networking

Currently, my development environment consists of a NextJS app running in a docker-compose setup under the name frontend. The backend is powered by an expressjs app known as backend. In my NextJS app, there's an environment variable that specifies t ...

Customize Joomla content in a component by using CSS within a template that I personally designed

Is there a way to customize the text content of a component in Joomla by editing the body text? The CSS properties for #content are adjusting padding, margin, border, width, height, and background but not affecting font attributes... Inside index.php < ...

Can someone explain why my Laravel route is consistently showing a 404 error?

Currently, I am attempting to perform an AJAX request for a form post type. However, the PHP parse script I am trying to send the data to is returning a 404 error as observed through Chrome developer tools. Below is the code snippet: <script type="text ...