(publication: any)
| 1 | export const getSitemap = (publication: any) => { |
| 2 | let xml = |
| 3 | '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; |
| 4 | |
| 5 | const domain = publication.url; |
| 6 | const staticPages = publication.staticPages.edges.map((edge: any) => edge.node); |
| 7 | const posts = publication.posts; |
| 8 | |
| 9 | xml += '<url>'; |
| 10 | xml += `<loc>${domain}</loc>`; |
| 11 | xml += '<changefreq>always</changefreq>'; |
| 12 | xml += '<priority>1</priority>'; |
| 13 | |
| 14 | if (posts.length > 0) { |
| 15 | xml += `<lastmod>${posts[0].publishedAt}</lastmod>`; |
| 16 | } |
| 17 | xml += '</url>'; |
| 18 | |
| 19 | for (let i: any = 0; i < posts.length; i += 1) { |
| 20 | xml += '<url>'; |
| 21 | xml += `<loc>${domain}/${posts[i].slug}</loc>`; |
| 22 | xml += '<changefreq>daily</changefreq>'; |
| 23 | xml += '<priority>0.8</priority>'; |
| 24 | if (posts[i].updatedAt) { |
| 25 | xml += `<lastmod>${posts[i].updatedAt}</lastmod>`; |
| 26 | } |
| 27 | xml += '</url>'; |
| 28 | } |
| 29 | |
| 30 | staticPages.forEach((page: any) => { |
| 31 | xml += '<url>'; |
| 32 | xml += `<loc>${domain}/${page.slug}</loc>`; |
| 33 | xml += '<changefreq>always</changefreq>'; |
| 34 | xml += `<priority>${1}</priority>`; |
| 35 | xml += '</url>'; |
| 36 | }); |
| 37 | |
| 38 | const uniqueTags = new Set<string>(); |
| 39 | for (const post of posts) { |
| 40 | if (Array.isArray(post.tags)) { |
| 41 | for (const tag of post.tags) { |
| 42 | uniqueTags.add(tag.slug); |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | uniqueTags.forEach((tag: any) => { |
| 48 | xml += '<url>'; |
| 49 | xml += `<loc>${domain}/tag/${tag}</loc>`; |
| 50 | xml += '<changefreq>always</changefreq>'; |
| 51 | xml += `<priority>1</priority>`; |
| 52 | xml += '</url>'; |
| 53 | }); |
| 54 | |
| 55 | xml += '</urlset>'; |
| 56 | return xml; |
| 57 | }; |
no test coverage detected