1.1.24 ā€¢ Published 9 days ago

@jill64/svelte-ogp v1.1.24

Weekly downloads
-
License
MIT
Repository
github
Last release
9 days ago

@jill64/svelte-ogp

šŸ–¼ļø Quick OGP configuration for SvelteKit

Demo

It provides serval typed properties and default values according to The Open Graph protocol and Twitter Cards.

Quick Example

<!-- src/+layout.svelte -->
<OGP
  title="Page Title | Your Site"
  site_name="Your Site"
  description="Page Description"
  image="https://image.example.com/og-image.png"
/>

ā†“

<html prefix="og: https://ogp.me/ns#">
  <head>
    <meta property="og:title" content="Page Title | Your Site" />
    <meta property="og:site_name" content="Your Site" />
    <meta property="og:description" content="Page Description" />
    <meta
      property="og:image"
      content="https://image.example.com/og-image.png"
    />

    <!-- Default Values -->
    <meta property="og:type" content="website" />
    <meta property="og:url" content="{$page.url.href}" />
    <meta name="twitter:card" content="summary_large_image" />
  </head>
  <!-- ... -->
</html>

Full Type Definition

SSR

To add a prefix attribute to the html delivered by the server, put the following in hooks.server.js.

// hooks.server.js
export { attach as handle } from '@jill64/svelte-ogp'

Advanced Properties

The value of prefix is bound as an attribute of the html tag.
You can bind it to a meta tag by passing the value to custom_properties or custom_names.

<OGP
  prefix="custom: prefix"
  custom_properties={{
    'og:key': 'value'
  }}
  custom_names={{
    'example:foo': 'bar'
  }}
/>

ā†“

<html prefix="custom: prefix">
  <head>
    <meta property="og:key" content="value" />
    <meta property="example:foo" content="bar" />
  </head>
</html>

Structured Properties

In edge cases, multiple additional properties or arrays may be required.
custom_properties and custom_names interpret the following structured objects and output them as serialized meta tags.

const custom_properties_1 = {
  'og:image:width': 300
}

const custom_properties_2 = {
  og: {
    image: {
      width: 300
    }
  }
}

const custom_properties_3 = {
  og: [
    {
      image: [
        {
          width: [300]
        }
      ]
    }
  ]
}

These are all interpreted as follows

<meta property="og:image:width" content="300" />

This allows for the following notations

<OGP
  custom_properties={{
    og: {
      locale: [
        en_GB,
        {
          alternate: ['fr_FR', 'es_ES']
        }
      ],
      image: [
        {
          '': 'https://example.com/image.jpg',
          width: '300',
          height: '400'
        },
        'https://example.com/image-2.jpg',
        {
          '': 'https://example.com/image-3.jpg',
          height: '1000'
        }
      ]
    }
  }}
/>

ā†“

<meta property="og:locale" content="en_GB" />
<meta property="og:locale:alternate" content="fr_FR" />
<meta property="og:locale:alternate" content="es_ES" />

<meta property="og:image" content="https://example.com/image.jpg" />
<meta property="og:image:width" content="300" />
<meta property="og:image:height" content="400" />

<meta property="og:image" content="https://example.com/image-2.jpg" />

<meta property="og:image" content="https://example.com/image-3.jpg" />
<meta property="og:image:height" content="1000" />

License

MIT

1.1.24

9 days ago

1.1.23

18 days ago

1.1.22

20 days ago

1.1.21

30 days ago

1.1.20

1 month ago

1.1.19

1 month ago

1.1.18

1 month ago

1.1.17

1 month ago

1.1.16

2 months ago

1.1.15

2 months ago

1.1.14

2 months ago

1.1.12

3 months ago

1.1.13

3 months ago

1.1.11

3 months ago

1.1.10

3 months ago

1.1.9

4 months ago

1.1.8

4 months ago

1.1.7

4 months ago

1.1.6

4 months ago

1.1.5

4 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.1.2

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.0.0

5 months ago

0.1.0

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago