Skip to content

Instantly share code, notes, and snippets.

@PCreations
Last active September 7, 2020 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PCreations/f40d22fa849ae6035d0dd5b894870e6a to your computer and use it in GitHub Desktop.
Save PCreations/f40d22fa849ae6035d0dd5b894870e6a to your computer and use it in GitHub Desktop.
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