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

Tally up various figures in all tables

I am dealing with a dynamic table generated from a PHP loop. Below is an example of the table structure extracted from the browser source code: <table class="table"> ... (table content) </table> <table class="table"> ... (t ...

Vue - Utilizing mapState in Vuex to display the contents of the first object within an array

I am trying to display the names array from the first object in players using mapState with Vuex. Currently, the objects in players are listed based on their titles, but I want to filter them based only on the names in the first object for the current page ...

Setting up a Node.js application with Nginx on DigitalOcean

While running my application on a DigitalOcean droplet using nginx, I encountered a peculiar issue. The app runs perfectly fine with http, but when switching to https, nginx throws a 502 BAD GATEWAY error. Despite trying various DigitalOcean guides and sco ...

Encountering a node-sass error while attempting to build due to upgrading node version

Currently, I am working on a Node v10.19.0 / Nextjs8 project locally and looking to upgrade to Next version 11. To begin the process, I decided to update the node version itself to 12.14.0 (or maybe 12.20.1?). However, this led to encountering 2 errors: &g ...

Creating a mandatory 'Select' component in Material UI with React JS

Is there a method to show an error message in red until a choice is selected? ...

Utilizing shared functions defined across different controllers

Can I utilize the code within these controllers for other purposes? .controller('GenericController', ['$scope', '$controller', '$rootScope', '$dialogs', '$state', '$http', '$modal& ...

The comparison between StrictNullChecks and Union Types in terms of syntax usage

Understanding StrictNullChecks in TypeScript Traditionally, null and undefined have been valid first class type citizens in JavaScript. TypeScript formerly did not enforce this, meaning you couldn't specify a variable to potentially be null or unde ...

Creating a JSON schema in JavaScript using an already established JSON framework

I have a json structure stored in a variable called "data" that looks like this: { "SearchWithMasterDataDIdAndScandefinitionDAO": [ { "dateDm_id": 20120602, "issueValue": "ELTDIWKZ", "scanName": "Company Stored as Person (Give ...

Ensure that all items retrieved from the mongoDB query have been fully processed before proceeding further

In the midst of a challenging project that involves processing numerous mongoDB queries to display data, I encountered an issue where not all data was showing immediately upon page load when dealing with large datasets. To temporarily resolve this, I imple ...

Avoid connecting HTML input elements with both JavaScript and Java models

I am troubleshooting an issue with my login page code. <div ng-show="!loggedIn()"> <form ng-submit="login()"> Username: <input type="text" ng-model="userName"/> Password: <input ...

How can I access the id_lang variable in React JS from outside its scope?

How do I access the 'id_lang' variable outside of the render function in order to pass it down for checking? const Navbar = () => { const getID = async (id) => { let id_lang = id; console.log(id_lang); } ret ...

Combining Various Data Types in a Flexible List

I'm looking for a way to dynamically add rows to a table. Right now, I have the input type on the server (whether it's int, bool, string, etc), but I want to know how to implement a field accept combobox. Here is the code in cshtml: <tr ng-r ...

Any tips for filtering an array within an array of objects using the filter method?

I have an array of products and models that I am currently filtering based on 'id' and 'category'. var app = angular.module("myApp", []); app.controller("myCtrl", function($scope) { $scope.products = [{ 'id': 1, ...

Solving the error message "window is not defined" in Nextjs

Hey, I'm attempting to create a component similar to [this tutorial][1] in my NextJS app but I'm running into an error ReferenceError: window is not defined //Navbar.js import styles from "../styles/Navbar.module.css"; export default fu ...

Script to pop up cancel alert box

There's a dilemma with this code - if you click CANCEL the first time the box pops up, it continues to run. I'm unsure of how to make it redirect to the underlying page when clicked on cancel for the first time. var numero= prompt ("Enter a nu ...

Puppeteer causes Express to stop listening to incoming requests

As I work on developing a straightforward API that utilizes Puppeteer to execute actions, I encounter an issue where my Express app stops listening once Puppeteer is launched. Below is the script in question: const Apify = require('apify'); cons ...

When I test my jQuery scripts in jsfiddle, they run smoothly. However, they do not seem to work properly when I

My code is almost perfect, but the jQuery function is giving me trouble. It works fine in jsfiddle, but for some reason, it's not functioning in my HTML file. I don't believe extra characters are being added when copying from the HTML file. I hav ...

Node/Express unexpectedly returning string instead of Array after parsing JSON file

Having difficulty parsing an empty (stringified) Array from a JSON file. Instead of returning an empty array, I am receiving a string. The initial set up of my JSON file is: "[]" I am storing the parsed data in a variable using File System let parsedOb ...

What is the best way to search a map object that serves as the document ID in Firebase?

I am attempting to retrieve all fieldnames within the payload > (random doc id) objects. https://i.sstatic.net/y9703.png At this moment, my approach involves fetching other collections using the following code: async fetchPage() { const query = fir ...

Production environment is not recognizing Next JS environment variables

In the Next.js documentation, it states that you should declare your environment variables in next.config.js under the env key in order to access them at build time: env: { GOOGLE_ANALYTICS_ID: process.env.GOOGLE_ANALYTICS_ID }, While this setup wor ...