Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate Svelte 5 #1197

Merged
merged 7 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-seals-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-meta-tags': major
---

Supports Svelte 5! And Svelte 3 and Svelte 4 are no longer supported
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.17.0'
node-version: '20.18.0'
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
Expand All @@ -28,6 +28,6 @@ jobs:
- name: Run Build
run: pnpm build
- name: Install Playwright
run: pnpm dlx playwright@1.47.0 install --with-deps
run: pnpm dlx playwright@1.48.1 install --with-deps
- name: Run Playwright
run: pnpm test
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.17.0'
node-version: '20.18.0'
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Create Release Pull Request or Publish to npm
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DS_Store
.DS_Store
node_modules
dist
build
Expand Down
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
engine-strict=true
use-node-version=20.17.0
use-node-version=20.18.0
manage-package-manager-versions=true
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,31 @@ interface LinkTag {
sizes?: string;
type?: string;
color?: string;
as?: string;
as?:
| 'fetch'
| 'audio'
| 'audioworklet'
| 'document'
| 'embed'
| 'font'
| 'frame'
| 'iframe'
| 'image'
| 'json'
| 'manifest'
| 'object'
| 'paintworklet'
| 'report'
| 'script'
| 'serviceworker'
| 'sharedworker'
| 'style'
| 'track'
| 'video'
| 'webidentity'
| 'worker'
| 'xslt'
| '';
crossOrigin?: string;
referrerPolicy?: string;
}
Expand Down
6 changes: 3 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.2.5",
"@sveltejs/kit": "^2.7.1",
"@sveltejs/vite-plugin-svelte": "^3.1.2",
"@sveltejs/kit": "^2.7.2",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"just-extend": "^6.2.0",
"svelte": "^4.2.19",
"svelte": "^5.0.3",
"svelte-check": "^4.0.5",
"svelte-meta-tags": "workspace:^",
"tslib": "^2.8.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/eslint": "^9.6.1",
"eslint": "^9.13.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.45.1",
"eslint-plugin-svelte": "^2.46.0",
"globals": "^15.11.0",
"prettier": "^3.3.3",
"prettier-plugin-svelte": "^3.2.7",
Expand Down
11 changes: 6 additions & 5 deletions packages/svelte-meta-tags/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
],
"repository": {
"type": "git",
"url": "https://github.com/oekazuma/svelte-meta-tags"
"url": "git+https://github.com/oekazuma/svelte-meta-tags.git",
"directory": "packages/svelte-meta-tags"
},
"scripts": {
"dev": "vite dev",
Expand All @@ -33,19 +34,19 @@
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.2.5",
"@sveltejs/kit": "^2.7.1",
"@sveltejs/kit": "^2.7.2",
"@sveltejs/package": "^2.3.5",
"@sveltejs/vite-plugin-svelte": "^3.1.2",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"publint": "^0.2.11",
"svelte": "^4.2.19",
"svelte": "^5.0.3",
"svelte-check": "^4.0.5",
"tslib": "^2.8.0",
"typescript": "^5.6.3",
"vite": "^5.4.9",
"vitest": "^2.1.3"
},
"peerDependencies": {
"svelte": "^3.55.0 || ^4.0.0"
"svelte": "^5.0.0"
},
"exports": {
"./JsonLd.svelte": {
Expand Down
14 changes: 10 additions & 4 deletions packages/svelte-meta-tags/src/lib/JsonLd.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
import type { JsonLdProps } from './types';
import type { Thing, WithContext } from 'schema-dts';

export let output: JsonLdProps['output'] = 'head';
export let schema: JsonLdProps['schema'] = undefined;
interface Props {
output?: JsonLdProps['output'];
schema?: JsonLdProps['schema'];
}

let { output = 'head', schema = undefined }: Props = $props();

type OmitContext<T> = Omit<T, '@context'>;

$: isValid = schema && typeof schema === 'object';
let isValid = $derived(schema && typeof schema === 'object');

const createSchema = (schema: JsonLdProps['schema']) => {
const addContext = (context: OmitContext<Thing> | OmitContext<WithContext<Thing>>) => ({
Expand All @@ -20,7 +24,9 @@
: addContext(schema as OmitContext<WithContext<Thing>>);
};

$: json = `${'<scri' + 'pt type="application/ld+json">'}${JSON.stringify(createSchema(schema))}${'</scri' + 'pt>'}`;
let json = $derived(
`${'<scri' + 'pt type="application/ld+json">'}${JSON.stringify(createSchema(schema))}${'</scri' + 'pt>'}`
);
</script>

<svelte:head>
Expand Down
65 changes: 43 additions & 22 deletions packages/svelte-meta-tags/src/lib/MetaTags.svelte
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
<script lang="ts">
import type { MetaTagsProps } from './types';

export let title: MetaTagsProps['title'] = '';
export let titleTemplate: MetaTagsProps['titleTemplate'] = '';
export let robots: MetaTagsProps['robots'] = 'index,follow';
export let additionalRobotsProps: MetaTagsProps['additionalRobotsProps'] = undefined;
export let description: MetaTagsProps['description'] = undefined;
export let mobileAlternate: MetaTagsProps['mobileAlternate'] = undefined;
export let languageAlternates: MetaTagsProps['languageAlternates'] = undefined;
export let twitter: MetaTagsProps['twitter'] = undefined;
export let facebook: MetaTagsProps['facebook'] = undefined;
export let openGraph: MetaTagsProps['openGraph'] = undefined;
export let canonical: MetaTagsProps['canonical'] = undefined;
export let keywords: MetaTagsProps['keywords'] = undefined;
export let additionalMetaTags: MetaTagsProps['additionalMetaTags'] = undefined;
export let additionalLinkTags: MetaTagsProps['additionalLinkTags'] = undefined;

$: updatedTitle = titleTemplate ? (title ? titleTemplate.replace(/%s/g, title) : title) : title;

let robotsParams = '';
interface Props {
title?: MetaTagsProps['title'];
titleTemplate?: MetaTagsProps['titleTemplate'];
robots?: MetaTagsProps['robots'];
additionalRobotsProps?: MetaTagsProps['additionalRobotsProps'];
description?: MetaTagsProps['description'];
mobileAlternate?: MetaTagsProps['mobileAlternate'];
languageAlternates?: MetaTagsProps['languageAlternates'];
twitter?: MetaTagsProps['twitter'];
facebook?: MetaTagsProps['facebook'];
openGraph?: MetaTagsProps['openGraph'];
canonical?: MetaTagsProps['canonical'];
keywords?: MetaTagsProps['keywords'];
additionalMetaTags?: MetaTagsProps['additionalMetaTags'];
additionalLinkTags?: MetaTagsProps['additionalLinkTags'];
}

let {
title = '',
titleTemplate = '',
robots = 'index,follow',
additionalRobotsProps = undefined,
description = undefined,
mobileAlternate = undefined,
languageAlternates = undefined,
twitter = undefined,
facebook = undefined,
openGraph = undefined,
canonical = undefined,
keywords = undefined,
additionalMetaTags = undefined,
additionalLinkTags = undefined
}: Props = $props();
shamokit marked this conversation as resolved.
Show resolved Hide resolved

let updatedTitle = $derived(titleTemplate ? (title ? titleTemplate.replace(/%s/g, title) : title) : title);

let robotsParams = $state('');
if (additionalRobotsProps) {
const {
nosnippet,
Expand All @@ -38,9 +57,11 @@
}${maxVideoPreview ? `,max-video-preview:${maxVideoPreview}` : ''}${notranslate ? ',notranslate' : ''}`;
}

$: if (!robots && additionalRobotsProps) {
console.warn('additionalRobotsProps cannot be used when robots is set to false');
}
$effect(() => {
if (!robots && additionalRobotsProps) {
console.warn('additionalRobotsProps cannot be used when robots is set to false');
}
});
</script>

<svelte:head>
Expand Down Expand Up @@ -289,7 +310,7 @@

{#if additionalMetaTags && Array.isArray(additionalMetaTags)}
{#each additionalMetaTags as tag}
<meta {...tag} />
<meta {...tag.httpEquiv ? { ...tag, 'http-equiv': tag.httpEquiv } : tag} />
{/each}
{/if}

Expand Down
26 changes: 25 additions & 1 deletion packages/svelte-meta-tags/src/lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,31 @@ export interface LinkTag {
sizes?: string;
type?: string;
color?: string;
as?: string;
as?:
| 'fetch'
| 'audio'
| 'audioworklet'
| 'document'
| 'embed'
| 'font'
| 'frame'
| 'iframe'
| 'image'
| 'json'
| 'manifest'
| 'object'
| 'paintworklet'
| 'report'
| 'script'
| 'serviceworker'
| 'sharedworker'
| 'style'
| 'track'
| 'video'
| 'webidentity'
| 'worker'
| 'xslt'
| '';
crossOrigin?: string;
referrerPolicy?: string;
}
Expand Down
Loading