UNPKG

@forge42/seo-tools

Version:

Framework agnostic set of helpers designed to help you create, maintain and develop your SEO

66 lines (65 loc) 6.01 kB
"use strict";var f=Object.create;var p=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var v=(e,t)=>{for(var i in t)p(e,i,{get:t[i],enumerable:!0})},u=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of y(t))!$.call(e,n)&&n!==i&&p(e,n,{get:()=>t[n],enumerable:!(r=x(t,n))||r.enumerable});return e};var c=(e,t,i)=>(i=e!=null?f(S(e)):{},u(t||!e||!e.__esModule?p(i,"default",{value:e,enumerable:!0}):i,e)),R=e=>u(p({},"__esModule",{value:!0}),e);var A={};v(A,{generateRemixSitemap:()=>I});module.exports=R(A);var w=c(require("url-pattern")),E=e=>e.replaceAll(/>\s+</g,"><").replaceAll(/\s+([^<>\s][^<>]*[^<>\s])\s+/g," $1 ").replaceAll(/(\s+)/g," ").trim();var b=e=>e?e?.map(t=>` <video:video> <video:title>${t.title}</video:title> <video:description>${t.description}</video:description> <video:thumbnail_loc>${t.thumbnailUrl}</video:thumbnail_loc> <video:content_loc>${t.contentLocation}</video:content_loc> <video:player_loc>${t.playerLocation}</video:player_loc> ${t.duration?`<video:duration>${t.duration}</video:duration>`:""} ${t.expirationDate?`<video:expiration_date>${t.expirationDate}</video:expiration_date>`:""} ${t.rating?`<video:rating>${t.rating}</video:rating>`:""} ${t.viewCount?`<video:view_count>${t.viewCount}</video:view_count>`:""} ${t.publicationDate?`<video:publication_date>${t.publicationDate}</video:publication_date>`:""} ${t.familyFriendly?`<video:family_friendly>${t.familyFriendly}</video:family_friendly>`:""} ${t.restriction?`<video:restriction relationship="${t.restriction.relationship}">${t.restriction.value}</video:restriction>`:""} ${t.platform?`<video:platform relationship="${t.platform.relationship}">${t.platform.value.join(" ")}</video:platform>`:""} ${t.requiresSubscription?`<video:requires_subscription>${t.requiresSubscription}</video:requires_subscription>`:""} ${t.uploader?`<video:uploader${t.uploader.url?` info="${t.uploader.url}"`:""}>${t.uploader.name}</video:uploader>`:""} ${t.live?`<video:live>${t.live}</video:live>`:""} ${t.tags?t.tags.map(i=>`<video:tag>${i}</video:tag>`).join(` `):""} </video:video> `).join(` `):"",D=e=>e?e?.map(t=>` <news:news> <news:publication> <news:name>${t.publication.name}</news:name> <news:language>${t.publication.language}</news:language> </news:publication> <news:publication_date>${t.publicationDate}</news:publication_date> <news:title>${t.title}</news:title> </news:news> `).join(` `):"",_=e=>e?e?.map(t=>` <image:image> <image:loc>${t}</image:loc> </image:image> `).join(` `):"",k=e=>e?e.map(t=>`<xhtml:link rel="alternate" hreflang="${t.hreflang}" href="${t.href}" />`).join(` `):"",g=e=>{let t=k(e.alternateLinks),i=_(e.images),r=D(e.news),n=b(e.videos);return e.route?` <url> <loc>${e.route}</loc> ${e.lastmod?`<lastmod>${e.lastmod}</lastmod>`:""} ${e.changefreq?`<changefreq>${e.changefreq}</changefreq>`:""} ${e.priority?`<priority>${e.priority}</priority>`:""} ${t} ${i} ${r} ${n} </url> `:""},L=e=>E(` <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-news/0.9 http://www.google.com/schemas/sitemap-news/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-video/1.1 http://www.google.com/schemas/sitemap-video/1.1/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap.xsd http://www.w3.org/TR/xhtml11/xhtml11_schema.html http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:xhtml="http://www.w3.org/TR/xhtml11/xhtml11_schema.html" > ${e} </urlset>`),F=({routes:e,domain:t,ignore:i,urlTransformer:r})=>e.map(n=>{let o=n.url.startsWith("/")?n.url:`/${n.url}`;if(i.some(s=>new w.default(s).match(o)!==null))return"";if(n.sitemapEntries)return(Array.isArray(n.sitemapEntries)?n.sitemapEntries:[n.sitemapEntries]).map(l=>g(l)).join(` `);let a=r?r(o):o,m=t+a;return g({route:m,lastmod:n.lastmod,changefreq:n.changefreq,priority:n.priority})}).join(` `),d=async({domain:e,ignore:t,routes:i,urlTransformer:r})=>{let n=["*.xml","*.txt","sitemap*",...t??[]],o=F({domain:e,ignore:n,routes:i,urlTransformer:r});return L(o)};var j=(e,t)=>{let i=t,r=[];for(;i&&(r.push(i.path),!(!i.parentId||!e[i.parentId]));)i=e[i.parentId];let n=r.reverse().filter(Boolean).join("/");return n===""?"/":n},q=e=>Object.values(e).map(t=>({...t,url:j(e,t)})),T=async({domain:e,sitemapData:t,routes:i})=>{let r=i;if(!r){let{routes:a}=await import("virtual:remix/server-build").catch(()=>{throw new Error("Could not find the remix server build. Make sure you have Remix running on Vite and not in SPA mode. Otherwise use the generateSitemap utility.")});r=a}let n=q(r);return(await Promise.all(n.map(async a=>{let m=a.url;if(a.id==="root")return;let s=a.module.handle;if(s&&typeof s=="object"&&"sitemap"in s&&typeof s.sitemap=="function"){let l=s.sitemap,h=await l(e,m,t);return{url:m,sitemapEntries:h,id:a.id}}return{url:m,sitemapEntries:null,id:a.id}}))).filter(Boolean)},I=async e=>{let{domain:t,sitemapData:i,ignore:r,urlTransformer:n,routes:o}=e,a=await T({domain:t,sitemapData:i,routes:o});return d({domain:t,routes:a,ignore:r,urlTransformer:n})};0&&(module.exports={generateRemixSitemap}); //# sourceMappingURL=sitemap.js.map