From b0218e182b6eba0e087c8104c0bc57b76d120fdb Mon Sep 17 00:00:00 2001 From: "create-issue-branch[bot]" <53036503+create-issue-branch[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:06:50 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Custom=20Code=20Component?= =?UTF-8?q?=20Swap=20is=20causing=20issues.=20(#112)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: create-issue-branch[bot] <53036503+create-issue-branch[bot]@users.noreply.github.com> Co-authored-by: Adam Matthiesen --- .changeset/spicy-stingrays-repeat.md | 11 +++++++++++ .../src/components/ghostrender/CodeSlot.astro | 17 ----------------- .../src/components/ghostrender/index.ts | 1 - .../src/routes/[slug].astro | 2 +- .../src/components/FeaturedPost.astro | 6 +----- .../src/components/Post.astro | 5 +---- .../src/components/astro-remote/CodeSlot.astro | 17 ----------------- .../src/components/astro-remote/index.ts | 1 - .../src/components/Page.astro | 15 +++++++-------- .../src/components/Post.astro | 15 +++++++-------- .../src/components/astro-remote/CodeSlot.astro | 17 ----------------- .../src/components/astro-remote/index.ts | 1 - .../src/components/astro-remote/CodeSlot.astro | 17 ----------------- .../src/components/astro-remote/index.ts | 1 - .../starlight-ghostcms/src/routes/[slug].astro | 2 -- .../starlight-ghostcms/src/routes/about.astro | 5 +---- playgrounds/astro-playground/astro.config.mjs | 8 ++++---- 17 files changed, 33 insertions(+), 108 deletions(-) create mode 100644 .changeset/spicy-stingrays-repeat.md delete mode 100644 packages/astro-ghostcms-brutalbyelian/src/components/ghostrender/CodeSlot.astro delete mode 100644 packages/astro-ghostcms-catppuccin/src/components/astro-remote/CodeSlot.astro delete mode 100644 packages/astro-ghostcms-catppuccin/src/components/astro-remote/index.ts delete mode 100644 packages/astro-ghostcms-theme-default/src/components/astro-remote/CodeSlot.astro delete mode 100644 packages/astro-ghostcms-theme-default/src/components/astro-remote/index.ts delete mode 100644 packages/starlight-ghostcms/src/components/astro-remote/CodeSlot.astro delete mode 100644 packages/starlight-ghostcms/src/components/astro-remote/index.ts diff --git a/.changeset/spicy-stingrays-repeat.md b/.changeset/spicy-stingrays-repeat.md new file mode 100644 index 000000000..5dccbcbc8 --- /dev/null +++ b/.changeset/spicy-stingrays-repeat.md @@ -0,0 +1,11 @@ +--- +"@matthiesenxyz/astro-ghostcms-brutalbyelian": patch +"@matthiesenxyz/astro-ghostcms-theme-default": patch +"@matthiesenxyz/astro-ghostcms-catppuccin": patch +"@matthiesenxyz/starlight-ghostcms": patch +--- + +fix: + +- Removed CodeSlot Component that sometimes would break with some
 components
+- Will be adding at a latter time a custom component to replace this, but at this time this is now fixed.
\ No newline at end of file
diff --git a/packages/astro-ghostcms-brutalbyelian/src/components/ghostrender/CodeSlot.astro b/packages/astro-ghostcms-brutalbyelian/src/components/ghostrender/CodeSlot.astro
deleted file mode 100644
index e1400d760..000000000
--- a/packages/astro-ghostcms-brutalbyelian/src/components/ghostrender/CodeSlot.astro
+++ /dev/null
@@ -1,17 +0,0 @@
----
-import { Code } from "astro/components"
-import { parse } from "ultrahtml"
-import { querySelector } from "ultrahtml/selector"
-
-const html = await Astro.slots.render("default")
-const ast = await parse(html)
-const codetag = querySelector(ast,'code')
-const { children, attributes } = codetag
-
-const code = children[0].value
-const checkLang = attributes.class ? attributes.class.slice(9) : undefined
-
-const lang = checkLang ? checkLang : 'plaintxt'
----
-
-
\ No newline at end of file
diff --git a/packages/astro-ghostcms-brutalbyelian/src/components/ghostrender/index.ts b/packages/astro-ghostcms-brutalbyelian/src/components/ghostrender/index.ts
index d6d29a8d3..4b20ce123 100644
--- a/packages/astro-ghostcms-brutalbyelian/src/components/ghostrender/index.ts
+++ b/packages/astro-ghostcms-brutalbyelian/src/components/ghostrender/index.ts
@@ -4,6 +4,5 @@ export { default as H3 } from "./H3.astro";
 export { default as H4 } from "./H4.astro";
 export { default as H5 } from "./H5.astro";
 export { default as H6 } from "./H6.astro";
-export { default as CodeSlot } from "./CodeSlot.astro";
 export { default as Paragraph } from "./Paragraph.astro";
 export { default as astrocard } from "./astrocard.astro";
diff --git a/packages/astro-ghostcms-brutalbyelian/src/routes/[slug].astro b/packages/astro-ghostcms-brutalbyelian/src/routes/[slug].astro
index e8b217828..99546cef0 100644
--- a/packages/astro-ghostcms-brutalbyelian/src/routes/[slug].astro
+++ b/packages/astro-ghostcms-brutalbyelian/src/routes/[slug].astro
@@ -34,6 +34,7 @@ invariant(settings, "Settings are required");
       content={post.html} 
       sanitize={{ 
         allowComponents: true,
+        allowElements: ['a', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img', 'figure', 'figcaption', 'ul', 'ol', 'li', 'blockquote', 'pre', 'code', 'em', 'strong', 'del', 'hr', 'br', 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'caption', 'div', 'span', 'script', 'astrocard'],
       }}
       components={{ 
         h1: C.H1,
@@ -42,7 +43,6 @@ invariant(settings, "Settings are required");
         h4: C.H4,
         h5: C.H5,
         h6: C.H6,
-        pre: C.CodeSlot,
         p: C.Paragraph,
         astrocard: C.astrocard,
       }}
diff --git a/packages/astro-ghostcms-catppuccin/src/components/FeaturedPost.astro b/packages/astro-ghostcms-catppuccin/src/components/FeaturedPost.astro
index 1eb32a6d0..9d505cfb7 100644
--- a/packages/astro-ghostcms-catppuccin/src/components/FeaturedPost.astro
+++ b/packages/astro-ghostcms-catppuccin/src/components/FeaturedPost.astro
@@ -4,7 +4,6 @@ import FeatureImage from "./FeatureImage.astro";
 import AuthorList from "./AuthorList.astro";
 import { formatDate } from "../utils";
 import { Markup } from 'astro-remote';
-import * as render from '../components/astro-remote';
 
 export type Props = {
   posts: Post[];
@@ -66,10 +65,7 @@ const latestFeatured = posts[0]
     content={latestFeatured.html} 
     sanitize={{ 
       allowComponents: true, 
-      allowElements: ['a', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img', 'figure', 'figcaption', 'ul', 'ol', 'li', 'blockquote', 'pre', 'code', 'em', 'strong', 'del', 'hr', 'br', 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'caption', 'div', 'span', 'script', 'getgist', 'getgistgroup', 'astrocard'],
-    }}
-    components={{
-      pre: render.CodeSlot
+      allowElements: ['a', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img', 'figure', 'figcaption', 'ul', 'ol', 'li', 'blockquote', 'pre', 'code', 'em', 'strong', 'del', 'hr', 'br', 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'caption', 'div', 'span', 'script', 'astrocard'],
     }}
   /> }
       
diff --git a/packages/astro-ghostcms-catppuccin/src/components/Post.astro b/packages/astro-ghostcms-catppuccin/src/components/Post.astro
index 673c6f3e2..3f268b188 100644
--- a/packages/astro-ghostcms-catppuccin/src/components/Post.astro
+++ b/packages/astro-ghostcms-catppuccin/src/components/Post.astro
@@ -3,7 +3,6 @@ import PostHero from "../components/PostHero.astro";
 import PostFooter from "../components/PostFooter.astro";
 import { getFeaturedPosts, invariant, type Post, type Settings } from "@matthiesenxyz/astro-ghostcms/api";
 import { Markup } from 'astro-remote';
-import * as render from '../components/astro-remote';
 
 export type Props = {
   post: Post;
@@ -34,9 +33,7 @@ invariant(settings, "Settings not found");
     content={post.html} 
     sanitize={{ 
       allowComponents: true,
-    }}
-    components={{
-      pre: render.CodeSlot
+      allowElements: ['a', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img', 'figure', 'figcaption', 'ul', 'ol', 'li', 'blockquote', 'pre', 'code', 'em', 'strong', 'del', 'hr', 'br', 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'caption', 'div', 'span', 'script', 'astrocard'],
     }}
   />
 
diff --git a/packages/astro-ghostcms-catppuccin/src/components/astro-remote/CodeSlot.astro b/packages/astro-ghostcms-catppuccin/src/components/astro-remote/CodeSlot.astro
deleted file mode 100644
index e1400d760..000000000
--- a/packages/astro-ghostcms-catppuccin/src/components/astro-remote/CodeSlot.astro
+++ /dev/null
@@ -1,17 +0,0 @@
----
-import { Code } from "astro/components"
-import { parse } from "ultrahtml"
-import { querySelector } from "ultrahtml/selector"
-
-const html = await Astro.slots.render("default")
-const ast = await parse(html)
-const codetag = querySelector(ast,'code')
-const { children, attributes } = codetag
-
-const code = children[0].value
-const checkLang = attributes.class ? attributes.class.slice(9) : undefined
-
-const lang = checkLang ? checkLang : 'plaintxt'
----
-
-
\ No newline at end of file
diff --git a/packages/astro-ghostcms-catppuccin/src/components/astro-remote/index.ts b/packages/astro-ghostcms-catppuccin/src/components/astro-remote/index.ts
deleted file mode 100644
index f5badee59..000000000
--- a/packages/astro-ghostcms-catppuccin/src/components/astro-remote/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as CodeSlot } from "./CodeSlot.astro";
diff --git a/packages/astro-ghostcms-theme-default/src/components/Page.astro b/packages/astro-ghostcms-theme-default/src/components/Page.astro
index ccfc64cd6..97e169e5c 100644
--- a/packages/astro-ghostcms-theme-default/src/components/Page.astro
+++ b/packages/astro-ghostcms-theme-default/src/components/Page.astro
@@ -2,7 +2,7 @@
 import FeatureImage from "../components/FeatureImage.astro";
 import type { Settings, Page } from "@matthiesenxyz/astro-ghostcms/api";
 import { Markup } from 'astro-remote';
-import * as render from '../components/astro-remote';
+
 export type Props = {
   page: Page;
   settings: Settings;
@@ -27,13 +27,12 @@ const { page, settings, pageClass } = Astro.props as Props;
     

{page.title}

+ content={page.html} + sanitize={{ + allowComponents: true, + allowElements: ['a', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img', 'figure', 'figcaption', 'ul', 'ol', 'li', 'blockquote', 'pre', 'code', 'em', 'strong', 'del', 'hr', 'br', 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'caption', 'div', 'span', 'script', 'astrocard'], + }} + />
diff --git a/packages/astro-ghostcms-theme-default/src/components/Post.astro b/packages/astro-ghostcms-theme-default/src/components/Post.astro index 0103f223e..ddaa51f7b 100644 --- a/packages/astro-ghostcms-theme-default/src/components/Post.astro +++ b/packages/astro-ghostcms-theme-default/src/components/Post.astro @@ -3,7 +3,7 @@ import PostHero from "../components/PostHero.astro"; import PostFooter from "../components/PostFooter.astro"; import {invariant, type Post, type Settings } from "@matthiesenxyz/astro-ghostcms/api"; import { Markup } from 'astro-remote'; -import * as render from '../components/astro-remote'; + export type Props = { post: Post; settings: Settings; @@ -19,13 +19,12 @@ invariant(settings, "Settings not found");
+ content={post.html} + sanitize={{ + allowComponents: true, + allowElements: ['a', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img', 'figure', 'figcaption', 'ul', 'ol', 'li', 'blockquote', 'pre', 'code', 'em', 'strong', 'del', 'hr', 'br', 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'caption', 'div', 'span', 'script', 'astrocard'], + }} + />
diff --git a/packages/astro-ghostcms-theme-default/src/components/astro-remote/CodeSlot.astro b/packages/astro-ghostcms-theme-default/src/components/astro-remote/CodeSlot.astro deleted file mode 100644 index 05629226b..000000000 --- a/packages/astro-ghostcms-theme-default/src/components/astro-remote/CodeSlot.astro +++ /dev/null @@ -1,17 +0,0 @@ ---- -import { Code } from "astro/components" -import { parse } from "ultrahtml" -import { querySelector } from "ultrahtml/selector" - -const html = await Astro.slots.render("default") -const ast = await parse(html) -const codetag = querySelector(ast,'code') -const { children, attributes } = codetag - -const code = children[0].value -const checkLang = attributes.class ? attributes.class.slice(9) : undefined - -const lang = checkLang ? checkLang : 'plaintext' ---- - - \ No newline at end of file diff --git a/packages/astro-ghostcms-theme-default/src/components/astro-remote/index.ts b/packages/astro-ghostcms-theme-default/src/components/astro-remote/index.ts deleted file mode 100644 index f5badee59..000000000 --- a/packages/astro-ghostcms-theme-default/src/components/astro-remote/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as CodeSlot } from "./CodeSlot.astro"; diff --git a/packages/starlight-ghostcms/src/components/astro-remote/CodeSlot.astro b/packages/starlight-ghostcms/src/components/astro-remote/CodeSlot.astro deleted file mode 100644 index 99457158c..000000000 --- a/packages/starlight-ghostcms/src/components/astro-remote/CodeSlot.astro +++ /dev/null @@ -1,17 +0,0 @@ ---- -import { Code } from "@astrojs/starlight/components" -import { parse } from "ultrahtml" -import { querySelector } from "ultrahtml/selector" - -const html = await Astro.slots.render("default") -const ast = await parse(html) -const codetag = querySelector(ast,'code') -const { children, attributes } = codetag - -const code = children[0].value -const checkLang = attributes.class ? attributes.class.slice(9) : undefined - -const lang = checkLang ? checkLang : 'txt' ---- - - \ No newline at end of file diff --git a/packages/starlight-ghostcms/src/components/astro-remote/index.ts b/packages/starlight-ghostcms/src/components/astro-remote/index.ts deleted file mode 100644 index f5badee59..000000000 --- a/packages/starlight-ghostcms/src/components/astro-remote/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as CodeSlot } from "./CodeSlot.astro"; diff --git a/packages/starlight-ghostcms/src/routes/[slug].astro b/packages/starlight-ghostcms/src/routes/[slug].astro index 8db132f68..2703a87ab 100644 --- a/packages/starlight-ghostcms/src/routes/[slug].astro +++ b/packages/starlight-ghostcms/src/routes/[slug].astro @@ -6,7 +6,6 @@ import { getPageProps } from '../utils/page'; import { getAllPosts } from '../utils/api'; import Metadata from '../components/Metadata.astro'; import { Markup } from 'astro-remote'; -import * as render from '../components/astro-remote'; import * as Gists from '@matthiesenxyz/astro-gists/components'; export async function getStaticPaths() { @@ -51,7 +50,6 @@ const pageProps = getPageProps(post.title) allowComponents: true, }} components={{ - pre: render.CodeSlot, getgist: Gists.GetGist, getgistgroup: Gists.GetGistGroup, }} diff --git a/packages/starlight-ghostcms/src/routes/about.astro b/packages/starlight-ghostcms/src/routes/about.astro index ae5e2c8c1..46a17adee 100644 --- a/packages/starlight-ghostcms/src/routes/about.astro +++ b/packages/starlight-ghostcms/src/routes/about.astro @@ -6,7 +6,6 @@ import Page from '../components/Page.astro' import { getPageProps } from '../utils/page' import { getSluggedPage } from '../utils/api' import { Markup } from 'astro-remote' -import * as render from '../components/astro-remote'; const aboutPage = await getSluggedPage("about"); @@ -26,9 +25,7 @@ const pageProps = getPageProps(aboutPage ? aboutPage.post.title : "") sanitize={{ allowComponents: true, }} - components={{ - pre: render.CodeSlot - }} /> + /> }