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

update to vanilla cookie consent 3.0.0 #16

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
103 changes: 53 additions & 50 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
{
"name": "@jop-software/astro-cookieconsent",
"version": "2.0.0",
"description": "vanilla-cookieconsent for astro",
"type": "module",
"license": "GPL-3.0-or-later",
"types": "./dist/main.d.ts",
"keywords": [
"astro-integration",
"astro-component",
"cookieconsent",
"consent",
"tracking",
"gdpr"
],
"contributors": [
{
"name": "Johannes Przymusinski",
"email": "[email protected]",
"url": "https://jop-software.de"
}
],
"exports": {
".": {
"import": "./dist/astro-cookieconsent.es.js",
"require": "./dist/astro-cookieconsent.umd.js"
}
"name": "@jop-software/astro-cookieconsent",
"version": "2.0.0",
"description": "vanilla-cookieconsent for astro",
"type": "module",
"license": "GPL-3.0-or-later",
"types": "./dist/main.d.ts",
"keywords": [
"astro-integration",
"astro-component",
"cookieconsent",
"consent",
"tracking",
"gdpr"
],
"contributors": [
{
"name": "Johannes Przymusinski",
"email": "[email protected]",
"url": "https://jop-software.de"
},
"main": "./dist/astro-cookieconsent.umd.js",
"module": "./dist/astro-cookieconsent.es.js",
"files": [
"dist"
],
"scripts": {
"build": "vite build && tsc --emitDeclarationOnly",
"build:watch": "vite build --watch",
"dev": "vite",
"prettier:check": "prettier --check src",
"prettier:write": "prettier --write src"
},
"devDependencies": {
"astro": "^1.8.0",
"prettier": "^2.7.1",
"typescript": "^4.9.4",
"vite": "^4.0.3"
},
"repository": {
"type": "git",
"url": "https://github.com/jop-software/astro-cookieconsent"
},
"peerDependencies": {
"vanilla-cookieconsent": "^2.9.1"
{
"name": "Artur Bauer"
}
],
"exports": {
".": {
"import": "./dist/astro-cookieconsent.es.js",
"require": "./dist/astro-cookieconsent.umd.js"
}
},
"main": "./dist/astro-cookieconsent.umd.js",
"module": "./dist/astro-cookieconsent.es.js",
"files": [
"dist"
],
"scripts": {
"build": "vite build && tsc --emitDeclarationOnly",
"build:watch": "vite build --watch",
"dev": "vite",
"prettier:check": "prettier --check src",
"prettier:write": "prettier --write src"
},
"devDependencies": {
"astro": "^1.8.0",
"prettier": "^2.7.1",
"typescript": "^4.9.4",
"vite": "^4.0.3"
},
"repository": {
"type": "git",
"url": "https://github.com/jop-software/astro-cookieconsent"
},
"peerDependencies": {
"vanilla-cookieconsent": "^3.0.0"
}
}
21 changes: 7 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
import * as CookieConsent from "vanilla-cookieconsent";
import { type AstroIntegration } from "astro";
import { type CookieConsentConfig } from "vanilla-cookieconsent";

const createPlugin = (config: UserConfig) => {
const createPlugin = (config: CookieConsentConfig): AstroIntegration => {
return {
name: "@jop-software/astro-cookieconsent",
hooks: {
"astro:config:setup": async ({ injectScript }: any) => {
"astro:config:setup": async ({ injectScript }) => {
injectScript(
"page",
"import 'vanilla-cookieconsent';"
"import * as cookieConsent from 'vanilla-cookieconsent';"
);
injectScript(
"page-ssr",
"import 'vanilla-cookieconsent/dist/cookieconsent.css';"
);
injectScript(
"page",
`window.cookieConsentConfiguration = ${JSON.stringify(config)}`
);
injectScript("page", `window.cookieConsent = initCookieConsent();`);
injectScript(
"page",
`window.cookieConsent.run(window.cookieConsentConfiguration);`
);
injectScript("page", `cookieConsent.run(${JSON.stringify(config)});`);
},
},
};
};

export type { CookieConsent };
export type { CookieConsentConfig };

export default createPlugin;
Loading