Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Blog update (#21289)

Francesco Sansalvadore1c0f677effbf
diff --git a/apps/www/_blog/2023-12-08-how-design-works-at-supabase.mdx b/apps/www/_blog/2023-12-08-how-design-works-at-supabase.mdx
index 0630cd97fab..63e112c7b9e 100644
--- a/apps/www/_blog/2023-12-08-how-design-works-at-supabase.mdx
+++ b/apps/www/_blog/2023-12-08-how-design-works-at-supabase.mdx
@@ -3,7 +3,6 @@ title: 'How design works at Supabase'
description: "The transformative journey of Supabase's Design team and its unique culture to enhance the output and quality of the entire company."
launchweek: X
categories:
- - product
- company
tags:
- launch-week
diff --git a/apps/www/components/Blog/BlogFilters.tsx b/apps/www/components/Blog/BlogFilters.tsx
index c1aa460a055..823e78130d5 100644
--- a/apps/www/components/Blog/BlogFilters.tsx
+++ b/apps/www/components/Blog/BlogFilters.tsx
@@ -1,6 +1,12 @@
-import { startCase } from 'lodash'
+import { useEffect, useState } from 'react'
import { useRouter } from 'next/router'
-import { useCallback, useEffect, useState } from 'react'
+import { useSearchParams } from 'next/navigation'
+import { AnimatePresence, motion } from 'framer-motion'
+import { startCase } from 'lodash'
+import { useKey } from 'react-use'
+import { LOCAL_STORAGE_KEYS, useBreakpoint } from 'common'
+import PostTypes from '~/types/post'
+import type { BlogView } from '~/pages/blog'
import {
Button,
@@ -8,76 +14,151 @@ import {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
+ IconAlignJustify,
IconChevronDown,
+ IconGrid,
IconSearch,
IconX,
Input,
+ cn,
} from 'ui'
-import { useParams } from '~/hooks/useParams'
-
-import { useBreakpoint } from 'common'
-import { AnimatePresence, motion } from 'framer-motion'
-import PostTypes from '~/types/post'
interface Props {
- posts: PostTypes[]
+ allPosts: PostTypes[]
setPosts: (posts: any) => void
- setCategory: (category: string) => void
- allCategories: string[]
- handlePosts: VoidFunction
+ view: BlogView
+ setView: (view: any) => void
}
-const MotionButton = motion(Button)
+/**
+ * ✅ search via text input
+ * ✅ update searchTerm when deleting text input
+ * ✅ search via q param
+ * ✅ search via category if no q param
+ * ✅ search via category and reset q param if present
+ */
-const BlogFilters = ({ posts, setPosts, setCategory, allCategories, handlePosts }: Props) => {
- const activeCategory = useParams()?.category
- const [searchKey, setSearchKey] = useState<string>('')
- const isMobile = useBreakpoint(1023)
- const is2XL = useBreakpoint(1535)
+function BlogFilters({ allPosts, setPosts, view, setView }: Props) {
+ const { BLOG_VIEW } = LOCAL_STORAGE_KEYS
+ const isList = view === 'list'
+ const [category, setCategory] = useState<string>('all')
+ const [searchTerm, setSearchTerm] = useState<string>('')
const [showSearchInput, setShowSearchInput] = useState<boolean>(false)
+
const router = useRouter()
- const [isMounted, setIsMounted] = useState(false)
+ const searchParams = useSearchParams()
+ const q = searchParams.get('q')
+ const activeCategory = searchParams.get('category')
+ const isMobile = useBreakpoint(1023)
+ const is2XL = useBreakpoint(1535)
- useEffect(() => {
- setShowSearchInput(!isMobile)
- }, [isMobile])
+ // Use hard-coded categories here as they:
+ // - serve as a reference
+ // - are easier to reorder
+ const allCategories = [
+ 'all',
+ 'product',
+ 'company',
+ 'postgres',
+ 'developers',
+ 'engineering',
+ 'launch-week',
+ ]
useEffect(() => {
- if (!!searchKey) {
- setPosts(handleSearchByText)
- } else {
+ if (!q) {
handlePosts()
}
- }, [searchKey])
+ }, [category])
+
+ useEffect(() => {
+ if (q) {
+ handleSearchByText(q)
+ }
+ }, [q])
+
+ const handleReplaceRouter = () => {
+ if (!searchTerm && category !== 'all') {
+ router.query.category = category
+ router.replace(router, undefined, { shallow: true, scroll: false })
+ }
+ }
+
+ const handlePosts = () => {
+ // construct an array of blog posts
+ // not inluding the first blog post
+ const shiftedBlogs = [...allPosts]
+ shiftedBlogs.shift()
+
+ handleReplaceRouter()
+
+ setPosts(
+ category === 'all'
+ ? shiftedBlogs
+ : allPosts.filter((post: any) => {
+ const found = post.categories?.includes(category)
+ return found
+ })
+ )
+ }
+
+ useKey('Escape', () => handleSearchByText(''))
useEffect(() => {
+ setShowSearchInput(!isMobile)
+ }, [isMobile])
+
+ useEffect(() => {
+ if (router.isReady && q) {
+ setSearchTerm(q)
+ }
if (router.isReady && activeCategory && activeCategory !== 'all') {
setCategory(activeCategory)
}
- }, [activeCategory, router.isReady])
+ }, [activeCategory, router.isReady, q])
- const handleSearchByText = useCallback(() => {
- if (!searchKey) return
- const matches = posts.filter((post: any) => {
+ const handleSearchByText = (text: string) => {
+ setSearchTerm(text)
+ searchParams.has('q') && router.replace('/blog', undefined, { shallow: true, scroll: false })
+ router.replace(`/blog?q=${text}`, undefined, { shallow: true, scroll: false })
+ if (text.length < 1) router.replace('/blog', undefined, { shallow: true, scroll: false })
+
+ const matches = allPosts.filter((post: any) => {
const found =
- post.tags?.join(' ').replaceAll('-', ' ').includes(searchKey.toLowerCase()) ||
- post.title?.toLowerCase().includes(searchKey.toLowerCase()) ||
- post.author?.includes(searchKey.toLowerCase())
+ post.tags?.join(' ').replaceAll('-', ' ').includes(text.toLowerCase()) ||
+ post.title?.toLowerCase().includes(text.toLowerCase()) ||
+ post.author?.includes(text.toLowerCase())
return found
})
- return matches
- }, [searchKey])
+
+ setPosts(matches)
+ }
+
+ const handleSetCategory = (category: string) => {
+ searchTerm && handlePosts()
+ searchTerm && setSearchTerm('')
+ setCategory(category)
+ category === 'all'
+ ? router.replace('/blog', undefined, { shallow: true, scroll: false })
+ : router.replace(`/blog?category=${category}`, undefined, {
+ shallow: true,
+ scroll: false,
+ })
+ }
const handleSearchChange = (event: any) => {
activeCategory && setCategory('all')
- setSearchKey(event.target.value)
+ handleSearchByText(event.target.value)
}
- useEffect(() => {
- setIsMounted(true)
- }, [])
+ const handleViewSelection = () => {
+ setView((prevView: 'list' | 'grid') => {
+ const newValue = prevView === 'list' ? 'grid' : 'list'
+ localStorage.setItem(BLOG_VIEW, newValue)
- if (!isMounted) return null
+ return newValue
+ })
+ }
return (
<div className="flex flex-row items-center justify-between gap-2">
@@ -90,7 +171,7 @@ const BlogFilters = ({ posts, setPosts, setCategory, allCategories, handlePosts
className="flex lg:hidden"
>
<DropdownMenu>
- <DropdownMenuTrigger>
+ <DropdownMenuTrigger asChild>
<Button
type="outline"
iconRight={<IconChevronDown />}
@@ -103,12 +184,12 @@ const BlogFilters = ({ posts, setPosts, setCategory, allCategories, handlePosts
{allCategories.map((category: string) => (
<DropdownMenuItem
key="custom-expiry"
- onClick={() => setCategory(category)}
- className={[
+ onClick={() => handleSetCategory(category)}
+ className={cn(
(category === 'all' && !activeCategory) || category === activeCategory
? 'text-brand-600'
- : '',
- ].join(' ')}
+ : ''
+ )}
>
{category === 'all' ? 'All Posts' : startCase(category.replaceAll('-', ' '))}
</DropdownMenuItem>
@@ -122,13 +203,13 @@ const BlogFilters = ({ posts, setPosts, setCategory, allCategories, handlePosts
<Button
key={category}
type={
- category === 'all' && !searchKey && !activeCategory
+ category === 'all' && !searchTerm && !activeCategory
? 'alternative'
: category === activeCategory
? 'alternative'
: 'outline'
}
- onClick={() => setCategory(category)}
+ onClick={() => handleSetCategory(category)}
size={is2XL ? 'tiny' : 'small'}
>
{category === 'all' ? 'All' : startCase(category.replaceAll('-', ' '))}
@@ -137,16 +218,21 @@ const BlogFilters = ({ posts, setPosts, setCategory, allCategories, handlePosts
</div>
{!showSearchInput && (
- <MotionButton
+ <motion.div
+ className="flex-1 flex justify-end"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0, transition: { duration: 0.05 } }}
- size="large"
- type="default"
- onClick={() => setShowSearchInput(true)}
>
- <IconSearch size="tiny" />
- </MotionButton>
+ <Button
+ className="px-2"
+ size="large"
+ type="default"
+ onClick={() => setShowSearchInput(true)}
+ >
+ <IconSearch size="tiny" />
+ </Button>
+ </motion.div>
)}
{showSearchInput && (
@@ -154,7 +240,7 @@ const BlogFilters = ({ posts, setPosts, setCategory, allCategories, handlePosts
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0, transition: { duration: 0.05 } }}
- className="w-full lg:max-w-[240px] xl:max-w-[280px]"
+ className="w-full h-auto flex justify-end gap-2 items-stretch lg:max-w-[240px] xl:max-w-[280px]"
>
<Input
icon={<IconSearch size="tiny" />}
@@ -163,7 +249,7 @@ const BlogFilters = ({ posts, setPosts, setCategory, allCategories, handlePosts
autoComplete="off"
type="search"
placeholder="Search blog"
- value={searchKey}
+ value={searchTerm}
onChange={handleSearchChange}
className="w-full"
actions={
@@ -171,10 +257,10 @@ const BlogFilters = ({ posts, setPosts, setCategory, allCategories, handlePosts
<Button
type="link"
onClick={() => {
- setSearchKey('')
+ setSearchTerm('')
setShowSearchInput(false)
}}
- className="text-foreground-light hover:text-foreground"
+ className="text-foreground-light hover:text-foreground hover:bg-selection"
>
<IconX size="tiny" />
</Button>
@@ -184,6 +270,14 @@ const BlogFilters = ({ posts, setPosts, setCategory, allCategories, handlePosts
</motion.div>
)}
</AnimatePresence>
+ <Button
+ type="default"
+ title={isList ? 'Grid View' : 'List View'}
+ onClick={handleViewSelection}
+ className="h-full p-1.5"
+ >
+ {isList ? <IconGrid /> : <IconAlignJustify />}
+ </Button>
</div>
)
}
diff --git a/apps/www/components/Blog/BlogGridItem.tsx b/apps/www/components/Blog/BlogGridItem.tsx
new file mode 100644
index 00000000000..ad5159b1a98
--- /dev/null
+++ b/apps/www/components/Blog/BlogGridItem.tsx
@@ -0,0 +1,84 @@
+import authors from 'lib/authors.json'
+import Image from 'next/image'
+import Link from 'next/link'
+import React from 'react'
+import Author from '~/types/author'
+import PostTypes from '~/types/post'
+import dayjs from 'dayjs'
+
+interface Props {
+ post: PostTypes
+}
+
+const BlogGridItem = ({ post }: Props) => {
+ const authorArray: string[] | undefined = post.author ? post.author.split(',') : []
+ const author = []
+
+ if (authorArray) {
+ for (let i = 0; i < authorArray.length; i++) {
+ author.push(
+ authors.find((authors: Author) => {
+ return authors.author_id === authorArray[i]
+ })
+ )
+ }
+ }
+
+ return (
+ <Link
+ href={post.path}
+ className="group inline-block min-w-full p-2 sm:p-4 h-full border border-transparent hover:border-overlay transition-all hover:bg-overlay rounded-xl"
+ >
+ <div className="flex flex-col space-y-2">
+ <div className="flex flex-col space-y-1">
+ <div className="border-default relative mb-3 w-full aspect-[2/1] lg:aspect-[5/3] overflow-hidden rounded-lg border shadow-sm">
+ <Image
+ fill
+ src={
+ !post.thumb
+ ? `/images/blog/blog-placeholder.png`
+ : post.type === 'casestudy'
+ ? post.thumb
+ : `/images/blog/${post.thumb}`
+ }
+ className="scale-100 object-cover overflow-hidden"
+ alt={`${post.title} thumbnail`}
+ />
+ </div>
+
+ {post.date && (
+ <div className="text-foreground-lighter flex items-center space-x-1.5 text-sm">
+ <p>{dayjs(post.date).format('D MMM YYYY')}</p>
+ {post.readingTime && (
+ <>
+ <p>•</p>
+ <p>{post.readingTime}</p>
+ </>
+ )}
+ </div>
+ )}
+ <h3 className="text-foreground max-w-sm text-xl">{post.title}</h3>
+ <p className="text-foreground-light max-w-sm text-base !mb-0">{post.description}</p>
+ </div>
+ {/* <div className="flex items-center -space-x-2">
+ {author.map((author: any, i: number) => {
+ return (
+ <div className="relative ring-background w-6 h-6 rounded-full ring-2" key={i}>
+ {author.author_image_url && (
+ <Image
+ src={author.author_image_url}
+ className="rounded-full object-cover border border-default w-full h-full"
+ alt={`${author.author} avatar`}
+ fill
+ />
+ )}
+ </div>
+ )
+ })}
+ </div> */}
+ </div>
+ </Link>
+ )
+}
+
+export default BlogGridItem
diff --git a/apps/www/components/Blog/BlogListItem.tsx b/apps/www/components/Blog/BlogListItem.tsx
index 096476bab12..6b6d8862efb 100644
--- a/apps/www/components/Blog/BlogListItem.tsx
+++ b/apps/www/components/Blog/BlogListItem.tsx
@@ -4,6 +4,7 @@ import Link from 'next/link'
import React from 'react'
import Author from '~/types/author'
import PostTypes from '~/types/post'
+import dayjs from 'dayjs'
interface Props {
post: PostTypes
@@ -24,58 +25,49 @@ const BlogListItem = ({ post }: Props) => {
}
return (
- <div>
- <Link href={post.path} className="group inline-block min-w-full">
- <div className="flex flex-col space-y-6">
- <div className="flex flex-col space-y-3">
- <div className="border-default relative mb-4 w-full aspect-[2/1] lg:aspect-[3/2] overflow-hidden rounded-lg border shadow-sm">
- <Image
- fill
- src={
- !post.thumb
- ? `/images/blog/blog-placeholder.png`
- : post.type === 'casestudy'
- ? post.thumb
- : `/images/blog/${post.thumb}`
- }
- className="scale-100 object-cover overflow-hidden transform transition-transform group-hover:scale-105"
- alt={`${post.title} thumbnail`}
- />
- </div>
-
- <h3 className="text-foreground max-w-sm text-xl">{post.title}</h3>
- <p className="text-foreground-light max-w-sm text-base">{post.description}</p>
- {post.date && (
- <div className="text-foreground-light flex items-center space-x-1.5 text-sm">
- <p>{post.date}</p>
- {post.readingTime && (
- <>
- <p>•</p>
- <p>{post.readingTime}</p>
- </>
+ <Link
+ href={post.path}
+ className="group flex flex-col lg:grid lg:grid-cols-10 xl:grid-cols-12 w-full py-2 sm:py-4 h-full border-b"
+ >
+ <div className="flex w-full lg:col-span-8 xl:col-span-8">
+ <h3 className="text-foreground text-lg group-hover:underline">{post.title}</h3>
+ </div>
+ <div className="lg:col-span-2 xl:col-span-4 flex justify-start items-center lg:grid grid-cols-2 xl:grid-cols-3 gap-2 text-sm">
+ <div className="hidden lg:flex items-center -space-x-2">
+ {author.map((author: any, i: number) => {
+ return (
+ <div className="relative ring-background w-6 h-6 rounded-full ring-2" key={i}>
+ {author.author_image_url && (
+ <Image
+ src={author.author_image_url}
+ className="rounded-full object-cover border border-default w-full h-full"
+ alt={`${author.author} avatar`}
+ fill
+ />
)}
</div>
+ )
+ })}
+ </div>
+ {post.categories && (
+ <div className="hidden xl:flex text-foreground-lighter">
+ {post.categories.map(
+ (category, i) =>
+ i === 0 && (
+ <p className="border border-muted py-1 px-2 rounded text-center w-auto capitalize">
+ {category}
+ </p>
+ )
)}
</div>
- <div className="flex items-center -space-x-2">
- {author.map((author: any, i: number) => {
- return (
- <div className="relative ring-background w-10 h-10 rounded-full ring-2" key={i}>
- {author.author_image_url && (
- <Image
- src={author.author_image_url}
- className="rounded-full object-cover border border-default w-full h-full"
- alt={`${author.author} avatar`}
- fill
- />
- )}
- </div>
- )
- })}
- </div>
- </div>
- </Link>
- </div>
+ )}
+ {post.date && (
+ <p className="text-foreground-lighter flex-1 lg:text-right w-full">
+ {dayjs(post.date).format('D MMM YYYY')}
+ </p>
+ )}
+ </div>
+ </Link>
)
}
diff --git a/apps/www/components/Blog/FeaturedThumb.tsx b/apps/www/components/Blog/FeaturedThumb.tsx
new file mode 100644
index 00000000000..320025e2bf4
--- /dev/null
+++ b/apps/www/components/Blog/FeaturedThumb.tsx
@@ -0,0 +1,75 @@
+import Image from 'next/legacy/image'
+import Link from 'next/link'
+import authors from 'lib/authors.json'
+import PostTypes from '../../types/post'
+
+function FeaturedThumb(blog: PostTypes) {
+ // @ts-ignore
+ const authorArray = blog.author.split(',')
+
+ const author = []
+ for (let i = 0; i < authorArray.length; i++) {
+ // @ts-ignore
+ author.push(
+ authors.find((authors: any) => {
+ // @ts-ignore
+ return authors.author_id === authorArray[i]
+ })
+ )
+ }
+
+ return (
+ <div key={blog.slug} className="w-full">
+ <Link
+ href={`${blog.path}`}
+ className="grid gap-4 lg:grid-cols-7 lg:gap-8 xl:gap-12 hover:bg-overlay border border-transparent hover:border-overlay p-2 sm:p-4 rounded-xl"
+ >
+ <div className="relative w-full aspect-[2/1] lg:col-span-3 lg:aspect-[3/2] overflow-auto rounded-lg border">
+ <Image
+ src={`/images/blog/` + (blog.thumb ? blog.thumb : blog.image)}
+ layout="fill"
+ className="object-cover"
+ alt="blog thumbnail"
+ />
+ </div>
+ <div className="flex flex-col space-y-2 lg:col-span-4 xl:justify-center max-w-xl">
+ <div className="text-lighter flex space-x-2 text-sm">
+ <span>{blog.date}</span>
+ <span>•</span>
+ <span>{blog.readingTime}</span>
+ </div>
+
+ <div>
+ <h2 className="h2 lg:!text-2xl xl:!text-3xl !mb-2">{blog.title}</h2>
+ <p className="p xl:text-lg">{blog.description}</p>
+ </div>
+
+ <div className="flex flex-col w-max gap-2">
+ {author.map((author: any, i: number) => {
+ return (
+ <div className="flex items-center space-x-2" key={i}>
+ {author.author_image_url && (
+ <div className="relative h-6 w-6 overflow-auto">
+ <Image
+ src={author.author_image_url}
+ alt={`${author.author} avatar`}
+ className="rounded-full object-cover"
+ layout="fill"
+ />
+ </div>
+ )}
+ <div className="flex flex-col">
+ <span className="text-foreground m-0 text-sm">{author.author}</span>
+ {/* <span className="text-light m-0 text-xs">{author.position}</span> */}
+ </div>
+ </div>
+ )
+ })}
+ </div>
+ </div>
+ </Link>
+ </div>
+ )
+}
+
+export default FeaturedThumb
diff --git a/apps/www/components/CaseStudies/index.tsx b/apps/www/components/CaseStudies/index.tsx
index 613e6665638..05f0f676296 100644
--- a/apps/www/components/CaseStudies/index.tsx
+++ b/apps/www/components/CaseStudies/index.tsx
@@ -1,7 +1,7 @@
import SectionHeader from 'components/UI/SectionHeader'
import CaseStudiesData from 'data/CaseStudies.json'
import { useRouter } from 'next/router'
-import BlogListItem from '../Blog/BlogListItem'
+import BlogGridItem from '../Blog/BlogGridItem'
import SectionContainer from '../Layouts/SectionContainer'
const CaseStudies = () => {
@@ -22,7 +22,7 @@ const CaseStudies = () => {
</div>
<div className="mx-auto mt-5 grid max-w-lg gap-8 lg:max-w-none lg:grid-cols-3 lg:gap-12">
{CaseStudiesData.map((caseStudy, idx: number) => (
- <BlogListItem
+ <BlogGridItem
key={idx}
post={{
type: 'casestudy',
diff --git a/apps/www/components/Products/AuthVisual.tsx b/apps/www/components/Products/AuthVisual.tsx
index 6eca4f929a3..8942fd0ead3 100644
--- a/apps/www/components/Products/AuthVisual.tsx
+++ b/apps/www/components/Products/AuthVisual.tsx
@@ -1,4 +1,3 @@
-import Image from 'next/image'
import React from 'react'
const AuthVisual = () => {
@@ -48,7 +47,7 @@ const AuthVisual = () => {
fill="hsl(var(--foreground-muted))"
/>
</g>
- <a href="mailto:[email protected]">
+ <g>
<rect
fill="black"
fillOpacity="0"
@@ -57,7 +56,7 @@ const AuthVisual = () => {
width="167.896"
height="18.2"
/>
- </a>
+ </g>
</g>
<g className="opacity-0 group-hover:opacity-100 transition-opacity">
<rect
@@ -94,7 +93,7 @@ const AuthVisual = () => {
fill="hsl(var(--foreground-muted))"
/>
</g>
- <a href="mailto:[email protected]">
+ <g>
<rect
fill="black"
fillOpacity="0"
@@ -103,7 +102,7 @@ const AuthVisual = () => {
width="167.896"
height="18.2"
/>
- </a>
+ </g>
<path
d="M191.498 315.516H190.39L193.594 306.788H194.685L197.89 315.516H196.782L194.174 308.169H194.106L191.498 315.516ZM191.907 312.107H196.373V313.044H191.907V312.107ZM201.772 315.652C201.158 315.652 200.63 315.507 200.187 315.217C199.744 314.928 199.403 314.528 199.164 314.02C198.925 313.511 198.806 312.93 198.806 312.277C198.806 311.612 198.928 311.026 199.172 310.517C199.42 310.006 199.763 309.607 200.204 309.32C200.647 309.03 201.164 308.885 201.755 308.885C202.215 308.885 202.63 308.97 202.999 309.141C203.369 309.311 203.671 309.55 203.907 309.857C204.143 310.163 204.289 310.521 204.346 310.93H203.34C203.263 310.632 203.093 310.368 202.829 310.138C202.567 309.905 202.215 309.788 201.772 309.788C201.38 309.788 201.036 309.891 200.741 310.095C200.448 310.297 200.219 310.582 200.055 310.952C199.893 311.318 199.812 311.749 199.812 312.243C199.812 312.749 199.891 313.189 200.05 313.564C200.212 313.939 200.44 314.23 200.732 314.438C201.028 314.645 201.374 314.749 201.772 314.749C202.033 314.749 202.271 314.703 202.484 314.612C202.697 314.521 202.877 314.391 203.025 314.22C203.172 314.05 203.278 313.845 203.34 313.607H204.346C204.289 313.993 204.148 314.341 203.924 314.651C203.702 314.957 203.408 315.202 203.042 315.384C202.678 315.562 202.255 315.652 201.772 315.652ZM208.475 315.652C207.861 315.652 207.333 315.507 206.89 315.217C206.447 314.928 206.106 314.528 205.867 314.02C205.628 313.511 205.509 312.93 205.509 312.277C205.509 311.612 205.631 311.026 205.876 310.517C206.123 310.006 206.467 309.607 206.907 309.32C207.35 309.03 207.867 308.885 208.458 308.885C208.918 308.885 209.333 308.97 209.702 309.141C210.072 309.311 210.374 309.55 210.61 309.857C210.846 310.163 210.992 310.521 211.049 310.93H210.043C209.967 310.632 209.796 310.368 209.532 310.138C209.271 309.905 208.918 309.788 208.475 309.788C208.083 309.788 207.739 309.891 207.444 310.095C207.151 310.297 206.922 310.582 206.758 310.952C206.596 311.318 206.515 311.749 206.515 312.243C206.515 312.749 206.594 313.189 206.753 313.564C206.915 313.939 207.143 314.23 207.435 314.438C207.731 314.645 208.077 314.749 208.475 314.749C208.736 314.749 208.974 314.703 209.187 314.612C209.4 314.521 209.58 314.391 209.728 314.22C209.876 314.05 209.981 313.845 210.043 313.607H211.049C210.992 313.993 210.851 314.341 210.627 314.651C210.405 314.957 210.111 315.202 209.745 315.384C209.381 315.562 208.958 315.652 208.475 315.652ZM215.263 315.652C214.633 315.652 214.089 315.513 213.631 315.234C213.177 314.953 212.826 314.561 212.579 314.058C212.334 313.553 212.212 312.964 212.212 312.294C212.212 311.624 212.334 311.033 212.579 310.521C212.826 310.007 213.17 309.607 213.61 309.32C214.053 309.03 214.57 308.885 215.161 308.885C215.502 308.885 215.839 308.942 216.171 309.055C216.503 309.169 216.806 309.354 217.079 309.609C217.351 309.862 217.569 310.197 217.731 310.615C217.893 311.033 217.974 311.547 217.974 312.158V312.584H212.928V311.714H216.951C216.951 311.345 216.877 311.016 216.729 310.726C216.584 310.436 216.377 310.207 216.107 310.04C215.84 309.872 215.525 309.788 215.161 309.788C214.761 309.788 214.414 309.888 214.121 310.087C213.832 310.283 213.609 310.538 213.452 310.854C213.296 311.169 213.218 311.507 213.218 311.868V312.447C213.218 312.942 213.303 313.361 213.474 313.705C213.647 314.045 213.887 314.305 214.194 314.484C214.501 314.661 214.857 314.749 215.263 314.749C215.528 314.749 215.766 314.712 215.979 314.638C216.195 314.561 216.381 314.447 216.538 314.297C216.694 314.143 216.815 313.953 216.9 313.726L217.871 313.999C217.769 314.328 217.597 314.618 217.356 314.868C217.114 315.115 216.816 315.308 216.461 315.447C216.106 315.584 215.707 315.652 215.263 315.652ZM224.14 310.436L223.236 310.692C223.18 310.541 223.096 310.395 222.985 310.253C222.877 310.108 222.729 309.989 222.542 309.895C222.354 309.801 222.114 309.754 221.822 309.754C221.421 309.754 221.087 309.847 220.82 310.031C220.556 310.213 220.424 310.445 220.424 310.726C220.424 310.976 220.515 311.173 220.697 311.318C220.878 311.463 221.163 311.584 221.549 311.68L222.521 311.919C223.106 312.061 223.542 312.278 223.829 312.571C224.116 312.861 224.259 313.234 224.259 313.692C224.259 314.067 224.151 314.402 223.935 314.697C223.722 314.993 223.424 315.226 223.04 315.396C222.657 315.567 222.211 315.652 221.702 315.652C221.035 315.652 220.482 315.507 220.045 315.217C219.607 314.928 219.33 314.504 219.214 313.947L220.168 313.709C220.259 314.061 220.431 314.325 220.684 314.501C220.94 314.678 221.273 314.766 221.685 314.766C222.154 314.766 222.526 314.666 222.802 314.467C223.08 314.266 223.219 314.024 223.219 313.743C223.219 313.516 223.14 313.325 222.981 313.172C222.822 313.016 222.577 312.899 222.248 312.822L221.157 312.567C220.557 312.425 220.117 312.205 219.836 311.906C219.557 311.605 219.418 311.229 219.418 310.777C219.418 310.408 219.522 310.081 219.729 309.797C219.94 309.513 220.225 309.29 220.586 309.128C220.949 308.966 221.361 308.885 221.822 308.885C222.469 308.885 222.978 309.027 223.347 309.311C223.719 309.595 223.984 309.97 224.14 310.436ZM230.409 310.436L229.506 310.692C229.449 310.541 229.365 310.395 229.255 310.253C229.147 310.108 228.999 309.989 228.811 309.895C228.624 309.801 228.384 309.754 228.091 309.754C227.691 309.754 227.357 309.847 227.09 310.031C226.826 310.213 226.693 310.445 226.693 310.726C226.693 310.976 226.784 311.173 226.966 311.318C227.148 311.463 227.432 311.584 227.818 311.68L228.79 311.919C229.375 312.061 229.811 312.278 230.098 312.571C230.385 312.861 230.529 313.234 230.529 313.692C230.529 314.067 230.421 314.402 230.205 314.697C229.992 314.993 229.693 315.226 229.31 315.396C228.926 315.567 228.48 315.652 227.972 315.652C227.304 315.652 226.752 315.507 226.314 315.217C225.877 314.928 225.6 314.504 225.483 313.947L226.438 313.709C226.529 314.061 226.701 314.325 226.953 314.501C227.209 314.678 227.543 314.766 227.955 314.766C228.424 314.766 228.796 314.666 229.071 314.467C229.35 314.266 229.489 314.024 229.489 313.743C229.489 313.516 229.409 313.325 229.25 313.172C229.091 313.016 228.847 312.899 228.517 312.822L227.426 312.567C226.827 312.425 226.387 312.205 226.105 311.906C225.827 311.605 225.688 311.229 225.688 310.777C225.688 310.408 225.791 310.081 225.999 309.797C226.209 309.513 226.495 309.29 226.855 309.128C227.219 308.966 227.631 308.885 228.091 308.885C228.739 308.885 229.247 309.027 229.617 309.311C229.989 309.595 230.253 309.97 230.409 310.436ZM235.418 315.516V308.97H236.389V309.959H236.457C236.577 309.635 236.793 309.372 237.105 309.17C237.418 308.969 237.77 308.868 238.162 308.868C238.236 308.868 238.328 308.869 238.439 308.872C238.55 308.875 238.633 308.879 238.69 308.885V309.908C238.656 309.899 238.578 309.886 238.456 309.869C238.337 309.849 238.21 309.839 238.077 309.839C237.758 309.839 237.474 309.906 237.224 310.04C236.977 310.17 236.781 310.352 236.636 310.585C236.494 310.815 236.423 311.078 236.423 311.374V315.516H235.418ZM242.427 315.652C241.797 315.652 241.253 315.513 240.795 315.234C240.341 314.953 239.99 314.561 239.743 314.058C239.498 313.553 239.376 312.964 239.376 312.294C239.376 311.624 239.498 311.033 239.743 310.521C239.99 310.007 240.334 309.607 240.774 309.32C241.217 309.03 241.734 308.885 242.325 308.885C242.666 308.885 243.003 308.942 243.335 309.055C243.668 309.169 243.97 309.354 244.243 309.609C244.516 309.862 244.733 310.197 244.895 310.615C245.057 311.033 245.138 311.547 245.138 312.158V312.584H240.092V311.714H244.115C244.115 311.345 244.041 311.016 243.893 310.726C243.748 310.436 243.541 310.207 243.271 310.04C243.004 309.872 242.689 309.788 242.325 309.788C241.925 309.788 241.578 309.888 241.285 310.087C240.996 310.283 240.773 310.538 240.616 310.854C240.46 311.169 240.382 311.507 240.382 311.868V312.447C240.382 312.942 240.467 313.361 240.638 313.705C240.811 314.045 241.051 314.305 241.358 314.484C241.665 314.661 242.021 314.749 242.427 314.749C242.692 314.749 242.93 314.712 243.143 314.638C243.359 314.561 243.545 314.447 243.702 314.297C243.858 314.143 243.979 313.953 244.064 313.726L245.035 313.999C244.933 314.328 244.761 314.618 244.52 314.868C244.278 315.115 243.98 315.308 243.625 315.447C243.27 315.584 242.871 315.652 242.427 315.652ZM251.133 317.97V314.51H251.048C250.974 314.629 250.869 314.78 250.733 314.962C250.597 315.141 250.402 315.301 250.149 315.443C249.896 315.582 249.56 315.652 249.139 315.652C248.594 315.652 248.112 315.514 247.695 315.239C247.277 314.96 246.95 314.568 246.714 314.062C246.479 313.554 246.361 312.953 246.361 312.26C246.361 311.572 246.479 310.976 246.714 310.47C246.95 309.964 247.278 309.574 247.699 309.298C248.119 309.023 248.605 308.885 249.156 308.885C249.582 308.885 249.919 308.956 250.166 309.098C250.416 309.237 250.606 309.396 250.737 309.575C250.871 309.751 250.974 309.896 251.048 310.01H251.168V308.97H252.139V317.97H251.133ZM249.275 314.749C249.679 314.749 250.02 314.643 250.298 314.433C250.577 314.22 250.788 313.926 250.933 313.551C251.078 313.173 251.15 312.737 251.15 312.243C251.15 311.754 251.079 311.327 250.937 310.96C250.795 310.591 250.585 310.304 250.307 310.099C250.028 309.892 249.685 309.788 249.275 309.788C248.849 309.788 248.494 309.898 248.21 310.116C247.929 310.332 247.717 310.626 247.575 310.999C247.436 311.368 247.366 311.783 247.366 312.243C247.366 312.709 247.437 313.132 247.579 313.513C247.724 313.891 247.937 314.192 248.219 314.416C248.503 314.638 248.855 314.749 249.275 314.749ZM258.105 312.839V308.97H259.111V315.516H258.105V314.408H258.037C257.883 314.74 257.645 315.023 257.321 315.256C256.997 315.486 256.588 315.601 256.094 315.601C255.685 315.601 255.321 315.511 255.003 315.332C254.685 315.151 254.435 314.878 254.253 314.514C254.071 314.148 253.98 313.686 253.98 313.129V308.97H254.986V313.061C254.986 313.538 255.119 313.919 255.386 314.203C255.656 314.487 256 314.629 256.418 314.629C256.668 314.629 256.922 314.565 257.18 314.438C257.442 314.31 257.66 314.114 257.837 313.849C258.016 313.585 258.105 313.249 258.105 312.839ZM260.953 315.516V308.97H261.958V315.516H260.953ZM261.464 307.879C261.268 307.879 261.099 307.812 260.957 307.679C260.818 307.545 260.748 307.385 260.748 307.197C260.748 307.01 260.818 306.849 260.957 306.716C261.099 306.582 261.268 306.516 261.464 306.516C261.66 306.516 261.828 306.582 261.967 306.716C262.109 306.849 262.18 307.01 262.18 307.197C262.18 307.385 262.109 307.545 261.967 307.679C261.828 307.812 261.66 307.879 261.464 307.879ZM263.8 315.516V308.97H264.772V309.959H264.84C264.959 309.635 265.175 309.372 265.488 309.17C265.8 308.969 266.153 308.868 266.545 308.868C266.619 308.868 266.711 308.869 266.822 308.872C266.932 308.875 267.016 308.879 267.073 308.885V309.908C267.039 309.899 266.961 309.886 266.839 309.869C266.719 309.849 266.593 309.839 266.459 309.839C266.141 309.839 265.857 309.906 265.607 310.04C265.36 310.17 265.164 310.352 265.019 310.585C264.877 310.815 264.806 311.078 264.806 311.374V315.516H263.8ZM270.81 315.652C270.18 315.652 269.636 315.513 269.178 315.234C268.724 314.953 268.373 314.561 268.126 314.058C267.881 313.553 267.759 312.964 267.759 312.294C267.759 311.624 267.881 311.033 268.126 310.521C268.373 310.007 268.717 309.607 269.157 309.32C269.6 309.03 270.117 308.885 270.708 308.885C271.049 308.885 271.386 308.942 271.718 309.055C272.05 309.169 272.353 309.354 272.626 309.609C272.898 309.862 273.116 310.197 273.278 310.615C273.44 311.033 273.521 311.547 273.521 312.158V312.584H268.475V311.714H272.498C272.498 311.345 272.424 311.016 272.276 310.726C272.131 310.436 271.924 310.207 271.654 310.04C271.387 309.872 271.072 309.788 270.708 309.788C270.307 309.788 269.961 309.888 269.668 310.087C269.378 310.283 269.155 310.538 268.999 310.854C268.843 311.169 268.765 311.507 268.765 311.868V312.447C268.765 312.942 268.85 313.361 269.021 313.705C269.194 314.045 269.434 314.305 269.741 314.484C270.047 314.661 270.404 314.749 270.81 314.749C271.074 314.749 271.313 314.712 271.526 314.638C271.742 314.561 271.928 314.447 272.084 314.297C272.241 314.143 272.361 313.953 272.447 313.726L273.418 313.999C273.316 314.328 273.144 314.618 272.903 314.868C272.661 315.115 272.363 315.308 272.008 315.447C271.653 315.584 271.253 315.652 270.81 315.652ZM277.522 315.652C276.976 315.652 276.495 315.514 276.077 315.239C275.66 314.96 275.333 314.568 275.097 314.062C274.861 313.554 274.744 312.953 274.744 312.26C274.744 311.572 274.861 310.976 275.097 310.47C275.333 309.964 275.661 309.574 276.082 309.298C276.502 309.023 276.988 308.885 277.539 308.885C277.965 308.885 278.302 308.956 278.549 309.098C278.799 309.237 278.989 309.396 279.12 309.575C279.253 309.751 279.357 309.896 279.431 310.01H279.516V306.788H280.522V315.516H279.55V314.51H279.431C279.357 314.629 279.252 314.78 279.116 314.962C278.979 315.141 278.785 315.301 278.532 315.443C278.279 315.582 277.942 315.652 277.522 315.652ZM277.658 314.749C278.062 314.749 278.403 314.643 278.681 314.433C278.959 314.22 279.171 313.926 279.316 313.551C279.461 313.173 279.533 312.737 279.533 312.243C279.533 311.754 279.462 311.327 279.32 310.96C279.178 310.591 278.968 310.304 278.69 310.099C278.411 309.892 278.067 309.788 277.658 309.788C277.232 309.788 276.877 309.898 276.593 310.116C276.312 310.332 276.1 310.626 275.958 310.999C275.819 311.368 275.749 311.783 275.749 312.243C275.749 312.709 275.82 313.132 275.962 313.513C276.107 313.891 276.32 314.192 276.601 314.416C276.886 314.638 277.238 314.749 277.658 314.749Z"
fill="hsl(var(--brand-default))"
diff --git a/apps/www/lib/mdx/mdxComponents.tsx b/apps/www/lib/mdx/mdxComponents.tsx
index 2006c6910e6..323285bf023 100644
--- a/apps/www/lib/mdx/mdxComponents.tsx
+++ b/apps/www/lib/mdx/mdxComponents.tsx
@@ -1,5 +1,12 @@
+import 'react-medium-image-zoom/dist/styles.css'
+
import { PropsWithChildren } from 'react'
import Image from 'next/image'
+import { useRouter } from 'next/router'
+import CopyToClipboard from 'react-copy-to-clipboard'
+import { isBrowser, useCopy } from 'common'
+import { ThemeImage } from 'ui-patterns/ThemeImage'
+
import Avatar from '~/components/Avatar'
import CodeBlock from '~/components/CodeBlock/CodeBlock'
import { CH } from '@code-hike/mdx/components'
@@ -15,13 +22,13 @@ import {
IconTriangle,
cn,
Admonition,
+ IconLink,
+ IconCheck,
+ Heading,
} from 'ui'
import ImageFadeStack from '~/components/ImageFadeStack'
import ZoomableImg from '~/components/ZoomableImg/ZoomableImg'
-import 'react-medium-image-zoom/dist/styles.css'
-import { ThemeImage } from 'ui-patterns/ThemeImage'
-
// import all components used in blog articles here
// to do: move this into a helper/utils, it is used elsewhere
@@ -66,6 +73,12 @@ export default function mdxComponents(type?: 'blog' | 'lp' | undefined) {
const components = {
CodeBlock,
CH,
+ h1: (props: any) => <Heading {...props} tag="h1" />,
+ h2: (props: any) => <Heading {...props} tag="h2" />,
+ h3: (props: any) => <Heading {...props} tag="h3" />,
+ h4: (props: any) => <Heading {...props} tag="h4" />,
+ h5: (props: any) => <Heading {...props} tag="h5" />,
+ h6: (props: any) => <Heading {...props} tag="h6" />,
Badge,
Quote,
Avatar,
diff --git a/apps/www/pages/blog.tsx b/apps/www/pages/blog.tsx
index 45d68a551c9..daf21c71769 100644
--- a/apps/www/pages/blog.tsx
+++ b/apps/www/pages/blog.tsx
@@ -1,96 +1,32 @@
import fs from 'fs'
-import { useEffect, useState } from 'react'
-
+import { useState } from 'react'
import { useRouter } from 'next/router'
-import Image from 'next/legacy/image'
-import Link from 'next/link'
-
import { NextSeo } from 'next-seo'
import { generateRss } from '~/lib/rss'
import { getSortedPosts } from '~/lib/posts'
-import authors from 'lib/authors.json'
import PostTypes from '~/types/post'
import DefaultLayout from '~/components/Layouts/Default'
+import BlogGridItem from '~/components/Blog/BlogGridItem'
import BlogListItem from '~/components/Blog/BlogListItem'
import BlogFilters from '~/components/Blog/BlogFilters'
+import FeaturedThumb from '~/components/Blog/FeaturedThumb'
+import { cn } from 'ui'
+import { LOCAL_STORAGE_KEYS, isBrowser } from 'common'
-export async function getStaticProps() {
- const allPostsData = getSortedPosts({ directory: '_blog', runner: '** BLOG PAGE **' })
- const rss = generateRss(allPostsData)
-
- // create a rss feed in public directory
- // rss feed is added via <Head> component in render return
- fs.writeFileSync('./public/rss.xml', rss)
-
- // generate a series of rss feeds for each author (for PlanetPG)
- const planetPgPosts = allPostsData.filter((post: any) => post.tags?.includes('planetpg'))
- const planetPgAuthors = planetPgPosts.map((post: any) => post.author.split(','))
- const uniquePlanetPgAuthors = new Set([].concat(...planetPgAuthors))
-
- uniquePlanetPgAuthors.forEach((author) => {
- const authorPosts = planetPgPosts.filter((post: any) => post.author.includes(author))
- if (authorPosts.length > 0) {
- const authorRss = generateRss(authorPosts, author)
- fs.writeFileSync(`./public/planetpg-${author}-rss.xml`, authorRss)
- }
- })
-
- return {
- props: {
- blogs: allPostsData,
- },
- }
-}
+export type BlogView = 'list' | 'grid'
function Blog(props: any) {
+ const { BLOG_VIEW } = LOCAL_STORAGE_KEYS
+ const localView = isBrowser ? (localStorage?.getItem(BLOG_VIEW) as BlogView) : undefined
const [blogs, setBlogs] = useState(props.blogs)
- const [category, setCategory] = useState<string>('all')
-
- // Using hard-coded categories as they:
- // - serve as a reference
- // - are easier to reorder
- const allCategories = [
- 'all',
- 'product',
- 'company',
- 'postgres',
- 'developers',
- 'engineering',
- 'launch-week',
- ]
+ const [view, setView] = useState<BlogView>(localView ?? 'list')
+ const isList = view === 'list'
const router = useRouter()
const meta_title = 'Supabase Blog: Open Source Firebase alternative Blog'
const meta_description = 'Get all your Supabase News on the Supabase blog.'
- useEffect(() => {
- handlePosts()
- }, [category])
-
- const handlePosts = () => {
- // construct an array of blog posts
- // not inluding the first blog post
- const shiftedBlogs = [...props.blogs]
- shiftedBlogs.shift()
-
- if (category === 'all') {
- router.replace('/blog', undefined, { shallow: true, scroll: false })
- } else {
- router.query.category = category
- router.replace(router, undefined, { shallow: true, scroll: false })
- }
-
- setBlogs(
- category === 'all'
- ? shiftedBlogs
- : props.blogs.filter((post: any) => {
- const found = post.categories?.includes(category)
- return found
- })
- )
- }
-
return (
<>
<NextSeo
@@ -116,36 +52,42 @@ function Blog(props: any) {
/>
<DefaultLayout>
<h1 className="sr-only">Supabase blog</h1>
- <div className="overflow-hidden py-12 lg:py-20">
- <div className="container mx-auto px-8 sm:px-16 xl:px-20">
- <div className="mx-auto ">
- {props.blogs.slice(0, 1).map((blog: any, i: number) => (
- <FeaturedThumb key={i} {...blog} />
- ))}
- </div>
- </div>
+ <div className="md:container mx-auto py-4 lg:py-10 px-4 sm:px-12 xl:px-16">
+ {props.blogs.slice(0, 1).map((blog: any, i: number) => (
+ <FeaturedThumb key={i} {...blog} />
+ ))}
</div>
<div className="border-default border-t">
- <div className="container mx-auto mt-10 lg:mt-16 px-8 sm:px-16 xl:px-20">
+ <div className="md:container mx-auto mt-6 lg:mt-8 px-6 sm:px-16 xl:px-20">
<BlogFilters
- posts={blogs}
+ allPosts={props.blogs}
setPosts={setBlogs}
- setCategory={setCategory}
- allCategories={allCategories}
- handlePosts={handlePosts}
+ view={view as BlogView}
+ setView={setView}
/>
- <ol className="grid grid-cols-12 py-10 lg:py-16 lg:gap-16">
+ <ol
+ className={cn(
+ 'grid -mx-2 sm:-mx-4 py-6 lg:py-6 lg:pb-20',
+ isList ? 'grid-cols-1' : 'grid-cols-12 lg:gap-4'
+ )}
+ >
{blogs?.length ? (
- blogs?.map((blog: PostTypes, idx: number) => (
- <div
- className="col-span-12 mb-16 md:col-span-12 lg:col-span-6 xl:col-span-4"
- key={idx}
- >
- <BlogListItem post={blog} />
- </div>
- ))
+ blogs?.map((blog: PostTypes, idx: number) =>
+ isList ? (
+ <div className="col-span-12 px-2 sm:px-4 [&_a]:last:border-none" key={idx}>
+ <BlogListItem post={blog} />
+ </div>
+ ) : (
+ <div
+ className="col-span-12 mb-4 md:col-span-12 lg:col-span-6 xl:col-span-4 h-full"
+ key={idx}
+ >
+ <BlogGridItem post={blog} />
+ </div>
+ )
+ )
) : (
<p className="text-sm text-light col-span-full">No results</p>
)}
@@ -157,70 +99,32 @@ function Blog(props: any) {
)
}
-function FeaturedThumb(blog: PostTypes) {
- // @ts-ignore
- const authorArray = blog.author.split(',')
+export async function getStaticProps() {
+ const allPostsData = getSortedPosts({ directory: '_blog', runner: '** BLOG PAGE **' })
+ const rss = generateRss(allPostsData)
- const author = []
- for (let i = 0; i < authorArray.length; i++) {
- // @ts-ignore
- author.push(
- authors.find((authors: any) => {
- // @ts-ignore
- return authors.author_id === authorArray[i]
- })
- )
- }
+ // create a rss feed in public directory
+ // rss feed is added via <Head> component in render return
+ fs.writeFileSync('./public/rss.xml', rss)
- return (
- <div key={blog.slug} className="w-full cursor-pointer">
- <Link href={`${blog.path}`} className="grid gap-8 lg:grid-cols-2 lg:gap-16">
- <div className="relative w-full aspect-[2/1] lg:aspect-[3/2] overflow-auto rounded-lg border">
- <Image
- src={`/images/blog/` + (blog.thumb ? blog.thumb : blog.image)}
- layout="fill"
- className="object-cover"
- alt="blog thumbnail"
- />
- </div>
- <div className="flex flex-col space-y-2">
- <div className="text-light flex space-x-2 text-sm">
- <span>{blog.date}</span>
- <span>•</span>
- <span>{blog.readingTime}</span>
- </div>
+ // generate a series of rss feeds for each author (for PlanetPG)
+ const planetPgPosts = allPostsData.filter((post: any) => post.tags?.includes('planetpg'))
+ const planetPgAuthors = planetPgPosts.map((post: any) => post.author.split(','))
+ const uniquePlanetPgAuthors = new Set([].concat(...planetPgAuthors))
- <div>
- <h2 className="h2">{blog.title}</h2>
- <p className="p text-xl">{blog.description}</p>
- </div>
+ uniquePlanetPgAuthors.forEach((author) => {
+ const authorPosts = planetPgPosts.filter((post: any) => post.author.includes(author))
+ if (authorPosts.length > 0) {
+ const authorRss = generateRss(authorPosts, author)
+ fs.writeFileSync(`./public/planetpg-${author}-rss.xml`, authorRss)
+ }
+ })
- <div className="flex flex-col w-max gap-2">
- {author.map((author: any, i: number) => {
- return (
- <div className="flex items-center space-x-3" key={i}>
- {author.author_image_url && (
- <div className="relative h-10 w-10 overflow-auto">
- <Image
- src={author.author_image_url}
- alt={`${author.author} avatar`}
- className="rounded-full object-cover"
- layout="fill"
- />
- </div>
- )}
- <div className="flex flex-col">
- <span className="text-foreground m-0 text-sm">{author.author}</span>
- <span className="text-light m-0 text-xs">{author.position}</span>
- </div>
- </div>
- )
- })}
- </div>
- </div>
- </Link>
- </div>
- )
+ return {
+ props: {
+ blogs: allPostsData,
+ },
+ }
}
export default Blog
diff --git a/apps/www/pages/blog/[slug].tsx b/apps/www/pages/blog/[slug].tsx
index 60cee0d4b95..e64b4356e95 100644
--- a/apps/www/pages/blog/[slug].tsx
+++ b/apps/www/pages/blog/[slug].tsx
@@ -1,24 +1,24 @@
+import matter from 'gray-matter'
import { NextSeo } from 'next-seo'
import type { GetStaticProps, InferGetStaticPropsType } from 'next'
import Image from 'next/image'
import Link from 'next/link'
import { useRouter } from 'next/router'
-import matter from 'gray-matter'
-import authors from 'lib/authors.json'
import { MDXRemote } from 'next-mdx-remote'
-import { Badge, Divider, IconChevronLeft } from 'ui'
+import { ReactMarkdown } from 'react-markdown/lib/react-markdown'
+import { Badge, IconChevronLeft } from 'ui'
+import authors from 'lib/authors.json'
+import { getAllPostSlugs, getPostdata, getSortedPosts } from '~/lib/posts'
+import mdxComponents from '~/lib/mdx/mdxComponents'
+import { mdxSerialize } from '~/lib/mdx/mdxSerialize'
+import { generateReadingTime, isNotNullOrUndefined } from '~/lib/helpers'
+
+import BlogLinks from '~/components/LaunchWeek/7/BlogLinks'
import CTABanner from '~/components/CTABanner'
import DefaultLayout from '~/components/Layouts/Default'
-import BlogLinks from '~/components/LaunchWeek/7/BlogLinks'
-import { generateReadingTime, isNotNullOrUndefined } from '~/lib/helpers'
+import LWXSummary from '~/components/LaunchWeek/X/LWXSummary'
import ShareArticleActions from '~/components/Blog/ShareArticleActions'
-import useActiveAnchors from '~/hooks/useActiveAnchors'
-import mdxComponents from '~/lib/mdx/mdxComponents'
-import { mdxSerialize } from '~/lib/mdx/mdxSerialize'
-import { getAllPostSlugs, getPostdata, getSortedPosts } from '~/lib/posts'
-import { ReactMarkdown } from 'react-markdown/lib/react-markdown'
-import LWXSummary from '../../components/LaunchWeek/X/LWXSummary'
type Post = ReturnType<typeof getSortedPosts>[number]
@@ -121,7 +121,6 @@ export const getStaticProps: GetStaticProps<BlogPostPageProps, Params> = async (
function BlogPostPage(props: InferGetStaticPropsType<typeof getStaticProps>) {
const content = props.blog.content
const authorArray = props.blog.author.split(',')
- useActiveAnchors('h2, h3, h4', '.prose-toc a')
const isLaunchWeek7 = props.blog.launchweek === 7
const isLaunchWeekX = props.blog.launchweek?.toString().toLocaleLowerCase() === 'x'
@@ -231,10 +230,10 @@ function BlogPostPage(props: InferGetStaticPropsType<typeof getStaticProps>) {
],
}}
/>
- <DefaultLayout className="overflow-x-hidden">
+ <DefaultLayout>
<div
className="
- container mx-auto px-6 py-4 md:py-8 xl:py-16 sm:px-16
+ container mx-auto px-4 py-4 md:py-8 xl:py-10 sm:px-16
xl:px-20
"
>
@@ -251,7 +250,7 @@ function BlogPostPage(props: InferGetStaticPropsType<typeof getStaticProps>) {
</div>
<div className="col-span-12 lg:col-span-12 xl:col-span-10">
{/* Title and description */}
- <div className="mb-6 lg:mb-12 max-w-5xl space-y-8">
+ <div className="mb-6 lg:mb-10 max-w-5xl space-y-8">
<div className="space-y-4">
<Link href="/blog" className="text-brand hidden lg:inline">
Blog
@@ -263,7 +262,7 @@ function BlogPostPage(props: InferGetStaticPropsType<typeof getStaticProps>) {
<p>{generateReadingTime(props.blog.source)}</p>
</div>
<div className="hidden lg:flex justify-between">
- <div className="flex-1 flex flex-col gap-3 pt-6 md:flex-row md:gap-0 lg:gap-3">
+ <div className="flex-1 flex flex-col gap-3 pt-2 md:flex-row md:gap-0 lg:gap-3">
{author.map((author: any, i: number) => {
return (
<div className="mr-4 w-max" key={i}>
@@ -303,7 +302,7 @@ function BlogPostPage(props: InferGetStaticPropsType<typeof getStaticProps>) {
</div>
<div className="grid grid-cols-12 lg:gap-16 xl:gap-8">
{/* Content */}
- <div className="col-span-12 lg:col-span-7 xl:col-span-7">
+ <div className="col-span-12 lg:col-span-7 xl:col-span-7 overflow-x-hidden">
<article>
<div className={['prose prose-docs'].join(' ')}>
{props.blog.youtubeHero ? (
@@ -312,11 +311,9 @@ function BlogPostPage(props: InferGetStaticPropsType<typeof getStaticProps>) {
width="700"
height="350"
src={props.blog.youtubeHero}
- frameBorder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
- // @ts-expect-error
- allowfullscreen={true}
- ></iframe>
+ allowFullScreen={true}
+ />
) : (
props.blog.thumb && (
<div className="hidden md:block relative mb-8 h-96 w-full overflow-auto rounded-lg border">
@@ -324,6 +321,7 @@ function BlogPostPage(props: InferGetStaticPropsType<typeof getStaticProps>) {
src={'/images/blog/' + props.blog.thumb}
alt={props.blog.title}
fill
+ sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
className="object-cover m-0"
/>
</div>
@@ -350,44 +348,12 @@ function BlogPostPage(props: InferGetStaticPropsType<typeof getStaticProps>) {
</div>
</div>
{/* Sidebar */}
- <div className="col-span-12 space-y-8 lg:col-span-5 xl:col-span-3 xl:col-start-9">
- <div className="space-y-6 lg:sticky lg:top-24 lg:mb-48">
+ <div className="relative col-span-12 space-y-8 lg:col-span-5 xl:col-span-3 xl:col-start-9">
+ <div className="space-y-6">
<div className="hidden lg:block">{toc}</div>
- <div>
- <div className="mb-4">
- <p className="text-foreground text-sm">Related articles</p>
- </div>
- <div className="space-y-2">
- {props.relatedPosts.map((post) => (
- <Link href={`${post.path}`} as={`${post.path}`} key={post.slug}>
- <div>
- <div className="cursor-pointer">
- <div className="flex gap-2">
- {/* <div className="text-foreground-lighter">
- <IconFile size={'small'} style={{ minWidth: '1.2rem' }} />
- </div> */}
- <span className="text-light hover:text-gray-1200 text-sm">
- {post.title}
- </span>
- </div>
- </div>
- <Divider light className="mt-2" />
- </div>
- </Link>
- ))}
- <div className="mt-2">
- <Link
- href={`/blog`}
- className="text-light hover:text-foreground cursor-pointer text-xs"
- >
- View all posts
- </Link>
- </div>
- <div className="py-4 hidden lg:block">
- <div className="text-foreground text-sm">Share this article</div>
- <ShareArticleActions title={props.blog.title} slug={props.blog.slug} />
- </div>
- </div>
+ <div className="hidden lg:block">
+ <div className="text-foreground text-sm">Share this article</div>
+ <ShareArticleActions title={props.blog.title} slug={props.blog.slug} />
</div>
</div>
</div>
diff --git a/apps/www/pages/blog/categories/[category].tsx b/apps/www/pages/blog/categories/[category].tsx
index ac3f09be60a..788b0866005 100644
--- a/apps/www/pages/blog/categories/[category].tsx
+++ b/apps/www/pages/blog/categories/[category].tsx
@@ -4,7 +4,7 @@ import Link from 'next/link'
import { startCase } from 'lodash'
import DefaultLayout from '~/components/Layouts/Default'
-import BlogListItem from '~/components/Blog/BlogListItem'
+import BlogGridItem from '~/components/Blog/BlogGridItem'
import PostTypes from '~/types/post'
export async function getStaticProps({ params }: any) {
@@ -55,7 +55,7 @@ function CategoriesIndex(props: Props) {
className="col-span-12 mb-16 md:col-span-12 lg:col-span-6 xl:col-span-4"
key={idx}
>
- <BlogListItem post={blog} />
+ <BlogGridItem post={blog} />
</div>
))}
</ol>
diff --git a/apps/www/pages/blog/tags/[tag].tsx b/apps/www/pages/blog/tags/[tag].tsx
index 7152eb5f5c2..f6fcad0f2e5 100644
--- a/apps/www/pages/blog/tags/[tag].tsx
+++ b/apps/www/pages/blog/tags/[tag].tsx
@@ -4,7 +4,7 @@ import Link from 'next/link'
import { startCase } from 'lodash'
import DefaultLayout from '~/components/Layouts/Default'
-import BlogListItem from '~/components/Blog/BlogListItem'
+import BlogGridItem from '~/components/Blog/BlogGridItem'
import PostTypes from '~/types/post'
export async function getStaticProps({ params }: any) {
@@ -55,7 +55,7 @@ function TagBlogsPage(props: Props) {
className="col-span-12 mb-16 md:col-span-12 lg:col-span-6 xl:col-span-4"
key={idx}
>
- <BlogListItem post={blog} />
+ <BlogGridItem post={blog} />
</div>
))}
</ol>
diff --git a/apps/www/public/planetpg-raminder_singh-rss.xml b/apps/www/public/planetpg-raminder_singh-rss.xml
new file mode 100644
index 00000000000..6c9697a6ecc
--- /dev/null
+++ b/apps/www/public/planetpg-raminder_singh-rss.xml
@@ -0,0 +1,19 @@
+
+ <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
+ <channel>
+ <title>'Postgres | Supabase Blog</title>
+ <link>https://supabase.com/blog</link>
+ <description>Latest Postgres news from Raminder Singh at Supabase</description>
+ <language>en</language>
+ <lastBuildDate>Tue, 23 Jan 2024 23:00:00 GMT</lastBuildDate>
+ <atom:link href="https://supabase.com/planetpg-raminder_singh-rss.xml" rel="self" type="application/rss+xml"/>
+ <item>
+ <guid>https://supabase.com/blog/how-pg-graphql-works</guid>
+ <title>How pg_graphql works</title>
+ <link>https://supabase.com/blog/how-pg-graphql-works</link>
+ <description>An insight into the internals of GraphQL in Postgres using pg_graphql, and how you can contribute.</description>
+ <pubDate>Tue, 23 Jan 2024 23:00:00 GMT</pubDate>
+</item>
+
+ </channel>
+ </rss>
diff --git a/apps/www/public/rss.xml b/apps/www/public/rss.xml
index c2a285aa140..80246d45679 100644
--- a/apps/www/public/rss.xml
+++ b/apps/www/public/rss.xml
@@ -5,9 +5,37 @@
<link>https://supabase.com</link>
<description>Latest news from Supabase</description>
<language>en</language>
- <lastBuildDate>Thu, 25 Jan 2024 23:00:00 GMT</lastBuildDate>
+ <lastBuildDate>Mon, 12 Feb 2024 23:00:00 GMT</lastBuildDate>
<atom:link href="https://supabase.com/rss.xml" rel="self" type="application/rss+xml"/>
<item>
+ <guid>https://supabase.com/blog/matryoshka-embeddings</guid>
+ <title>Matryoshka embeddings: faster OpenAI vector search using Adaptive Retrieval</title>
+ <link>https://supabase.com/blog/matryoshka-embeddings</link>
+ <description>Use Adaptive Retrieval to improve query performance with OpenAI&apos;s new embedding models</description>
+ <pubDate>Mon, 12 Feb 2024 23:00:00 GMT</pubDate>
+</item>
+<item>
+ <guid>https://supabase.com/blog/nosql-mongodb-compatibility-with-ferretdb-and-flydotio</guid>
+ <title>NoSQL Postgres: Add MongoDB compatibility to your Supabase projects with FerretDB</title>
+ <link>https://supabase.com/blog/nosql-mongodb-compatibility-with-ferretdb-and-flydotio</link>
+ <description>NoSQL Postgres: Add MongoDB compatibility to your Supabase projects with FerretDB</description>
+ <pubDate>Tue, 30 Jan 2024 23:00:00 GMT</pubDate>
+</item>
+<item>
+ <guid>https://supabase.com/blog/pgvector-fast-builds</guid>
+ <title>pgvector 0.6.0: 30x faster with parallel index builds</title>
+ <link>https://supabase.com/blog/pgvector-fast-builds</link>
+ <description>pgvector 0.6.0 brings a significant improvement: parallel index builds for HNSW. Building an HNSW index is now up to 30x faster for unlogged tables.</description>
+ <pubDate>Mon, 29 Jan 2024 23:00:00 GMT</pubDate>
+</item>
+<item>
+ <guid>https://supabase.com/blog/ruby-on-rails-postgres</guid>
+ <title>Getting started with Ruby on Rails and Postgres on Supabase</title>
+ <link>https://supabase.com/blog/ruby-on-rails-postgres</link>
+ <description>Learn how to create a new Rails app and connect it to a Supabase Postgres database.</description>
+ <pubDate>Sun, 28 Jan 2024 23:00:00 GMT</pubDate>
+</item>
+<item>
<guid>https://supabase.com/blog/flutter-figma-clone</guid>
<title>Create a Figma Clone app with Flutter and Supabase Realtime</title>
<link>https://supabase.com/blog/flutter-figma-clone</link>
diff --git a/apps/www/types/post.ts b/apps/www/types/post.ts
index 607120a9e09..30c42e28ac6 100644
--- a/apps/www/types/post.ts
+++ b/apps/www/types/post.ts
@@ -19,6 +19,7 @@ type PostTypes = {
url: string
path: string
tags?: []
+ categories?: []
logo?: string
logo_inverse?: string
hideAuthor?: boolean
diff --git a/packages/common/constants/local-storage.ts b/packages/common/constants/local-storage.ts
index 8826de33cae..46b45969e9c 100644
--- a/packages/common/constants/local-storage.ts
+++ b/packages/common/constants/local-storage.ts
@@ -1,4 +1,5 @@
export const LOCAL_STORAGE_KEYS = {
TELEMETRY_CONSENT: 'supabase-consent',
HIDE_PROMO_TOAST: 'supabase-hide-promo-toast',
+ BLOG_VIEW: 'supabase-blog-view',
}
diff --git a/packages/common/hooks/index.ts b/packages/common/hooks/index.ts
index de011d364a4..74e8477312a 100644
--- a/packages/common/hooks/index.ts
+++ b/packages/common/hooks/index.ts
@@ -1,5 +1,6 @@
export * from './useBreakpoint'
export * from './useConstant'
+export * from './useCopy'
export * from './useDebounce'
export * from './useParams'
export * from './useTelemetryProps'
diff --git a/packages/common/hooks/useCopy.ts b/packages/common/hooks/useCopy.ts
new file mode 100644
index 00000000000..460df34f30a
--- /dev/null
+++ b/packages/common/hooks/useCopy.ts
@@ -0,0 +1,14 @@
+import { useState } from 'react'
+
+export function useCopy() {
+ const [copied, setCopied] = useState(false)
+
+ function handleCopy() {
+ setCopied(true)
+ setTimeout(() => {
+ setCopied(false)
+ }, 1000)
+ }
+
+ return { copied, handleCopy }
+}
diff --git a/packages/ui/index.tsx b/packages/ui/index.tsx
index 7c1bab0afb6..4dd90fe2fac 100644
--- a/packages/ui/index.tsx
+++ b/packages/ui/index.tsx
@@ -38,12 +38,17 @@ export * from './src/components/PromoToast'
export * from './src/components/Popover'
export * from './src/layout/PortalToast'
+// HTML
+
+export * from './src/components/CustomHTMLElements'
+
// UTILITIES
export * from './src/components/Space'
export * from './src/components/Loading'
export * from './src/components/LogoLoader'
export * from './src/components/Divider'
+export * from './src/lib/utils'
// DATA ENTRY
@@ -69,9 +74,6 @@ export * from './src/layout/banners'
// ai icon
export * from './src/layout/ai-icon-animation'
-// utilities
-export * from './src/lib/utils'
-
// theme switcher
export * from './src/components/ThemeProvider/themes'
export * from './src/components/ThemeProvider/singleThemes'
diff --git a/packages/ui/src/components/CustomHTMLElements/CustomHTMLElements.utils.test.ts b/packages/ui/src/components/CustomHTMLElements/CustomHTMLElements.utils.test.ts
new file mode 100644
index 00000000000..2d2d1285229
--- /dev/null
+++ b/packages/ui/src/components/CustomHTMLElements/CustomHTMLElements.utils.test.ts
@@ -0,0 +1,96 @@
+import { getAnchor, removeAnchor } from './CustomHTMLElements.utils'
+
+describe('CustomHTMLElementsUtils', () => {
+ describe('getAnchor', () => {
+ describe('when value is an object', () => {
+ it('returns slugified version of props.children', () => {
+ const value = {
+ props: {
+ children: 'Full Text Search',
+ },
+ }
+
+ const result = getAnchor(value)
+
+ expect(result).toStrictEqual('full-text-search')
+ })
+ })
+
+ describe('when value is an array', () => {
+ describe('when custom anchor exists', () => {
+ it('returns inner slug', () => {
+ const value = ['Proximity: <->', '[#proximity]']
+
+ const result = getAnchor(value)
+
+ expect(result).toStrictEqual('proximity')
+ })
+
+ it('trims whitespace', () => {
+ const value = ['Proximity: <->', ' [#proximity] ']
+
+ const result = getAnchor(value)
+
+ expect(result).toStrictEqual('proximity')
+ })
+ })
+
+ it('returns concatenated slug of elements', () => {
+ const value = ['Full', 'Text', 'Search']
+
+ const result = getAnchor(value)
+
+ expect(result).toStrictEqual('full-text-search')
+ })
+
+ it('trims whitespace', () => {
+ const value = [' Full ', ' Text ', ' Search ']
+
+ const result = getAnchor(value)
+
+ expect(result).toStrictEqual('full-text-search')
+ })
+
+ it('removes special characters', () => {
+ const value = ['function()']
+
+ const result = getAnchor(value)
+
+ expect(result).toStrictEqual('function')
+ })
+ })
+
+ describe('when value is a string', () => {
+ it('returns slugified version of string', () => {
+ const value = 'My (Very) Awesome Heading'
+
+ const result = getAnchor(value)
+
+ expect(result).toStrictEqual('my-very-awesome-heading')
+ })
+ })
+ })
+
+ describe('removeAnchor', () => {
+ describe('when value is an array', () => {
+ it('filters out custom anchor elements', () => {
+ const value = ['My (Very) Awesome Heading', '[#my-custom-heading]']
+
+ const result = removeAnchor(value)
+
+ expect(result).toStrictEqual(['My (Very) Awesome Heading'])
+ })
+ })
+
+ describe('when value is a string', () => {
+ it('strips out custom anchor string', () => {
+ const value = 'My (Very) Awesome Heading [#my-custom-heading]'
+
+ const result = removeAnchor(value)
+
+ // Original implementation didn't trim the resulting string - not sure if it really matters
+ expect(result).toStrictEqual('My (Very) Awesome Heading ')
+ })
+ })
+ })
+})
diff --git a/packages/ui/src/components/CustomHTMLElements/CustomHTMLElements.utils.ts b/packages/ui/src/components/CustomHTMLElements/CustomHTMLElements.utils.ts
new file mode 100644
index 00000000000..337f48b2bbf
--- /dev/null
+++ b/packages/ui/src/components/CustomHTMLElements/CustomHTMLElements.utils.ts
@@ -0,0 +1,101 @@
+// Check if heading has custom anchor first, before forming the anchor based on the title
+export const getAnchor = (text: any): string | undefined => {
+ if (typeof text === 'object') {
+ if (Array.isArray(text)) {
+ const customAnchor = text.find((x) => typeof x === 'string' && hasCustomAnchor(x))
+ if (customAnchor !== undefined) {
+ return parseCustomAnchor(customAnchor)
+ }
+
+ const formattedText = text
+ .map((x) => {
+ if (typeof x !== 'string') {
+ return x.props.children
+ }
+
+ return x.trim()
+ })
+ .map((x) => {
+ if (typeof x !== 'string') {
+ return x
+ }
+
+ return slugify(x)
+ })
+
+ return formattedText.join('-').toLowerCase()
+ } else {
+ const anchor = text.props.children
+ if (typeof anchor === 'string') {
+ return slugify(anchor)
+ }
+ return anchor
+ }
+ } else if (typeof text === 'string') {
+ if (hasCustomAnchor(text)) {
+ return parseCustomAnchor(text)
+ }
+ return slugify(text)
+ } else {
+ return undefined
+ }
+}
+
+const hasCustomAnchor = (value: string): boolean => value.includes('[#') && value.includes(']')
+
+const parseCustomAnchor = (value: string): string =>
+ value.slice(value.indexOf('[#') + 2, value.indexOf(']'))
+
+const slugify = (value: string): string =>
+ value
+ .toLowerCase()
+ .trim()
+ .replace(/[^a-z0-9- ]/g, '')
+ .replace(/[ ]/g, '-')
+
+export const removeAnchor = (text: any) => {
+ if (typeof text === 'object' && Array.isArray(text)) {
+ return text.filter((x) => !(typeof x === 'string' && hasCustomAnchor(x)))
+ } else if (typeof text === 'string') {
+ if (text.indexOf('[#') > 0) return text.slice(0, text.indexOf('[#'))
+ else return text
+ }
+ return text
+}
+
+export const highlightSelectedTocItem = (id: string) => {
+ const tocMenuItems = document.querySelectorAll('.toc-menu a')
+
+ // find any currently active items and remove them
+ const currentActiveItem = document.querySelector('.toc-menu .toc__menu-item--active')
+ currentActiveItem?.classList.remove('toc__menu-item--active')
+
+ // Add active class to the current item
+ tocMenuItems.forEach((item) => {
+ // @ts-ignore
+ if (item.href.split('#')[1] === id) {
+ item.classList.add('toc__menu-item--active')
+ }
+ })
+}
+
+// find any currently active items and remove them on route change
+export const unHighlightSelectedTocItems = () => {
+ const currentActiveItem = document.querySelector('.toc-menu .toc__menu-item--active')
+ currentActiveItem?.classList.remove('toc__menu-item--active')
+}
+
+export const highlightSelectedNavItem = (id: string) => {
+ const navMenuItems = document.querySelectorAll<HTMLAnchorElement>('.function-link-item a')
+
+ // find any currently active items and remove them
+ const currentActiveItems = document.querySelectorAll('.function-link-list .text-brand')
+ currentActiveItems.forEach((item) => item.classList.remove('text-brand'))
+
+ // Add active class to the current item
+ navMenuItems.forEach((item) => {
+ if (item.href.split('/').at(-1) === id) {
+ item.classList.add('text-brand')
+ }
+ })
+}
diff --git a/packages/ui/src/components/CustomHTMLElements/Heading.tsx b/packages/ui/src/components/CustomHTMLElements/Heading.tsx
new file mode 100644
index 00000000000..bb3eed1a3d9
--- /dev/null
+++ b/packages/ui/src/components/CustomHTMLElements/Heading.tsx
@@ -0,0 +1,60 @@
+import {
+ getAnchor,
+ removeAnchor,
+ highlightSelectedTocItem,
+ unHighlightSelectedTocItems,
+} from './CustomHTMLElements.utils'
+import { useInView } from 'react-intersection-observer'
+
+/**
+ * [Joshen] The trick with rootMargin
+ * We are shrinking the top of the root element by 20 percent, which is currently our entire page,
+ * and the bottom by 35 percent. Therefore, when a header is at the top 20 percent and bottom 35 percent
+ * of our page, it will not be counted as visible.
+ */
+
+interface Props {
+ tag?: string
+ parseAnchors?: boolean
+ customAnchor?: string
+}
+
+/**
+ * This TOC is used in .mdx files and in .tsx files.
+ * In mdx files, we need to parse the content and format them to match the
+ * expected tocList format (text, link,level).
+ *
+ * In tsx files, we can generate this tocList directly. For these files, we don't
+ * need to parse the <a> and generate anchors. Custom anchors are used in tsx files.
+ * (see: /pages/guides/cli/config.tsx)
+ */
+const Heading: React.FC<React.PropsWithChildren<Props>> = ({ tag, customAnchor, children }) => {
+ const HeadingTag = `${tag}` as any
+ const anchor = customAnchor ? customAnchor : getAnchor(children)
+ const link = `#${anchor}`
+
+ const { ref } = useInView({
+ threshold: 1,
+ rootMargin: '-20% 0% -35% 0px',
+ onChange: (inView, entry) => {
+ if (window.scrollY === 0) unHighlightSelectedTocItems()
+ if (inView) highlightSelectedTocItem(entry.target.id)
+ },
+ })
+
+ return (
+ <HeadingTag id={anchor} ref={ref} className="group scroll-mt-24">
+ {removeAnchor(children)}
+ {anchor && (
+ <a
+ href={link}
+ aria-hidden="true"
+ className="ml-2 opacity-0 group-hover:opacity-100 transition"
+ >
+ <span aria-hidden="true">#</span>
+ </a>
+ )}
+ </HeadingTag>
+ )
+}
+export default Heading
diff --git a/packages/ui/src/components/CustomHTMLElements/index.tsx b/packages/ui/src/components/CustomHTMLElements/index.tsx
new file mode 100644
index 00000000000..51b2839dcc1
--- /dev/null
+++ b/packages/ui/src/components/CustomHTMLElements/index.tsx
@@ -0,0 +1,5 @@
+import Heading from './Heading'
+
+export { Heading }
+
+export default Heading