@useavalon/seo 0.2.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- export function injectMetaTags(e,t,n){let i=r(e),a=[],o=n.siteUrl.replace(/\/+$/,``),c=t.startsWith(`http`)?t:`${o}${t}`;if(n.canonical&&!i.canonical&&a.push(`<link rel="canonical" href="${s(c)}" />`),n.openGraph){let e=i.ogTitle||i.title,t=i.ogDescription||i.description||n.defaultDescription,r=i.ogImage||n.defaultOgImage?.url;if(!i.ogTitle&&e&&a.push(`<meta property="og:title" content="${s(e)}" />`),!i.ogDescription&&t&&a.push(`<meta property="og:description" content="${s(t)}" />`),i.ogUrl||a.push(`<meta property="og:url" content="${s(c)}" />`),!i.ogType){let e=i.articlePublishedTime?`article`:`website`;a.push(`<meta property="og:type" content="${e}" />`)}if(!i.ogLocale&&n.locale&&a.push(`<meta property="og:locale" content="${s(n.locale)}" />`),!i.ogSiteName&&n.siteName&&a.push(`<meta property="og:site_name" content="${s(n.siteName)}" />`),!i.ogImage&&r){let e=r.startsWith(`http`)?r:`${o}${r}`;a.push(`<meta property="og:image" content="${s(e)}" />`)}if(i.ogImage||r){if(!i.ogImageWidth){let e=n.defaultOgImage?.width||1200;a.push(`<meta property="og:image:width" content="${e}" />`)}if(!i.ogImageHeight){let e=n.defaultOgImage?.height||630;a.push(`<meta property="og:image:height" content="${e}" />`)}}}if(n.twitterCards){let e=i.twitterTitle||i.ogTitle||i.title,t=i.twitterDescription||i.ogDescription||i.description||n.defaultDescription,r=i.twitterImage||i.ogImage||n.defaultOgImage?.url;if(!i.twitterCard){let e=r?`summary_large_image`:`summary`;a.push(`<meta name="twitter:card" content="${e}" />`)}if(!i.twitterSite&&n.twitterSite&&a.push(`<meta name="twitter:site" content="${s(n.twitterSite)}" />`),!i.twitterCreator&&n.twitterCreator&&a.push(`<meta name="twitter:creator" content="${s(n.twitterCreator)}" />`),!i.twitterTitle&&e&&a.push(`<meta name="twitter:title" content="${s(e)}" />`),!i.twitterDescription&&t&&a.push(`<meta name="twitter:description" content="${s(t)}" />`),!i.twitterImage&&r){let e=r.startsWith(`http`)?r:`${o}${r}`;a.push(`<meta name="twitter:image" content="${s(e)}" />`)}}if(n.fontPreconnect?.length)for(let t of n.fontPreconnect)e.includes(t)||(a.push(`<link rel="preconnect" href="${s(t)}" />`),(t.includes(`fonts.gstatic`)||t.includes(`cdn.fonts`))&&a.push(`<link rel="preconnect" href="${s(t)}" crossorigin />`));if(a.length===0)return e;let l=e.toLowerCase().indexOf(`</head>`);return l===-1?e:e.slice(0,l)+a.join(`
1
+ export function injectMetaTags(t,n,i){let a=e(t),o=[],s=i.siteUrl.replace(/\/+$/,``),c=n.startsWith(`http`)?n:`${s}${n}`;if(i.canonical&&!a.canonical&&o.push(`<link rel="canonical" href="${r(c)}" />`),i.openGraph){let e=a.ogTitle||a.title,t=a.ogDescription||a.description||i.defaultDescription,n=a.ogImage||i.defaultOgImage?.url;if(!a.ogTitle&&e&&o.push(`<meta property="og:title" content="${r(e)}" />`),!a.ogDescription&&t&&o.push(`<meta property="og:description" content="${r(t)}" />`),a.ogUrl||o.push(`<meta property="og:url" content="${r(c)}" />`),!a.ogType){let e=a.articlePublishedTime?`article`:`website`;o.push(`<meta property="og:type" content="${e}" />`)}if(!a.ogLocale&&i.locale&&o.push(`<meta property="og:locale" content="${r(i.locale)}" />`),!a.ogSiteName&&i.siteName&&o.push(`<meta property="og:site_name" content="${r(i.siteName)}" />`),!a.ogImage&&n){let e=n.startsWith(`http`)?n:`${s}${n}`;o.push(`<meta property="og:image" content="${r(e)}" />`)}if(a.ogImage||n){if(!a.ogImageWidth){let e=i.defaultOgImage?.width||1200;o.push(`<meta property="og:image:width" content="${e}" />`)}if(!a.ogImageHeight){let e=i.defaultOgImage?.height||630;o.push(`<meta property="og:image:height" content="${e}" />`)}}}if(i.twitterCards){let e=a.twitterTitle||a.ogTitle||a.title,t=a.twitterDescription||a.ogDescription||a.description||i.defaultDescription,n=a.twitterImage||a.ogImage||i.defaultOgImage?.url;if(!a.twitterCard){let e=n?`summary_large_image`:`summary`;o.push(`<meta name="twitter:card" content="${e}" />`)}if(!a.twitterSite&&i.twitterSite&&o.push(`<meta name="twitter:site" content="${r(i.twitterSite)}" />`),!a.twitterCreator&&i.twitterCreator&&o.push(`<meta name="twitter:creator" content="${r(i.twitterCreator)}" />`),!a.twitterTitle&&e&&o.push(`<meta name="twitter:title" content="${r(e)}" />`),!a.twitterDescription&&t&&o.push(`<meta name="twitter:description" content="${r(t)}" />`),!a.twitterImage&&n){let e=n.startsWith(`http`)?n:`${s}${n}`;o.push(`<meta name="twitter:image" content="${r(e)}" />`)}}if(i.fontPreconnect?.length)for(let e of i.fontPreconnect)t.includes(e)||(o.push(`<link rel="preconnect" href="${r(e)}" />`),(e.includes(`fonts.gstatic`)||e.includes(`cdn.fonts`))&&o.push(`<link rel="preconnect" href="${r(e)}" crossorigin />`));if(o.length===0)return t;let l=t.toLowerCase().indexOf(`</head>`);return l===-1?t:t.slice(0,l)+o.join(`
2
2
  `)+`
3
- `+e.slice(l)}export function extractMetadataFromHtml(e){let t={},n=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);n&&(t.title=n[1].trim());let r=e.match(/<meta\s[^>]*name\s*=\s*["']description["'][^>]*content\s*=\s*["']([^"']*)["'][^>]*\/?>/i);if(r)t.description=r[1];else{let n=e.match(/<meta\s[^>]*content\s*=\s*["']([^"']*)["'][^>]*name\s*=\s*["']description["'][^>]*\/?>/i);n&&(t.description=n[1])}let a=extractMetaProperty(e,`og:title`),o=extractMetaProperty(e,`og:description`),s=extractMetaProperty(e,`og:image`),c=extractMetaProperty(e,`og:image:width`),l=extractMetaProperty(e,`og:image:height`);return(a||o||s)&&(t.openGraph={},a&&(t.openGraph.title=a),o&&(t.openGraph.description=o),s&&(t.openGraph.image=s),c&&(t.openGraph.imageWidth=parseInt(c,10)),l&&(t.openGraph.imageHeight=parseInt(l,10))),t}export function extractArticleMetaFromHtml(e){let t=extractMetaProperty(e,`article:published_time`),n=extractMetaProperty(e,`article:modified_time`),r=extractMetaProperty(e,`article:author`),a=extractMetaProperty(e,`article:section`),o=/<meta\s[^>]*property\s*=\s*["']article:tag["'][^>]*content\s*=\s*["']([^"']*)["'][^>]*\/?>/gi,s=[];for(let t=o.exec(e);t!==null;t=o.exec(e))s.push(t[1]);return{...t&&{datePublished:t},...n&&{dateModified:n},...r&&{author:r},...a&&{section:a},...s.length>0&&{tags:s}}}function r(e){let t={},n=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);n&&(t.title=n[1].trim()),t.description=a(e,`description`),t.robots=a(e,`robots`);let r=e.match(/<link\s[^>]*rel\s*=\s*["']canonical["'][^>]*href\s*=\s*["']([^"']*)["'][^>]*\/?>/i);return r&&(t.canonical=r[1]),t.ogTitle=extractMetaProperty(e,`og:title`),t.ogDescription=extractMetaProperty(e,`og:description`),t.ogImage=extractMetaProperty(e,`og:image`),t.ogImageWidth=extractMetaProperty(e,`og:image:width`),t.ogImageHeight=extractMetaProperty(e,`og:image:height`),t.ogUrl=extractMetaProperty(e,`og:url`),t.ogType=extractMetaProperty(e,`og:type`),t.ogLocale=extractMetaProperty(e,`og:locale`),t.ogSiteName=extractMetaProperty(e,`og:site_name`),t.twitterCard=a(e,`twitter:card`),t.twitterSite=a(e,`twitter:site`),t.twitterCreator=a(e,`twitter:creator`),t.twitterTitle=a(e,`twitter:title`),t.twitterDescription=a(e,`twitter:description`),t.twitterImage=a(e,`twitter:image`),t.articlePublishedTime=extractMetaProperty(e,`article:published_time`),t.articleModifiedTime=extractMetaProperty(e,`article:modified_time`),t.articleAuthor=extractMetaProperty(e,`article:author`),t.articleSection=extractMetaProperty(e,`article:section`),t}export function extractMetaProperty(e,t){let n=o(t),r=String.raw`<meta\s[^>]*property\s*=\s*["']`+n+String.raw`["'][^>]*content\s*=\s*["']([^"']*)["'][^>]*/?>`,i=String.raw`<meta\s[^>]*content\s*=\s*["']([^"']*)["'][^>]*property\s*=\s*["']`+n+String.raw`["'][^>]*/?>`,a=e.match(new RegExp(r,`i`));if(a)return a[1];let s=e.match(new RegExp(i,`i`));return s?s[1]:void 0}function a(e,t){let n=o(t),r=String.raw`<meta\s[^>]*name\s*=\s*["']`+n+String.raw`["'][^>]*content\s*=\s*["']([^"']*)["'][^>]*/?>`,i=String.raw`<meta\s[^>]*content\s*=\s*["']([^"']*)["'][^>]*name\s*=\s*["']`+n+String.raw`["'][^>]*/?>`,a=e.match(new RegExp(r,`i`));if(a)return a[1];let s=e.match(new RegExp(i,`i`));return s?s[1]:void 0}function o(e){return e.replaceAll(/[.*+?^${}()|[\]\\]/g,e=>`\\`+e)}function s(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`"`,`&quot;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`)}
3
+ `+t.slice(l)}export function extractMetadataFromHtml(e){let t={},n=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);n&&(t.title=n[1].trim());let r=e.match(/<meta\s[^>]*name\s*=\s*["']description["'][^>]*content\s*=\s*["']([^"']*)["'][^>]*\/?>/i);if(r)t.description=r[1];else{let n=e.match(/<meta\s[^>]*content\s*=\s*["']([^"']*)["'][^>]*name\s*=\s*["']description["'][^>]*\/?>/i);n&&(t.description=n[1])}let i=extractMetaProperty(e,`og:title`),a=extractMetaProperty(e,`og:description`),o=extractMetaProperty(e,`og:image`),s=extractMetaProperty(e,`og:image:width`),c=extractMetaProperty(e,`og:image:height`);return(i||a||o)&&(t.openGraph={},i&&(t.openGraph.title=i),a&&(t.openGraph.description=a),o&&(t.openGraph.image=o),s&&(t.openGraph.imageWidth=parseInt(s,10)),c&&(t.openGraph.imageHeight=parseInt(c,10))),t}export function extractArticleMetaFromHtml(e){let t=extractMetaProperty(e,`article:published_time`),n=extractMetaProperty(e,`article:modified_time`),r=extractMetaProperty(e,`article:author`),i=extractMetaProperty(e,`article:section`),a=/<meta\s[^>]*property\s*=\s*["']article:tag["'][^>]*content\s*=\s*["']([^"']*)["'][^>]*\/?>/gi,o=[];for(let t=a.exec(e);t!==null;t=a.exec(e))o.push(t[1]);return{...t&&{datePublished:t},...n&&{dateModified:n},...r&&{author:r},...i&&{section:i},...o.length>0&&{tags:o}}}function e(e){let n={},r=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);r&&(n.title=r[1].trim()),n.description=t(e,`description`),n.robots=t(e,`robots`);let i=e.match(/<link\s[^>]*rel\s*=\s*["']canonical["'][^>]*href\s*=\s*["']([^"']*)["'][^>]*\/?>/i);return i&&(n.canonical=i[1]),n.ogTitle=extractMetaProperty(e,`og:title`),n.ogDescription=extractMetaProperty(e,`og:description`),n.ogImage=extractMetaProperty(e,`og:image`),n.ogImageWidth=extractMetaProperty(e,`og:image:width`),n.ogImageHeight=extractMetaProperty(e,`og:image:height`),n.ogUrl=extractMetaProperty(e,`og:url`),n.ogType=extractMetaProperty(e,`og:type`),n.ogLocale=extractMetaProperty(e,`og:locale`),n.ogSiteName=extractMetaProperty(e,`og:site_name`),n.twitterCard=t(e,`twitter:card`),n.twitterSite=t(e,`twitter:site`),n.twitterCreator=t(e,`twitter:creator`),n.twitterTitle=t(e,`twitter:title`),n.twitterDescription=t(e,`twitter:description`),n.twitterImage=t(e,`twitter:image`),n.articlePublishedTime=extractMetaProperty(e,`article:published_time`),n.articleModifiedTime=extractMetaProperty(e,`article:modified_time`),n.articleAuthor=extractMetaProperty(e,`article:author`),n.articleSection=extractMetaProperty(e,`article:section`),n}export function extractMetaProperty(e,t){let r=n(t),i=String.raw`<meta\s[^>]*property\s*=\s*["']`+r+String.raw`["'][^>]*content\s*=\s*["']([^"']*)["'][^>]*/?>`,a=String.raw`<meta\s[^>]*content\s*=\s*["']([^"']*)["'][^>]*property\s*=\s*["']`+r+String.raw`["'][^>]*/?>`,o=e.match(new RegExp(i,`i`));if(o)return o[1];let s=e.match(new RegExp(a,`i`));return s?s[1]:void 0}function t(e,t){let r=n(t),i=String.raw`<meta\s[^>]*name\s*=\s*["']`+r+String.raw`["'][^>]*content\s*=\s*["']([^"']*)["'][^>]*/?>`,a=String.raw`<meta\s[^>]*content\s*=\s*["']([^"']*)["'][^>]*name\s*=\s*["']`+r+String.raw`["'][^>]*/?>`,o=e.match(new RegExp(i,`i`));if(o)return o[1];let s=e.match(new RegExp(a,`i`));return s?s[1]:void 0}function n(e){return e.replaceAll(/[.*+?^${}()|[\]\\]/g,e=>`\\`+e)}function r(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`"`,`&quot;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`)}
@@ -1 +1 @@
1
- import{validateSeoConfig as e}from"./config.js";import{extractArticleMetaFromHtml as t,extractMetadataFromHtml as n,injectMetaTags as r}from"./meta-tags.js";import{buildArticleJsonLd as i,buildBreadcrumbListJsonLd as a,buildWebPageJsonLd as o,buildWebSiteJsonLd as s,injectJsonLd as c}from"./structured-data.js";export function seo(t){let n=e(t),r=[];return r.push({name:`avalon-seo`,enforce:`pre`,configureServer(e){e.middlewares.use((e,t,r)=>{let i=e.url??`/`;if(i.startsWith(`/@`)||i.startsWith(`/__`)||i.startsWith(`/node_modules/`)||i.startsWith(`/src/`)||i.startsWith(`/packages/`)||i.includes(`.`)&&!i.endsWith(`/`))return r();u(t,i,n),r()})}}),r}function u(e,t,n){let r=e.end.bind(e),i=e.setHeader.bind(e),a=e.writeHead.bind(e),o=[],s=!1,c=()=>{s=!0};e.setHeader=((e,t)=>(e.toLowerCase()===`content-type`&&typeof t==`string`&&t.includes(`text/html`)&&c(),i(e,t))),e.writeHead=((e,...t)=>{for(let e of t)if(e&&typeof e==`object`&&!Array.isArray(e))for(let[t,n]of Object.entries(e))t.toLowerCase()===`content-type`&&typeof n==`string`&&n.includes(`text/html`)&&c();return a(e,...t)}),e.end=((a,l,u)=>{if(!s){let t=e.getHeader(`content-type`);typeof t==`string`&&t.includes(`text/html`)&&c()}if(!s)return r(a,l,u);if(a){if(Buffer.isBuffer(a))o.push(a);else if(typeof a==`string`){let e=typeof l==`string`?l:`utf-8`;o.push(Buffer.from(a,e))}}if(o.length===0)return r(a,l,u);let f=Buffer.concat(o).toString(`utf-8`),p=typeof l==`function`?l:u,m=d(f,t,n);return m!==f&&i(`Content-Length`,String(Buffer.byteLength(m))),r(m,`utf-8`,p)})}function d(e,l,u){let d=n(e);if(!d.title&&!d.description)return e;let f=u.siteUrl.replace(/\/+$/,``),p=l.startsWith(`http`)?l:`${f}${l}`;if(u.titleSuffix!==!1&&d.title){let t=typeof u.titleSuffix==`string`?u.titleSuffix:` — ${u.siteName}`;if(!d.title.includes(u.siteName)){let n=d.title+t;e=e.replace(/<title[^>]*>[\s\S]*?<\/title>/i,`<title>${n}</title>`),d.title=n}}if(e=r(e,l,u),u.structuredData){if(e=c(e,o(d,p)),e=c(e,s(u)),u.breadcrumbs){let t=new URL(l,f||`http://localhost`).pathname,n=a(t,f);n&&(e=c(e,n))}let n=t(e);if(d.title&&(n.datePublished||d.description)){let t={title:d.title,description:d.description,image:d.openGraph?.image,imageWidth:d.openGraph?.imageWidth,imageHeight:d.openGraph?.imageHeight,datePublished:n.datePublished,dateModified:n.dateModified,author:n.author,section:n.section,tags:n.tags};e=c(e,i(t,p,u))}}return e}
1
+ import{validateSeoConfig as e}from"./config.js";import{extractArticleMetaFromHtml as t,extractMetadataFromHtml as n,injectMetaTags as r}from"./meta-tags.js";import{buildArticleJsonLd as i,buildBreadcrumbListJsonLd as a,buildWebPageJsonLd as o,buildWebSiteJsonLd as s,injectJsonLd as c}from"./structured-data.js";export function seo(t){let n=e(t),r=[];return r.push({name:`avalon-seo`,enforce:`pre`,configureServer(e){e.middlewares.use((e,t,r)=>{let i=e.url??`/`;if(i.startsWith(`/@`)||i.startsWith(`/__`)||i.startsWith(`/node_modules/`)||i.startsWith(`/src/`)||i.startsWith(`/packages/`)||i.includes(`.`)&&!i.endsWith(`/`))return r();l(t,i,n),r()})}}),r}function l(e,t,n){let r=e.end.bind(e),i=e.setHeader.bind(e),a=e.writeHead.bind(e),o=[],s=!1,c=()=>{s=!0};e.setHeader=((e,t)=>(e.toLowerCase()===`content-type`&&typeof t==`string`&&t.includes(`text/html`)&&c(),i(e,t))),e.writeHead=((e,...t)=>{for(let e of t)if(e&&typeof e==`object`&&!Array.isArray(e))for(let[t,n]of Object.entries(e))t.toLowerCase()===`content-type`&&typeof n==`string`&&n.includes(`text/html`)&&c();return a(e,...t)}),e.end=((a,l,d)=>{if(!s){let t=e.getHeader(`content-type`);typeof t==`string`&&t.includes(`text/html`)&&c()}if(!s)return r(a,l,d);if(a){if(Buffer.isBuffer(a))o.push(a);else if(typeof a==`string`){let e=typeof l==`string`?l:`utf-8`;o.push(Buffer.from(a,e))}}if(o.length===0)return r(a,l,d);let f=Buffer.concat(o).toString(`utf-8`),p=typeof l==`function`?l:d,m=u(f,t,n);return m!==f&&i(`Content-Length`,String(Buffer.byteLength(m))),r(m,`utf-8`,p)})}function u(e,l,u){let d=n(e);if(!d.title&&!d.description)return e;let f=u.siteUrl.replace(/\/+$/,``),p=l.startsWith(`http`)?l:`${f}${l}`;if(u.titleSuffix!==!1&&d.title){let t=typeof u.titleSuffix==`string`?u.titleSuffix:` — ${u.siteName}`;if(!d.title.includes(u.siteName)){let n=d.title+t;e=e.replace(/<title[^>]*>[\s\S]*?<\/title>/i,`<title>${n}</title>`),d.title=n}}if(e=r(e,l,u),u.structuredData){if(e=c(e,o(d,p)),e=c(e,s(u)),u.breadcrumbs){let t=new URL(l,f||`http://localhost`).pathname,n=a(t,f);n&&(e=c(e,n))}let n=t(e);if(d.title&&(n.datePublished||d.description)){let t={title:d.title,description:d.description,image:d.openGraph?.image,imageWidth:d.openGraph?.imageWidth,imageHeight:d.openGraph?.imageHeight,datePublished:n.datePublished,dateModified:n.dateModified,author:n.author,section:n.section,tags:n.tags};e=c(e,i(t,p,u))}}return e}
@@ -1 +1 @@
1
- export function buildWebPageJsonLd(e,t){let n={"@context":`https://schema.org`,"@type":`WebPage`,url:t};return e.title&&(n.name=e.title),e.description&&(n.description=e.description),e.openGraph?.image&&(n.image=e.openGraph.image),n}export function buildWebSiteJsonLd(e){let t={"@context":`https://schema.org`,"@type":`WebSite`,url:e.siteUrl,name:e.siteName};if(e.searchPath){let n=e.siteUrl.replace(/\/+$/,``),r=e.searchQueryParam||`q`;t.potentialAction={"@type":`SearchAction`,target:`${n}${e.searchPath}?${r}={search_term_string}`,"query-input":`required name=search_term_string`}}return t}export function buildBreadcrumbListJsonLd(e,t){let n=e.split(`/`).filter(Boolean);if(n.length===0)return null;let r=t.replace(/\/+$/,``),i=[{"@type":`ListItem`,position:1,name:`Home`,item:r||`/`}];for(let e=0;e<n.length;e++){let t=n[e].replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),a=e===n.length-1,o={"@type":`ListItem`,position:e+2,name:t};a||(o.item=`${r}/${n.slice(0,e+1).join(`/`)}`),i.push(o)}return{"@context":`https://schema.org`,"@type":`BreadcrumbList`,itemListElement:i}}export function buildArticleJsonLd(e,t,n){let r=n.siteUrl.replace(/\/+$/,``),a={"@context":`https://schema.org`,"@type":`Article`,headline:e.title,mainEntityOfPage:t};e.description&&(a.description=e.description);let s=e.image||n.defaultOgImage?.url;if(s){let t={"@type":`ImageObject`,url:s.startsWith(`http`)?s:`${r}${s}`},i=e.imageWidth||n.defaultOgImage?.width,o=e.imageHeight||n.defaultOgImage?.height;i&&(t.width=i),o&&(t.height=o),a.image=t}return e.datePublished&&(a.datePublished=e.datePublished),e.dateModified&&(a.dateModified=e.dateModified),a.author=i(e,n),a.publisher=o(n),e.wordCount&&(a.wordCount=e.wordCount),e.section&&(a.articleSection=e.section),e.tags?.length&&(a.keywords=e.tags.join(`, `)),n.speakable&&n.speakableSelectors?.length&&(a.speakable={"@type":`SpeakableSpecification`,cssSelector:n.speakableSelectors}),a}function i(e,t){if(t.author)return a(t.author);if(e.author){let t={"@type":`Person`,name:e.author};return e.authorUrl&&(t.url=e.authorUrl),t}return{"@type":`Person`,name:t.siteName}}function a(e){let t={"@type":`Person`,name:e.name};return e.url&&(t.url=e.url),e.image&&(t.image=e.image),e.jobTitle&&(t.jobTitle=e.jobTitle),e.description&&(t.description=e.description),e.worksFor&&(t.worksFor={"@type":`Organization`,name:e.worksFor.name,...e.worksFor.url&&{url:e.worksFor.url}}),e.sameAs?.length&&(t.sameAs=e.sameAs),t}function o(e){if(e.publisher){let t={"@type":`Organization`,name:e.publisher.name};return e.publisher.url&&(t.url=e.publisher.url),e.publisher.logo&&(t.logo={"@type":`ImageObject`,url:e.publisher.logo.url,...e.publisher.logo.width&&{width:e.publisher.logo.width},...e.publisher.logo.height&&{height:e.publisher.logo.height}}),t}let t=e.siteUrl.replace(/\/+$/,``);return{"@type":`Organization`,name:e.siteName,url:t}}export function injectJsonLd(e,t){let n=e.toLowerCase().indexOf(`</head>`);if(n===-1)return e;let r=`<script type="application/ld+json">${JSON.stringify(t)}<\/script>`;return e.slice(0,n)+r+e.slice(n)}
1
+ export function buildWebPageJsonLd(e,t){let n={"@context":`https://schema.org`,"@type":`WebPage`,url:t};return e.title&&(n.name=e.title),e.description&&(n.description=e.description),e.openGraph?.image&&(n.image=e.openGraph.image),n}export function buildWebSiteJsonLd(e){let t={"@context":`https://schema.org`,"@type":`WebSite`,url:e.siteUrl,name:e.siteName};if(e.searchPath){let n=e.siteUrl.replace(/\/+$/,``),r=e.searchQueryParam||`q`;t.potentialAction={"@type":`SearchAction`,target:`${n}${e.searchPath}?${r}={search_term_string}`,"query-input":`required name=search_term_string`}}return t}export function buildBreadcrumbListJsonLd(e,t){let n=e.split(`/`).filter(Boolean);if(n.length===0)return null;let r=t.replace(/\/+$/,``),i=[{"@type":`ListItem`,position:1,name:`Home`,item:r||`/`}];for(let e=0;e<n.length;e++){let t=n[e].replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),a=e===n.length-1,o={"@type":`ListItem`,position:e+2,name:t};a||(o.item=`${r}/${n.slice(0,e+1).join(`/`)}`),i.push(o)}return{"@context":`https://schema.org`,"@type":`BreadcrumbList`,itemListElement:i}}export function buildArticleJsonLd(t,r,i){let a=i.siteUrl.replace(/\/+$/,``),o={"@context":`https://schema.org`,"@type":`Article`,headline:t.title,mainEntityOfPage:r};t.description&&(o.description=t.description);let s=t.image||i.defaultOgImage?.url;if(s){let e={"@type":`ImageObject`,url:s.startsWith(`http`)?s:`${a}${s}`},n=t.imageWidth||i.defaultOgImage?.width,r=t.imageHeight||i.defaultOgImage?.height;n&&(e.width=n),r&&(e.height=r),o.image=e}return t.datePublished&&(o.datePublished=t.datePublished),t.dateModified&&(o.dateModified=t.dateModified),o.author=e(t,i),o.publisher=n(i),t.wordCount&&(o.wordCount=t.wordCount),t.section&&(o.articleSection=t.section),t.tags?.length&&(o.keywords=t.tags.join(`, `)),i.speakable&&i.speakableSelectors?.length&&(o.speakable={"@type":`SpeakableSpecification`,cssSelector:i.speakableSelectors}),o}function e(e,n){if(n.author)return t(n.author);if(e.author){let t={"@type":`Person`,name:e.author};return e.authorUrl&&(t.url=e.authorUrl),t}return{"@type":`Person`,name:n.siteName}}function t(e){let t={"@type":`Person`,name:e.name};return e.url&&(t.url=e.url),e.image&&(t.image=e.image),e.jobTitle&&(t.jobTitle=e.jobTitle),e.description&&(t.description=e.description),e.worksFor&&(t.worksFor={"@type":`Organization`,name:e.worksFor.name,...e.worksFor.url&&{url:e.worksFor.url}}),e.sameAs?.length&&(t.sameAs=e.sameAs),t}function n(e){if(e.publisher){let t={"@type":`Organization`,name:e.publisher.name};return e.publisher.url&&(t.url=e.publisher.url),e.publisher.logo&&(t.logo={"@type":`ImageObject`,url:e.publisher.logo.url,...e.publisher.logo.width&&{width:e.publisher.logo.width},...e.publisher.logo.height&&{height:e.publisher.logo.height}}),t}let t=e.siteUrl.replace(/\/+$/,``);return{"@type":`Organization`,name:e.siteName,url:t}}export function injectJsonLd(e,t){let n=e.toLowerCase().indexOf(`</head>`);if(n===-1)return e;let r=`<script type="application/ld+json">${JSON.stringify(t)}<\/script>`;return e.slice(0,n)+r+e.slice(n)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useavalon/seo",
3
- "version": "0.2.2",
3
+ "version": "0.5.4",
4
4
  "description": "SEO plugin for Avalon — auto-injects Open Graph, Twitter cards, canonical URLs, JSON-LD structured data, and robots meta tags",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,7 +35,7 @@
35
35
  "README.md"
36
36
  ],
37
37
  "dependencies": {
38
- "zod": "^4.3.6"
38
+ "zod": "^4.6.5"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "vite": "^8.0.0"
@@ -46,8 +46,8 @@
46
46
  }
47
47
  },
48
48
  "devDependencies": {
49
- "oxc-minify": "^0.120.0",
50
- "oxc-transform": "^0.120.0",
51
- "vitest": "^4.1.0"
49
+ "oxc-minify": "^0.152.0",
50
+ "oxc-transform": "^0.152.0",
51
+ "vitest": "^5.0.3"
52
52
  }
53
53
  }