-
Notifications
You must be signed in to change notification settings - Fork 0
/
next-sitemap.config.js
65 lines (59 loc) · 1.55 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
53
54
55
56
57
58
59
60
61
62
63
64
65
// next-sitemap.config.js
const { request, gql } = require("graphql-request");
const graphqlAPI = process.env.NEXT_PUBLIC_GRAPHCMS_ENDPOINT;
async function getNewsArticles() {
const query = gql`
query GetNewsArticles {
postsConnection(first: 100, orderBy: createdAt_DESC) {
edges {
node {
slug
title
createdAt
}
}
}
}
`;
const result = await request(graphqlAPI, query);
return result.postsConnection.edges.map(({ node }) => ({
loc: `https://onlyblog.vercel.app/${node.slug}`,
publication_date: node.createdAt,
title: node.title,
}));
}
module.exports = {
siteUrl: "https://onlyblog.vercel.app",
generateRobotsTxt: true,
exclude: ["/admin/**", "/user/**"],
additionalSitemaps: [
{
loc: "/sitemap-news.xml",
lastmod: new Date().toISOString(),
},
],
extraPaths: async (config) => {
const newsArticles = await getNewsArticles();
return newsArticles.map((article) => ({
loc: article.loc,
lastmod: article.publication_date,
}));
},
transform: async (config, path) => {
const articles = await getNewsArticles();
const article = articles.find((article) => article.loc === path);
return {
loc: article ? article.loc : path,
news: article
? {
publication: {
name: "OnlyBlog News",
language: "en",
},
publication_date: article.publication_date,
title: article.title,
}
: undefined,
};
},
};