GithubHelp home page GithubHelp logo

didier / sveo Goto Github PK

View Code? Open in Web Editor NEW
24.0 3.0 3.0 139 KB

Declare metadata on SvelteKit pages, for example for SEO. Work in progress!

Home Page: https://www.npmjs.com/package/@didiercatz/sveo

License: MIT License

JavaScript 63.20% CSS 0.92% HTML 4.25% Svelte 31.63%
svelte svelte-kit seo

sveo's Introduction

SVEO

Dependency-free approach to declare metadata on SvelteKit pages โ€” for example for SEO.

  • Enables you to pass data from page components to __layout.svelte
  • โœ… Works with MDSveX out of the box.
  • Sveo component for easy templating of meta tags, Twitter cards, OpenGraph, etc.
Warning: This is not (yet) production-ready. It might not build at all. Use at your own discretion.

Getting started

Installing

npm i -D @didiercatz/sveo
I really wanted to get sveo, but according to npm, that's too similar to svgo. ๐Ÿคทโ€โ™‚๏ธ

Using

Using Sveo is quite simple. Create (or edit) a __layout.svelte inside your routes folder.

import { metadata } from '@didiercatz/sveo'

const seo = await metadata(page)
<script context="module">
  import { metadata } from '@didiercatz/sveo'

  export const load = async ({ page }) => {
    // The metadata from the page component
    const { title, description } = await metadata(page)

    return {
      props: {
        title,
        description
      }
    }
  }
</script>

Then, in your markup, you can use the title property as you please.

<!-- __layout[.reset].svelte -->

<script>
  export let title
  export let description
</script>

<h1>{title}</h1>
<p>{description}</p>

Finally, you can define metadata in your route's <script module="context">:

<script module="context">
  export const metadata = {
    title: 'Hello world',
    description: 'Have a wonderful day.'
  }
</script>

Sveo component

While using the metadata function is a nice way to grab data from your page components, sveo also comes with a more full-fledged component that automatically templates your SEO stuff like meta tags, page titles, Twitter cards, etc.

<!-- __layout[.reset].svelte -->
<script context="module">
  import { metadata } from '@didiercatz/sveo'

  export const load = async ({ page }) => {
    const seo = await metadata(page)

    return {
      props: { seo }
    }
  }
</script>

<script>
  import Sveo from '@didiercatz/sveo'

  export let seo = {
    // You could even fill in some defaults here.
  }
</script>

<Sveo {seo}/>

Options

options default Purpose
routes src/routes The folder containing your SvelteKit routes

License

MIT

sveo's People

Contributors

didier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.