From 1aae6d6efe7f00dc9da533eef730909563852c38 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Thu, 11 Aug 2022 10:44:29 -0700 Subject: [PATCH] Support Manifold and Metaculus embeds --- web/components/editor/embed-modal.tsx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/web/components/editor/embed-modal.tsx b/web/components/editor/embed-modal.tsx index 26d53edd..19e5349d 100644 --- a/web/components/editor/embed-modal.tsx +++ b/web/components/editor/embed-modal.tsx @@ -19,12 +19,24 @@ function getTweetId(text: string) { return match ? match[1] : null } -// A valid YouTube URL looks like 'https://www.youtube.com/watch?v=ziq7FUKpCS8' +// Manifold URL: https://manifold.markets/Austin/will-manifold-ever-be-worth-1b +function getManifoldSlug(text: string) { + const match = text.match(/^https?:\/\/manifold\.markets\/([^\/]+)\/([^\/]+)/) + return match ? [match[1], match[2]] : null +} + +// Youtube URL: 'https://www.youtube.com/watch?v=ziq7FUKpCS8' function getYoutubeId(text: string) { const match = text.match(/^https?:\/\/www\.youtube\.com\/watch\?v=([^&]+)/) return match ? match[1] : null } +// Metaculus URL: 'https://www.metaculus.com/questions/5320/chinese-annexation-of-half-of-taiwan-by-2050/' +function getMetaculusId(text: string) { + const match = text.match(/^https?:\/\/www\.metaculus\.com\/questions\/(\d+)/) + return match ? match[1] : null +} + function isValidUrl(text: string) { // Conjured by Codex return /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/.test( @@ -39,10 +51,17 @@ function embedCode(text: string) { // Append a leading 't', to prevent tweetId from being interpreted as a number. // If it's a number, there may be numeric precision issues. return `` + } else if (getManifoldSlug(text)) { + const [username, slug] = getManifoldSlug(text) as [string, string] + return `` } else if (getYoutubeId(text)) { return `` + } else if (getMetaculusId(text)) { + return `` } else if (isValidUrl(text)) { return `` }