-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext-sitemap.config.js
52 lines (49 loc) · 1.36 KB
/
next-sitemap.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/** @type {import('next-sitemap').IConfig} */
module.exports = {
siteUrl: "https://yourdomain.com/",
generateRobotsTxt: true,
robotsTxtOptions: {
policies: [
{
userAgent: "*",
allow: "/",
},
],
},
transform: async (config, path) => {
const response = await fetch(`http://localhost:3000/api/posts`);
const posts = await response.json();
const videoPostIndex = posts.findIndex((post) => {
// const postUrl = new URL(post.link);
console.log(post.link, path);
console.log(post.link === `${path}/`);
return post.link === `${path}/`;
});
return {
loc: path,
changefreq: config.changefreq,
priority: config.priority,
lastmod: new Date().toISOString(),
...(videoPostIndex > -1
? {
videos: [
{
title: posts[videoPostIndex].title,
description: posts[videoPostIndex].title,
contentLoc: {
href: `${path}#FeaturedVideo`,
},
publicationDate: new Date(
posts[videoPostIndex].date
).toISOString(),
thumbnailLoc: {
href: posts[videoPostIndex].video_thumbnail.url,
},
live: false,
},
],
}
: {}),
};
},
};