Skip to content

Commit

Permalink
style overrides for newsletter embed (#1718)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbos committed Jun 21, 2024
1 parent 59dba74 commit a963ee6
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"gpt-3-encoder": "^1.1.4",
"gray-matter": "^4.0.3",
"js-cookie": "^3.0.5",
"linkedom": "^0.18.3",
"media-chrome": "^3.2.0",
"npm-run-all": "^4.1.5",
"openai": "^3.3.0",
Expand Down
94 changes: 90 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/routes/(site)/snackpack/[issue_id]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { error, json } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { env } from '$env/dynamic/private';
import type { Broadcast } from '../proxy+page.server';
import { parseHTML } from 'linkedom';

export const load: PageServerLoad = async function ({ setHeaders, params, locals }) {
// 1. Fetch a broadcast by this ID
Expand All @@ -22,11 +23,18 @@ export const load: PageServerLoad = async function ({ setHeaders, params, locals
'cache-control': 'public, max-age=2592000, s-maxage=2592000'
});

// Scope the CSS in the returned HTML
const { document } = parseHTML(response.broadcast.content);
const styleTags = document.querySelectorAll('style');
styleTags.forEach((style) => {
style.innerHTML = `.newsletter-output { ${style.innerHTML} }`;
});

return {
subject: response.broadcast.subject,
published_at: response.broadcast.published_at,
id: response.broadcast.id,
html: response.broadcast.content,
html: document.toString(),
meta: {
title: `Syntax Newsletter - Issue ${response.broadcast.id}`
}
Expand Down
6 changes: 6 additions & 0 deletions src/routes/(site)/snackpack/[issue_id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@
:global(img) {
max-width: 100%;
}
:global(.ck-inner-section) {
border: 0 !important;
}
:global(table) {
border: 0 !important;
}
}
</style>
4 changes: 2 additions & 2 deletions src/routes/(site)/style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
░██████╗██╗░░░██╗███╗░░██╗
██╔════╝╚██╗░██╔╝████╗░██║
╚█████╗░░╚████╔╝░██╔██╗██║
Expand Down Expand Up @@ -53,7 +53,7 @@ html::view-transition-new() {
border-radius: var(--brad);
}

table {
table:not(.newsleter-output table) {
border: 1px solid black;
border-collapse: collapse;
position: relative;
Expand Down

0 comments on commit a963ee6

Please sign in to comment.