@useavalon/seo 0.1.0
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.
- package/README.md +126 -0
- package/dist/mod.js +1 -0
- package/dist/src/config.js +2 -0
- package/dist/src/meta-tags.js +3 -0
- package/dist/src/plugin.js +1 -0
- package/dist/src/structured-data.js +1 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# @useavalon/seo
|
|
2
|
+
|
|
3
|
+
SEO plugin for [Avalon](https://useavalon.dev) — auto-injects Open Graph, Twitter cards, canonical URLs, JSON-LD structured data, and font preconnect links into every page.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @useavalon/seo
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Add the plugin to your `vite.config.ts`:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { seo } from '@useavalon/seo';
|
|
17
|
+
import { avalon } from '@useavalon/avalon';
|
|
18
|
+
import { defineConfig } from 'vite';
|
|
19
|
+
|
|
20
|
+
export default defineConfig(async () => {
|
|
21
|
+
const avalonPlugins = await avalon({ /* ... */ });
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
plugins: [
|
|
25
|
+
seo({
|
|
26
|
+
siteUrl: 'https://mysite.com',
|
|
27
|
+
siteName: 'My Site',
|
|
28
|
+
defaultDescription: 'A site built with Avalon',
|
|
29
|
+
defaultOgImage: {
|
|
30
|
+
url: '/og-image.png',
|
|
31
|
+
width: 1200,
|
|
32
|
+
height: 630,
|
|
33
|
+
},
|
|
34
|
+
twitterSite: '@mysite',
|
|
35
|
+
twitterCreator: '@author',
|
|
36
|
+
searchPath: '/search',
|
|
37
|
+
author: {
|
|
38
|
+
name: 'Jane Doe',
|
|
39
|
+
url: 'https://mysite.com/about',
|
|
40
|
+
image: 'https://mysite.com/jane.jpg',
|
|
41
|
+
jobTitle: 'Software Engineer',
|
|
42
|
+
sameAs: ['https://twitter.com/janedoe', 'https://github.com/janedoe'],
|
|
43
|
+
},
|
|
44
|
+
publisher: {
|
|
45
|
+
name: 'My Company',
|
|
46
|
+
url: 'https://mysite.com',
|
|
47
|
+
logo: { url: 'https://mysite.com/logo.png', width: 600, height: 60 },
|
|
48
|
+
},
|
|
49
|
+
fontPreconnect: [
|
|
50
|
+
'https://fonts.googleapis.com',
|
|
51
|
+
'https://fonts.gstatic.com',
|
|
52
|
+
],
|
|
53
|
+
}),
|
|
54
|
+
...avalonPlugins,
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## What It Does
|
|
61
|
+
|
|
62
|
+
The plugin intercepts every HTML response and auto-injects missing SEO tags. It reads existing tags to avoid duplication — if your layout already sets `og:title`, the plugin won't add another one.
|
|
63
|
+
|
|
64
|
+
### Meta Tags
|
|
65
|
+
|
|
66
|
+
- **Canonical URL** — `<link rel="canonical">` from the current request path
|
|
67
|
+
- **Open Graph** — `og:title`, `og:description`, `og:url`, `og:type`, `og:locale`, `og:site_name`, `og:image` with `og:image:width` and `og:image:height`
|
|
68
|
+
- **Twitter Cards** — `twitter:card`, `twitter:site`, `twitter:creator`, `twitter:title`, `twitter:description`, `twitter:image`
|
|
69
|
+
- **Font Preconnect** — `<link rel="preconnect">` for configured font CDNs
|
|
70
|
+
|
|
71
|
+
### JSON-LD Structured Data
|
|
72
|
+
|
|
73
|
+
- **WebPage** — on every page
|
|
74
|
+
- **WebSite** — with `SearchAction` when `searchPath` is configured (enables Google sitelinks search box)
|
|
75
|
+
- **BreadcrumbList** — auto-generated from URL path segments
|
|
76
|
+
- **Article** — when the page has `article:published_time` meta tag, includes full Person author (E-E-A-T), Organization publisher with logo ImageObject, and image with dimensions
|
|
77
|
+
- **Speakable** — `SpeakableSpecification` on Article schema for voice engines
|
|
78
|
+
|
|
79
|
+
## Config Reference
|
|
80
|
+
|
|
81
|
+
| Option | Type | Default | Description |
|
|
82
|
+
|--------|------|---------|-------------|
|
|
83
|
+
| `siteUrl` | `string` | required | Base URL of the site |
|
|
84
|
+
| `siteName` | `string` | required | Site name for OG and JSON-LD |
|
|
85
|
+
| `defaultDescription` | `string?` | — | Fallback meta description |
|
|
86
|
+
| `defaultOgImage` | `{ url, width?, height? }?` | — | Default OG image with dimensions |
|
|
87
|
+
| `twitterSite` | `string?` | — | Twitter handle for `twitter:site` |
|
|
88
|
+
| `twitterCreator` | `string?` | — | Twitter handle for `twitter:creator` |
|
|
89
|
+
| `locale` | `string?` | `'en_US'` | Default OG locale |
|
|
90
|
+
| `author` | `PersonConfig?` | — | Author info for Article JSON-LD |
|
|
91
|
+
| `publisher` | `OrganizationConfig?` | — | Publisher info for Article JSON-LD |
|
|
92
|
+
| `searchPath` | `string?` | — | Path to search page (enables SearchAction) |
|
|
93
|
+
| `searchQueryParam` | `string?` | `'q'` | Query param name for search |
|
|
94
|
+
| `canonical` | `boolean?` | `true` | Inject canonical URLs |
|
|
95
|
+
| `openGraph` | `boolean?` | `true` | Inject OG meta tags |
|
|
96
|
+
| `twitterCards` | `boolean?` | `true` | Inject Twitter card tags |
|
|
97
|
+
| `structuredData` | `boolean?` | `true` | Inject JSON-LD |
|
|
98
|
+
| `breadcrumbs` | `boolean?` | `true` | Inject BreadcrumbList JSON-LD |
|
|
99
|
+
| `speakable` | `boolean?` | `true` | Add Speakable to Article JSON-LD |
|
|
100
|
+
| `speakableSelectors` | `string[]?` | `['h1', '[data-speakable]']` | CSS selectors for speakable content |
|
|
101
|
+
| `fontPreconnect` | `string[]?` | — | URLs to preconnect for fonts |
|
|
102
|
+
|
|
103
|
+
## How Pages Opt Into Article Schema
|
|
104
|
+
|
|
105
|
+
The plugin reads `article:*` meta tags from the HTML to decide when to inject Article JSON-LD. Set these in your page's frontmatter/metadata:
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
export const metadata = {
|
|
109
|
+
title: 'My Blog Post',
|
|
110
|
+
description: 'A great article about...',
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// In your layout, emit these meta tags from frontmatter:
|
|
114
|
+
<meta property="article:published_time" content="2026-01-15" />
|
|
115
|
+
<meta property="article:modified_time" content="2026-02-01" />
|
|
116
|
+
<meta property="article:author" content="Jane Doe" />
|
|
117
|
+
<meta property="article:section" content="Tech" />
|
|
118
|
+
<meta property="article:tag" content="javascript" />
|
|
119
|
+
<meta property="article:tag" content="seo" />
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
When `article:published_time` is present, the plugin generates full Article JSON-LD with author, publisher, image dimensions, and speakable specification.
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{seo}from"./src/plugin.js";export{validateSeoConfig,SeoConfigSchema,PersonConfigSchema,OrganizationConfigSchema}from"./src/config.js";export{buildWebPageJsonLd,buildWebSiteJsonLd,buildBreadcrumbListJsonLd,buildArticleJsonLd,injectJsonLd}from"./src/structured-data.js";export{injectMetaTags,extractMetadataFromHtml,extractArticleMetaFromHtml,extractMetaProperty}from"./src/meta-tags.js";
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{z as e}from"zod";export const PersonConfigSchema=e.object({name:e.string(),url:e.string().optional(),image:e.string().optional(),jobTitle:e.string().optional(),worksFor:e.object({name:e.string(),url:e.string().optional()}).optional(),description:e.string().optional(),sameAs:e.array(e.string()).optional()});export const OrganizationConfigSchema=e.object({name:e.string(),url:e.string().optional(),logo:e.object({url:e.string(),width:e.number().optional(),height:e.number().optional()}).optional()});export const SeoConfigSchema=e.object({siteUrl:e.string(),siteName:e.string(),defaultDescription:e.string().optional(),defaultOgImage:e.object({url:e.string(),width:e.number().optional().default(1200),height:e.number().optional().default(630)}).optional(),twitterSite:e.string().optional(),twitterCreator:e.string().optional(),locale:e.string().optional().default(`en_US`),author:PersonConfigSchema.optional(),publisher:OrganizationConfigSchema.optional(),searchPath:e.string().optional(),searchQueryParam:e.string().optional().default(`q`),canonical:e.boolean().optional().default(!0),openGraph:e.boolean().optional().default(!0),twitterCards:e.boolean().optional().default(!0),structuredData:e.boolean().optional().default(!0),breadcrumbs:e.boolean().optional().default(!0),speakable:e.boolean().optional().default(!0),speakableSelectors:e.array(e.string()).optional().default([`h1`,`[data-speakable]`]),fontPreconnect:e.array(e.string()).optional(),titleSuffix:e.union([e.string(),e.literal(!1)]).optional()});export function validateSeoConfig(e){let t=SeoConfigSchema.safeParse(e);if(t.success)return t.data;let n=t.error.issues.map(e=>` - ${e.path.join(`.`)}: ${e.message}`);throw Error(`Invalid @useavalon/seo config:\n${n.join(`
|
|
2
|
+
`)}`)}
|
|
@@ -0,0 +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(`
|
|
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=[],c;for(;(c=o.exec(e))!==null;)s.push(c[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(`&`,`&`).replaceAll(`"`,`"`).replaceAll(`<`,`<`).replaceAll(`>`,`>`)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{validateSeoConfig as e}from"./config.js";import{injectMetaTags as t,extractMetadataFromHtml as n,extractArticleMetaFromHtml as r}from"./meta-tags.js";import{buildWebPageJsonLd as i,buildWebSiteJsonLd as a,buildBreadcrumbListJsonLd as o,buildArticleJsonLd 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=function(e,t){return e.toLowerCase()===`content-type`&&typeof t==`string`&&t.includes(`text/html`)&&c(),i(e,t)},e.writeHead=function(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=function(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=t(e,l,u),u.structuredData){if(e=c(e,i(d,p)),e=c(e,a(u)),u.breadcrumbs){let t=new URL(l,f||`http://localhost`).pathname,n=o(t,f);n&&(e=c(e,n))}let t=r(e);if(d.title&&(t.datePublished||d.description)){let n={title:d.title,description:d.description,image:d.openGraph?.image,imageWidth:d.openGraph?.imageWidth,imageHeight:d.openGraph?.imageHeight,datePublished:t.datePublished,dateModified:t.dateModified,author:t.author,section:t.section,tags:t.tags};e=c(e,s(n,p,u))}}return e}
|
|
@@ -0,0 +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)}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@useavalon/seo",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SEO plugin for Avalon — auto-injects Open Graph, Twitter cards, canonical URLs, JSON-LD structured data, and robots meta tags",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/useAvalon/Avalon.git",
|
|
10
|
+
"directory": "packages/seo"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://useavalon.dev/docs/plugins/seo",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"avalon",
|
|
15
|
+
"seo",
|
|
16
|
+
"json-ld",
|
|
17
|
+
"open-graph",
|
|
18
|
+
"twitter-cards",
|
|
19
|
+
"structured-data",
|
|
20
|
+
"canonical",
|
|
21
|
+
"breadcrumbs",
|
|
22
|
+
"schema-org"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./dist/mod.js"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "bun run scripts/build.ts",
|
|
29
|
+
"prepublishOnly": "bun run build",
|
|
30
|
+
"postpublish": "bun run scripts/postpublish.ts"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist/**/*.js",
|
|
34
|
+
"dist/**/*.d.ts",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"zod": "^4.3.6"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"vite": "^8.0.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"vite": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"oxc-minify": "^0.120.0",
|
|
50
|
+
"oxc-transform": "^0.120.0",
|
|
51
|
+
"vitest": "^4.1.0"
|
|
52
|
+
}
|
|
53
|
+
}
|