Star 历史趋势
数据来源: GitHub API · 生成自 Stargazers.cn
README.md

Svead 🍺

All Contributors

MadeWithSvelte.com shield

Tests: E2E

Tests: Unit

Put a proper <Head /> on every page.

Svead is two Svelte components. Head sets your title, canonical, Open Graph and Twitter tags. SchemaOrg adds JSON-LD structured data.

Read the docs at svead.pages.dev

Svead: put a proper Head on every page

Name

The name was meant to be Svelte + Head, but I like Puru's suggestion of Svelte + Mead, hence the pint.

Use it

pnpm add -D svead

Svead needs Svelte 5. If you're still on Svelte 4, stay on svead@0.0.9, which has the older API with one prop per tag.

Build a config for the page and hand it to Head. Add SchemaOrg when you want structured data too:

<script lang="ts">
	import { Head, SchemaOrg } from 'svead';
	import type { SeoConfig, SchemaOrgProps } from 'svead';

	const seo_config: SeoConfig = {
		title: 'Welcome to My Site',
		description: 'This is a simple web page example.',
		url: 'https://example.com/welcome',
	};

	const schema_org: SchemaOrgProps['schema'] = {
		'@type': 'WebPage',
		name: 'Welcome to My Site',
		description: 'This is a simple web page example.',
		url: 'https://example.com/welcome',
	};
</script>

<Head {seo_config} />
<SchemaOrg schema={schema_org} />

<h1>Welcome to My Site</h1>
<p>This is a simple web page example.</p>

The home page has a pint you can type a config into to see the tags it produces.

Head

Head takes one prop, seo_config. From just the three required options it renders 13 tags:

  • the canonical link, <title> and the title and description meta tags
  • Open Graph: og:url, og:type, og:title and og:description
  • Twitter: twitter:card, twitter:title and twitter:description
  • itemprop name and description

The optional ones add to that, for example open_graph_image adds og:image, og:image:alt, twitter:image and itemprop="image".

SeoConfig options

PropertyTypeDescriptionRequired
titlestringThe title of the web page.Yes
descriptionstringA description of the web page.Yes
urlstringThe URL of the web page.Yes
websitestringThe website the web page belongs to.No
languagestringThe locale for og:locale, e.g. en_GB. Omitted if unset.No
open_graph_imagestringThe URL of an image to use for Open Graph meta tags.No
payment_pointerstringA payment pointer for Web Monetization.No
author_namestringThe name of the author.No
site_namestringThe name of the site for og:site_name.No
twitter_handlestringThe Twitter handle of the content creator or site.No
twitter_card_typestringThe type of Twitter card. Defaults to 'summary_large_image'.No
open_graph_image_altstringAlt text for the Open Graph image. Defaults to the title.No

SchemaOrg

The SchemaOrg component allows you to add structured data to your web pages using JSON-LD format. This helps search engines better understand your content and can potentially improve your site's appearance in search results.

Usage

<script lang="ts">
	import { SchemaOrg, type SchemaOrgProps } from 'svead';

	const schema_org: SchemaOrgProps['schema'] = {
		'@type': 'BlogPosting',
		headline: 'My First Blog Post',
		description: 'This is an example of a blog post using svead.',
		author: {
			'@type': 'Person',
			name: 'John Doe',
		},
		datePublished: '2023-08-22T10:00:00Z',
	};
</script>

<SchemaOrg schema={schema_org} />

SchemaOrgProps

PropertyTypeDescriptionRequired
schemaSchemaOrgType or arrayThe structured data object(s) following schema.org vocabulary.Yes

SchemaOrgType

SchemaOrgType is a union type that includes:

  • Thing: Represents the most generic type of item in schema.org.
  • WithContext<Thing>: A Thing with an added @context property.
  • Graph: A JSON-LD graph with @context and @graph.

You can use any valid schema.org type as defined in the schema.org documentation.

Good to know

  • The @context property is automatically added by the component if not provided.
  • Passing an array renders a single JSON-LD @graph with one shared https://schema.org context.
  • You can also include related schema types by nesting them within the main schema object.
  • Always validate your structured data using tools like Google's Rich Results Test to ensure it's correctly formatted.

Nesting schema types

<script lang="ts">
	import { SchemaOrg, type SchemaOrgProps } from 'svead';

	const schema_org: SchemaOrgProps['schema'] = {
		'@type': 'WebPage',
		name: 'My Blog Post',
		description: 'An example blog post with structured data',
		mainEntity: {
			'@type': 'BlogPosting',
			headline: 'My First Blog Post',
			author: {
				'@type': 'Person',
				name: 'John Doe',
			},
			datePublished: '2023-08-22T10:00:00Z',
		},
	};
</script>

<SchemaOrg schema={schema_org} />

Documentation

Developing locally

This is a pnpm workspace: the package is in packages/svead and the docs site in apps/web. It needs Node 24.15 or later.

pnpm install
# run the docs site against the local package
pnpm run dev:web
# format, lint and type check
pnpm run check
# unit tests for the package and the site
pnpm run test:ci
# end-to-end tests for the site, against a production build
pnpm --filter web run test:e2e

Tests sit beside the code they cover: *.svelte.test.ts runs in a real browser, *.ssr.test.ts and *.test.ts run in Node, and *.e2e.ts is Playwright.

Each docs page is a Markdown file in apps/web/src/lib/copy with an entry in apps/web/src/lib/docs/pages.ts, which is what the sidebar, the home page list and the command palette read. After adding or renaming a page, run pnpm run share-cards in apps/web to render its link preview image. A test fails if a page has no entry or no image.

Releasing

Scott, this is here for you to remember how to do this 🙃

Releases are manual and use changesets:

# describe the change (once per change, commit the file it writes)
pnpm changeset
# bump the version and write the changelog
pnpm run version
# build and publish to npm
pnpm run release
# push the tags
git push --follow-tags

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Scott Spence
Scott Spence

💻 📖 💡 🚧 ⚠️
Add your contributions

This project follows the all-contributors specification. Contributions of any kind welcome!

关于 About

Svead 🍺, a component that allows you to set head meta information, canonical, title, Twitter and Facebook Open Graph tags, and schema.org data.
breadcrumbscanonicalcomponentheadjson-ldlinksmetatagssveltesveltekit

语言 Languages

TypeScript57.3%
Svelte35.7%
CSS5.6%
JavaScript1.0%
HTML0.4%

提交活跃度 Commit Activity

代码提交热力图
过去 52 周的开发活跃度
23
Total Commits
峰值: 19次/周
Less
More

核心贡献者 Contributors