From 2cbc4b49d00dd79844d67a2905260c627444d203 Mon Sep 17 00:00:00 2001 From: Adam Matthiesen Date: Wed, 13 Mar 2024 04:48:49 -0700 Subject: [PATCH] Update Theme Handling... Start to a huge project --- .../brutalunocss-preset.ts | 25 ---------- .../astro-ghostcms-brutalbyelian/package.json | 2 - .../astro-ghostcms-catppuccin/cat-frappe.js | 19 -------- .../astro-ghostcms-catppuccin/cat-latte.js | 19 -------- .../cat-macchiato.js | 19 -------- .../astro-ghostcms-catppuccin/cat-mocha.js | 19 -------- .../astro-ghostcms-catppuccin/package.json | 13 +---- .../src/components/FeaturedPost.astro | 3 +- .../src/components/Post.astro | 2 +- packages/astro-ghostcms/package.json | 7 +++ packages/astro-ghostcms/src/astro-ghostcms.ts | 1 + .../astro-ghostcms-themeprovider.ts | 48 ++++++++++++++++++- .../astro-ghostcms/src/schemas/userconfig.ts | 18 +++++++ playgrounds/astro-playground/astro.config.mjs | 9 ++-- .../astro-playground/tailwind.config.cjs | 4 -- playgrounds/astro-playground/uno.config.ts | 6 --- pnpm-lock.yaml | 37 ++++++++++++-- 17 files changed, 114 insertions(+), 137 deletions(-) delete mode 100644 packages/astro-ghostcms-brutalbyelian/brutalunocss-preset.ts delete mode 100644 packages/astro-ghostcms-catppuccin/cat-frappe.js delete mode 100644 packages/astro-ghostcms-catppuccin/cat-latte.js delete mode 100644 packages/astro-ghostcms-catppuccin/cat-macchiato.js delete mode 100644 packages/astro-ghostcms-catppuccin/cat-mocha.js delete mode 100644 playgrounds/astro-playground/tailwind.config.cjs delete mode 100644 playgrounds/astro-playground/uno.config.ts diff --git a/packages/astro-ghostcms-brutalbyelian/brutalunocss-preset.ts b/packages/astro-ghostcms-brutalbyelian/brutalunocss-preset.ts deleted file mode 100644 index 63db751e..00000000 --- a/packages/astro-ghostcms-brutalbyelian/brutalunocss-preset.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { - definePreset, - presetIcons, - presetTypography, - presetWind, -} from "unocss"; - -export default definePreset(() => { - return { - name: "brutalTheme", - presets: [ - presetWind(), - presetIcons({ - collections: { - //@ts-expect-error - logos: () => - import("@iconify-json/logos/icons.json").then((i) => i.default), - uil: () => - import("@iconify-json/uil/icons.json").then((l) => l.default), - }, - }), - presetTypography(), - ], - }; -}); diff --git a/packages/astro-ghostcms-brutalbyelian/package.json b/packages/astro-ghostcms-brutalbyelian/package.json index 47f775ce..b421ab95 100644 --- a/packages/astro-ghostcms-brutalbyelian/package.json +++ b/packages/astro-ghostcms-brutalbyelian/package.json @@ -25,13 +25,11 @@ "url": "https://github.com/MatthiesenXYZ/astro-ghostcms/issues", "email": "issues@astro-ghostcms.xyz" }, - "main": "./brutalunocss-preset.ts", "files": [ "src", "brutalunocss-preset.ts" ], "exports": { - ".": "./brutalunocss-preset.ts", "./index.astro": "./src/routes/index.astro", "./[slug].astro": "./src/routes/[slug].astro", "./tags.astro": "./src/routes/tags.astro", diff --git a/packages/astro-ghostcms-catppuccin/cat-frappe.js b/packages/astro-ghostcms-catppuccin/cat-frappe.js deleted file mode 100644 index c83ff066..00000000 --- a/packages/astro-ghostcms-catppuccin/cat-frappe.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @type {import('tailwindcss').Config} */ -import { fontFamily as _fontFamily } from "tailwindcss/defaultTheme"; -export const content = [ - "./node_modules/@matthiesenxyz/astro-ghostcms-catppuccin/src/**/*.{astro,js,css,ts}", -]; -export const theme = { - extend: { - fontFamily: { - sans: ["Inter Variable", "Inter", ..._fontFamily.sans], - }, - }, -}; -export const plugins = [ - require("@tailwindcss/typography"), - require("@catppuccin/tailwindcss")({ - prefix: "ctp", - defaultFlavour: "frappe", - }), -]; diff --git a/packages/astro-ghostcms-catppuccin/cat-latte.js b/packages/astro-ghostcms-catppuccin/cat-latte.js deleted file mode 100644 index 1a62ecd1..00000000 --- a/packages/astro-ghostcms-catppuccin/cat-latte.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @type {import('tailwindcss').Config} */ -import { fontFamily as _fontFamily } from "tailwindcss/defaultTheme"; -export const content = [ - "./node_modules/@matthiesenxyz/astro-ghostcms-catppuccin/src/**/*.{astro,js,css,ts}", -]; -export const theme = { - extend: { - fontFamily: { - sans: ["Inter Variable", "Inter", ..._fontFamily.sans], - }, - }, -}; -export const plugins = [ - require("@tailwindcss/typography"), - require("@catppuccin/tailwindcss")({ - prefix: "ctp", - defaultFlavour: "latte", - }), -]; diff --git a/packages/astro-ghostcms-catppuccin/cat-macchiato.js b/packages/astro-ghostcms-catppuccin/cat-macchiato.js deleted file mode 100644 index 1a06af40..00000000 --- a/packages/astro-ghostcms-catppuccin/cat-macchiato.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @type {import('tailwindcss').Config} */ -import { fontFamily as _fontFamily } from "tailwindcss/defaultTheme"; -export const content = [ - "./node_modules/@matthiesenxyz/astro-ghostcms-catppuccin/src/**/*.{astro,js,css,ts}", -]; -export const theme = { - extend: { - fontFamily: { - sans: ["Inter Variable", "Inter", ..._fontFamily.sans], - }, - }, -}; -export const plugins = [ - require("@tailwindcss/typography"), - require("@catppuccin/tailwindcss")({ - prefix: "ctp", - defaultFlavour: "macchiato", - }), -]; diff --git a/packages/astro-ghostcms-catppuccin/cat-mocha.js b/packages/astro-ghostcms-catppuccin/cat-mocha.js deleted file mode 100644 index d71be375..00000000 --- a/packages/astro-ghostcms-catppuccin/cat-mocha.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @type {import('tailwindcss').Config} */ -import { fontFamily as _fontFamily } from "tailwindcss/defaultTheme"; -export const content = [ - "./node_modules/@matthiesenxyz/astro-ghostcms-catppuccin/src/**/*.{astro,js,css,ts}", -]; -export const theme = { - extend: { - fontFamily: { - sans: ["Inter Variable", "Inter", ..._fontFamily.sans], - }, - }, -}; -export const plugins = [ - require("@tailwindcss/typography"), - require("@catppuccin/tailwindcss")({ - prefix: "ctp", - defaultFlavour: "mocha", - }), -]; diff --git a/packages/astro-ghostcms-catppuccin/package.json b/packages/astro-ghostcms-catppuccin/package.json index 1ae23b14..864f3e6b 100644 --- a/packages/astro-ghostcms-catppuccin/package.json +++ b/packages/astro-ghostcms-catppuccin/package.json @@ -25,21 +25,10 @@ "url": "https://github.com/MatthiesenXYZ/astro-ghostcms/issues", "email": "issues@astro-ghostcms.xyz" }, - "main": "./cat-macchiato.js", "files": [ - "src", - "cat-frappe.js", - "cat-latte.js", - "cat-macchiato.js", - "cat-mocha.js", - "index.js" + "src" ], "exports": { - ".": "./cat-macchiato.js", - "./frappe": "./cat-frappe.js", - "./latte": "./cat-latte.js", - "./macchiato": "./cat-macchiato.js", - "./mocha": "./cat-mocha.js", "./index.astro": "./src/routes/index.astro", "./[slug].astro": "./src/routes/[slug].astro", "./tags.astro": "./src/routes/tags.astro", diff --git a/packages/astro-ghostcms-catppuccin/src/components/FeaturedPost.astro b/packages/astro-ghostcms-catppuccin/src/components/FeaturedPost.astro index 47d9b2ff..36b65116 100644 --- a/packages/astro-ghostcms-catppuccin/src/components/FeaturedPost.astro +++ b/packages/astro-ghostcms-catppuccin/src/components/FeaturedPost.astro @@ -63,9 +63,8 @@ const latestFeatured = posts[0]
-
+
- {useRemote ? (latestFeatured && -
+
{useRemote ? ( (), + }), verbose: z.coerce.boolean().optional(), }), plugins: [...corePlugins], @@ -16,7 +24,12 @@ export default defineIntegration({ const DEFAULT_THEME = "@matthiesenxyz/astro-ghostcms-theme-default"; return { - "astro:config:setup": ({ watchIntegration, injectRoute, logger }) => { + "astro:config:setup": ({ + watchIntegration, + injectRoute, + logger, + addIntegration, + }) => { watchIntegration(resolve()); const themeLogger = logger.fork( @@ -44,7 +57,40 @@ export default defineIntegration({ verboseLogsInfo(`${c.bold(c.cyan("Injecting Theme:"))} ${c.bold(c.underline(c.magenta(options.theme)))}`); } + const checkTheme = () => { + if (options.theme === "@matthiesenxyz/astro-ghostcms-catppuccin") { + return {defaultFlavour: options.catppuccinThemeOptions.defaultFlavor} + } + return {defaultFlavor: undefined}; + } + // Add the UnoCSS integration + addIntegration( + UnoCSS({ + configFile: false, + injectReset: true, + presets: [ + presetUno(), + presetWind({ + variablePrefix: "" + }), + presetIcons({ + collections: { + uil: () => + import("@iconify-json/uil/icons.json") + .then((l) => l.default), + }, + }), + presetTypography(), + presetCatppuccin(checkTheme()), + ], + transformers: [ + transformerDirectives(), + ], + }) + ) + + // Inject Routes injectRoute({ pattern: "/", entrypoint: `${options.theme}/index.astro`, diff --git a/packages/astro-ghostcms/src/schemas/userconfig.ts b/packages/astro-ghostcms/src/schemas/userconfig.ts index 6455a712..00258e7f 100644 --- a/packages/astro-ghostcms/src/schemas/userconfig.ts +++ b/packages/astro-ghostcms/src/schemas/userconfig.ts @@ -2,6 +2,8 @@ import type { SitemapOptions } from "@astrojs/sitemap"; import type { RobotsTxtOptions } from "astro-robots-txt"; import { z } from "astro/zod"; +type CATPPUCCINFLAVOURS = "latte" | "frappe" | "macchiato" | "mocha"; + export const GhostUserConfigSchema = z.object({ /** OPTIONAL - Either set the URL in your .env or put it here * @example @@ -26,7 +28,23 @@ export const GhostUserConfigSchema = z.object({ * @default "@matthiesenxyz/astro-ghostcms-theme-default" */ theme: z.string().default("@matthiesenxyz/astro-ghostcms-theme-default"), + /** + * OPTIONAL - Catppuccin Theme Options + */ + catppuccinThemeOptions: z.object({ + /** OPTIONAL - Set the default flavor for the catppuccino theme + * @default "macchiato" + */ + defaultFlavor: z.custom().optional().default("macchiato"), + }).optional().default({}), + /** + * OPTIONAL - Astro Remote Configuration + */ astroRemote: z.object({ + /** + * OPTIONAL - Enable or Disable the Astro Remote + * @default true + */ enable: z.boolean().default(true), }).optional().default({}), }).optional().default({}), diff --git a/playgrounds/astro-playground/astro.config.mjs b/playgrounds/astro-playground/astro.config.mjs index e7734a4f..027e11ba 100644 --- a/playgrounds/astro-playground/astro.config.mjs +++ b/playgrounds/astro-playground/astro.config.mjs @@ -1,18 +1,17 @@ import ghostcms from "@matthiesenxyz/astro-ghostcms"; import { defineConfig } from "astro/config"; -// import tailwind from "@astrojs/tailwind"; -// import UnoCSS from "unocss/astro"; // https://astro.build/config export default defineConfig({ site: "https://demo.astro-ghostcms.xyz/", integrations: [ - //tailwind(), - // UnoCSS({ injectReset: true }), ghostcms({ ghostURL: 'https://ghostdemo.matthiesen.xyz', ThemeProvider: { - theme: "@matthiesenxyz/astro-ghostcms-theme-default", + theme: "@matthiesenxyz/astro-ghostcms-catppuccin", + catppuccinThemeOptions: { + defaultFlavor: "latte", + }, astroRemote: { enable: true, }, diff --git a/playgrounds/astro-playground/tailwind.config.cjs b/playgrounds/astro-playground/tailwind.config.cjs deleted file mode 100644 index a0e05b42..00000000 --- a/playgrounds/astro-playground/tailwind.config.cjs +++ /dev/null @@ -1,4 +0,0 @@ -/** @type {import('tailwindcss').Config} */ -module.exports = { - presets: [require("@matthiesenxyz/astro-ghostcms-catppuccin/macchiato")], -}; diff --git a/playgrounds/astro-playground/uno.config.ts b/playgrounds/astro-playground/uno.config.ts deleted file mode 100644 index e3f5c156..00000000 --- a/playgrounds/astro-playground/uno.config.ts +++ /dev/null @@ -1,6 +0,0 @@ -import brutalTheme from "@matthiesenxyz/astro-ghostcms-brutalbyelian"; -import { defineConfig } from "unocss"; - -export default defineConfig({ - presets: [brutalTheme()], -}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4ba16637..2bfa960a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,6 +32,12 @@ importers: '@astrojs/sitemap': specifier: ^3.1.1 version: 3.1.1 + '@iconify-json/logos': + specifier: ^1.1.41 + version: 1.1.42 + '@iconify-json/uil': + specifier: ^1.1.8 + version: 1.1.8 '@matthiesenxyz/astro-ghostcms-theme-default': specifier: ^0.1.19 version: link:../astro-ghostcms-theme-default @@ -44,6 +50,12 @@ importers: '@ts-ghost/core-api': specifier: ^6.0.0 version: 6.0.0 + '@unocss/astro': + specifier: ^0.58.5 + version: 0.58.5(vite@5.1.6) + '@unocss/reset': + specifier: ^0.58.5 + version: 0.58.5 astro: specifier: '>=4.4.1' version: 4.5.0(@types/node@20.11.25) @@ -68,6 +80,12 @@ importers: satori-html: specifier: ^0.3.2 version: 0.3.2 + unocss: + specifier: ^0.58.5 + version: 0.58.5(postcss@8.4.35)(vite@5.1.6) + unocss-preset-catppuccin: + specifier: 0.1.0 + version: 0.1.0 vite: specifier: ^5.1.6 version: 5.1.6(@types/node@20.11.25) @@ -78,6 +96,9 @@ importers: '@types/node': specifier: ^20.11.25 version: 20.11.25 + '@unocss/transformer-directives': + specifier: 0.58.5 + version: 0.58.5 vitest: specifier: ^1.3.1 version: 1.3.1(@types/node@20.11.25)(@vitest/ui@1.3.1) @@ -941,6 +962,10 @@ packages: dev: true optional: true + /@catppuccin/palette@0.1.8: + resolution: {integrity: sha512-41quIj08vgPMy8kQxQb0+VqxuTlo2xfNYGSgOuiJXNojWnGuhLxBc61jgu2jiZYGNXVqgVNGWwmWEUf6s32jiA==} + dev: false + /@catppuccin/tailwindcss@0.1.6(tailwindcss@3.4.1): resolution: {integrity: sha512-V+Y0AwZ5SSyvOVAcDl7Ng30xy+m82OKnEJ+9+kcZZ7lRyXuZrAb2GScdq9XR3v+ggt8qiZ/G4TvaC9cJ88AAXA==} peerDependencies: @@ -2656,7 +2681,7 @@ packages: '@unocss/core': 0.58.5 '@unocss/reset': 0.58.5 '@unocss/vite': 0.58.5(vite@5.1.6) - vite: 5.1.6(sass@1.71.1) + vite: 5.1.6(@types/node@20.11.25) transitivePeerDependencies: - rollup @@ -2831,7 +2856,7 @@ packages: chokidar: 3.6.0 fast-glob: 3.3.2 magic-string: 0.30.8 - vite: 5.1.6(sass@1.71.1) + vite: 5.1.6(@types/node@20.11.25) transitivePeerDependencies: - rollup @@ -8539,6 +8564,12 @@ packages: engines: {node: '>= 10.0.0'} dev: false + /unocss-preset-catppuccin@0.1.0: + resolution: {integrity: sha512-/NU+FcwLMzh0ZzIJHZ/0O4RAFy+KdwrehUy8rBS8rtP0ER3TUdTytzxnGYlehu3bcmlSIsi6yOQ9X08YMnR8dw==} + dependencies: + '@catppuccin/palette': 0.1.8 + dev: false + /unocss@0.58.5(postcss@8.4.35)(vite@5.1.6): resolution: {integrity: sha512-0g4P6jLgRRNnhscxw7nQ9RHGrKJ1UPPiHPet+YT3TXUcmy4mTiYgo9+kGQf5bjyrzsELJ10cT6Qz2y6g9Tls4g==} engines: {node: '>=14'} @@ -8571,7 +8602,7 @@ packages: '@unocss/transformer-directives': 0.58.5 '@unocss/transformer-variant-group': 0.58.5 '@unocss/vite': 0.58.5(vite@5.1.6) - vite: 5.1.6(sass@1.71.1) + vite: 5.1.6(@types/node@20.11.25) transitivePeerDependencies: - postcss - rollup