GithubHelp home page GithubHelp logo

Comments (8)

oekazuma avatar oekazuma commented on May 26, 2024 1

Yes! PR please.

from svelte-meta-tags.

oekazuma avatar oekazuma commented on May 26, 2024

If you are using SvelteKit, we recommend writing as follows

+layout.svelte

<script>
  import { MetaTags } from 'svelte-meta-tags';
  import { page } from '$app/stores';

  export let data;

  $: metaTags = {
    titleTemplate: '%s | Svelte Meta Tags',
    ...$page.data.metaTagsChild,
  };
</script>

{#if metaTagsChild}
  <MetaTags {...metaTags} />
{/if}

+page.ts

import type { MetaTagsProps } from 'svelte-meta-tags';

export const load = async ({ url }) => {
  const metaTags: MetaTagsProps = Object.freeze({
    title: 'page title',
    description: 'Description',
    openGraph: {
      type: 'website',
      url: new URL(url.pathname, url.origin).href,
      locale: 'en_IE',
      title: 'Open Graph Title',
      description: 'Open Graph Description',
    },
  });

  return {
    metaTagsChild,
  };
};

from svelte-meta-tags.

TristanBrotherton avatar TristanBrotherton commented on May 26, 2024

Thank you. Would you accept a PR with this added to the documentation?

from svelte-meta-tags.

TristanBrotherton avatar TristanBrotherton commented on May 26, 2024

PR added - closing this for hygiene, thank you!

from svelte-meta-tags.

fromaline avatar fromaline commented on May 26, 2024

@oekazuma, hi! First of all, thanks for the project! It's quite handy and I use it in my SvelteKit project.

I have a minor question regarding this exact use case:
Do I need to do Object.freeze in load function? Or it's just a personal preference?

It seems like this works fine too:

import type { MetaTagsProps } from 'svelte-meta-tags';

export const load = async ({ url }) => {
  const metaTags: MetaTagsProps = {
    title: 'page title',
    description: 'Description',
    openGraph: {
      type: 'website',
      url: new URL(url.pathname, url.origin).href,
      locale: 'en_IE',
      title: 'Open Graph Title',
      description: 'Open Graph Description',
    },
  };

  return {
    metaTagsChild: metaTags,
  };
};

Maybe I'm missing something.

from svelte-meta-tags.

oekazuma avatar oekazuma commented on May 26, 2024

@fromaline
It is safe to use Object.freeze to prevent changes from being made to the object. It is up to the user whether to use it or not, but I personally recommend it.
I have prepared an example of its use, so please take a look at it here.

https://github.com/oekazuma/svelte-meta-tags/tree/main/example/src/routes

from svelte-meta-tags.

fromaline avatar fromaline commented on May 26, 2024

@oekazuma got it. Thanks for answering!

Your example looks good to me. Maybe we should replace the current "Overwriting default values with a child page" section with code from your example?

from svelte-meta-tags.

oekazuma avatar oekazuma commented on May 26, 2024

@fromaline
We have already updated the documentation!
https://github.com/oekazuma/svelte-meta-tags?tab=readme-ov-file#-usage

from svelte-meta-tags.

Related Issues (20)

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.