Last active
September 7, 2020 08:37
-
-
Save PCreations/f40d22fa849ae6035d0dd5b894870e6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createIsRecentArticle } from "./is-recent-article"; | |
import { articleToXml } from "./article-to-xml"; | |
import { createExecuteLatestArticlesQuery } from "./execute-latest-articles-query"; | |
import { createS3xmlUploader } from "./s3-xml-uploader"; | |
export const createRecentArticlesSitemap = ({ | |
todayDate, | |
executeLatestArticlesQuery = createExecuteLatestArticlesQuery(), | |
s3xmlUploader = createS3xmlUploader({ bucketName: process.env.S3_BUCKET }), | |
}) => { | |
const isRecentArticle = createIsRecentArticle(todayDate); | |
return async ({ domain, language }) => { | |
const articles = await executeLatestArticlesQuery({ | |
domain, | |
graphQLEndpoint: process.env.GRAPHQL_ENDPOINT, | |
}); | |
const xmlString = `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">${articles | |
.filter(isRecentArticle) | |
.map((article) => articleToXml({ language, article })) | |
.join("")}</urlset>`; | |
return s3xmlUploader.upload({ domain, xmlString }); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment