From 064d6ee06afa91e37f523bcadf2b07796d724b13 Mon Sep 17 00:00:00 2001 From: Peter Hozak Date: Sat, 2 Sep 2023 17:09:14 +0100 Subject: [PATCH] add embed parameter for inclusion on other websites #307 * strip header, footer, initial questions, and discord * allow override of search placeholder * fix "None of these" button when inside iframe --- README.md | 11 ++++++++++ app/components/layouts.tsx | 9 +++++++- app/components/search.tsx | 6 +++++- app/hooks/theme.tsx | 2 +- app/root.css | 41 +++++++++++++++++++----------------- app/root.tsx | 19 ++++++++++++----- app/routes/index.tsx | 33 +++++++++++++++++++---------- app/routes/questions/add.tsx | 12 +++++------ app/routes/random.tsx | 3 ++- public/embed-example.html | 22 +++++++++++++++++++ 10 files changed, 112 insertions(+), 46 deletions(-) create mode 100644 public/embed-example.html diff --git a/README.md b/README.md index 9ed197bc..8a4fd83a 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,15 @@ Stampy UI is an interface for [aisafety.info](https://aisafety.info), a question Contributions are welcome, the code is released under the MIT License. If you'd like to join the [dev team](https://coda.io/d/AI-Safety-Info_dfau7sl2hmG/Dev-team_sulmV#_luYjG), drop by [our Discord](https://discord.com/invite/7wjJbFJnSN) and post in #stampy-dev! +## Supported URL parameters + +- state - controls which questions are displayed as collapsed / open / related, e.g. `aisafety.info/?state=6568_897Ir6220r` +- embed - show site without header/footer for embedding on other sites, e.g. [embed-example.html](/public/embed-example.html) + - placeholder (string) - override `` of the search box + - theme (light|dark) - override CSS theme (if not provided, the embedded site will use `preferred-color-scheme` system setting) + - showInitial - also show initial questions, not just search bar +- more (disabled|infini|button|buttonInfini) - debug versions of load more / infinite scroll, e.g. `aisafety.info/?more=infini` + ## Stampy UI Development Setup 1. Requirements @@ -88,6 +97,8 @@ Production domains are deployed via GitHub Actions. ## Add a new domain +If the same CF worker should be reachable from another domain: + - log in to [Cloudflare Dashboard](https://dash.cloudflare.com/) owned by @plexish - use `Add a site` button on homepage, choose the Free plan - in the DNS section for this site > `Add record` for 2 new CNAME records: diff --git a/app/components/layouts.tsx b/app/components/layouts.tsx index 9f3a8ce5..be54099b 100644 --- a/app/components/layouts.tsx +++ b/app/components/layouts.tsx @@ -4,11 +4,14 @@ import logoFunSvg from '../assets/stampy-logo.svg' import logoMinSvg from '../assets/stampy-logo-min.svg' import {Share, Users, Code, Tag} from './icons-generated' import CopyLink from './copyLink' +import type {Context} from '~/root' const year = new Date().getFullYear() export const Header = ({reset = () => null}: {reset?: (e: MouseEvent) => void}) => { - const minLogo = useOutletContext() + const {minLogo, embed} = useOutletContext() + + if (embed) return null return (
@@ -55,6 +58,10 @@ export const Header = ({reset = () => null}: {reset?: (e: MouseEvent) => void}) } export const Footer = () => { + const {embed} = useOutletContext() + + if (embed) return null + return (