Skip to content

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

chore: add 'article' open graph meta info.

Jonathan Summers-Muire8809669d5b2
diff --git a/www/lib/helpers.tsx b/www/lib/helpers.tsx
new file mode 100644
index 00000000000..c07c3c10278
--- /dev/null
+++ b/www/lib/helpers.tsx
@@ -0,0 +1,9 @@
+// get reading time
+// returns :string
+export const generateReadingTime = (text: string) => {
+ const wordsPerMinute = 200
+ const noOfWords = text.split(/\s/g).length
+ const minutes = noOfWords / wordsPerMinute
+ const readTime = Math.ceil(minutes)
+ return `${readTime} minute read`
+}
diff --git a/www/lib/posts.tsx b/www/lib/posts.tsx
index 2a8df12905c..b6245b7eea5 100644
--- a/www/lib/posts.tsx
+++ b/www/lib/posts.tsx
@@ -1,14 +1,12 @@
-// ./lib/posts.js
-
import fs from 'fs'
import path from 'path'
import matter from 'gray-matter'
+import { generateReadingTime } from './helpers'
//Finding directory named "blog" from the current working directory of Node.
const postDirectory = path.join(process.cwd(), '_blog')
export const getSortedPosts = (limit?: number, tags?: any) => {
- console.log(tags)
//Reads all the files in the post directory
const fileNames = fs.readdirSync(postDirectory)
@@ -20,24 +18,17 @@ export const getSortedPosts = (limit?: number, tags?: any) => {
const fullPath = path.join(postDirectory, filename)
//Extracts contents of the MDX file
const fileContents = fs.readFileSync(fullPath, 'utf8')
- const { data } = matter(fileContents)
+ const { data, content } = matter(fileContents)
const options = { month: 'long', day: 'numeric', year: 'numeric' }
const formattedDate = new Date(data.date).toLocaleDateString('en-IN', options)
- // // add tags into categories array
- // data.tags.map((tag: string) => {
- // if (!categories.includes(tag)) return categories.push(tag)
- // })
-
- // if(this.items.indexOf(item) === -1) {
- // this.items.push(item);
- // console.log(this.items);
- // }
+ const readingTime = generateReadingTime(content)
const frontmatter = {
...data,
date: formattedDate,
+ readingTime,
}
return {
slug,
@@ -55,7 +46,6 @@ export const getSortedPosts = (limit?: number, tags?: any) => {
if (tags) {
allPostsData = allPostsData.filter((post: any) => {
- console.log(post)
const found = tags.some((tag: any) => post.tags.includes(tag))
return found
})
diff --git a/www/package-lock.json b/www/package-lock.json
index 6ec38fa6a10..632752a9d45 100644
--- a/www/package-lock.json
+++ b/www/package-lock.json
@@ -4795,6 +4795,11 @@
}
}
},
+ "next-seo": {
+ "version": "4.20.0",
+ "resolved": "https://registry.npmjs.org/next-seo/-/next-seo-4.20.0.tgz",
+ "integrity": "sha512-N3NIISxOV+6XatPdZWRt8L/PkdxX4qpl6s2uQVMYTkteo8hgpHDgs6XZkDzuHaPi10neSZoqQiytsxohTCyEvw=="
+ },
"node-abi": {
"version": "2.19.3",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.19.3.tgz",
diff --git a/www/package.json b/www/package.json
index c409a54093b..8bc060b6321 100644
--- a/www/package.json
+++ b/www/package.json
@@ -22,6 +22,7 @@
"markdown-toc": "^1.2.0",
"next": "latest",
"next-mdx-remote": "^2.1.3",
+ "next-seo": "^4.20.0",
"react": "^16.13.0",
"react-copy-to-clipboard": "^5.0.2",
"react-dom": "^16.13.0",
diff --git a/www/pages/blog.tsx b/www/pages/blog.tsx
index 39a5f367459..600faff1dd7 100644
--- a/www/pages/blog.tsx
+++ b/www/pages/blog.tsx
@@ -5,6 +5,8 @@ import authors from 'lib/authors.json'
import { getSortedPosts, getAllCategories } from '~/lib/posts'
import { useEffect, useState } from 'react'
+import { NextSeo } from 'next-seo'
+
export async function getStaticProps() {
const allPostsData = getSortedPosts()
const categories = getAllCategories()
@@ -35,63 +37,59 @@ function Blog(props: any) {
}, [category])
return (
- <DefaultLayout>
- <div className="bg-white dark:bg-dark-700 overflow-hidden py-12">
- <div className="container mx-auto px-8 sm:px-16 xl:px-20 mt-16">
- <div className="mx-auto max-w-7xl">
- <Typography.Title>Blog</Typography.Title>
+ <>
+ <NextSeo title="Blog" description="Latest news from the Supabase team." />
+ <DefaultLayout>
+ <div className="bg-white dark:bg-dark-700 overflow-hidden py-12">
+ <div className="container mx-auto px-8 sm:px-16 xl:px-20 mt-16">
+ <div className="mx-auto max-w-7xl">
+ <Typography.Title>Blog</Typography.Title>
+ </div>
</div>
</div>
- </div>
- <div className="bg-gray-50 dark:bg-dark-800 overflow-hidden py-12">
- <div className="container mx-auto px-8 sm:px-16 xl:px-20 mt-16">
- <div className="mx-auto max-w-7xl">
- <Typography.Title level={2}>Latests posts</Typography.Title>
- <div className="mt-5 max-w-lg mx-auto grid gap-16 lg:grid-cols-2 lg:max-w-none">
- {/* <ul> */}
- {props.blogs.slice(0, 2).map((blog: any, idx: any) => {
- return FeaturedThumb(blog)
- })}
- {/* </ul> */}
+ <div className="bg-gray-50 dark:bg-dark-800 overflow-hidden py-12">
+ <div className="container mx-auto px-8 sm:px-16 xl:px-20 mt-16">
+ <div className="mx-auto max-w-7xl">
+ <Typography.Title level={2}>Latests posts</Typography.Title>
+ <div className="mt-5 max-w-lg mx-auto grid gap-16 lg:grid-cols-2 lg:max-w-none">
+ {/* <ul> */}
+ {props.blogs.slice(0, 2).map((blog: any, idx: any) => {
+ return FeaturedThumb(blog)
+ })}
+ {/* </ul> */}
+ </div>
</div>
</div>
- </div>
- <div className="container mx-auto px-8 sm:px-16 xl:px-20 mt-32">
- <div className=" mx-auto max-w-7xl">
- <div className="grid grid-cols-12">
- <div className="col-span-8">
- <Typography.Title level={2}>More posts from the team</Typography.Title>
+ <div className="container mx-auto px-8 sm:px-16 xl:px-20 mt-32">
+ <div className=" mx-auto max-w-7xl">
+ <div className="grid grid-cols-12">
+ <div className="col-span-8">
+ <Typography.Title level={2}>More posts from the team</Typography.Title>
+ </div>
</div>
- {/* <Select className="sbui-border-fix col-span-4">
- <Select.Option value="" selected>
- Choose a category
- </Select.Option>
- <Select.Option value="case-study">Case study</Select.Option>
- <Select.Option value="supabase">Supabase</Select.Option>
- </Select> */}
+ <Space className="mt-6">
+ {props.categories.map((categoryId: string) => (
+ <Button
+ type={category === categoryId ? 'primary' : 'outline'}
+ key={categoryId}
+ onClick={() => setCategory(categoryId)}
+ >
+ {categoryId}
+ </Button>
+ ))}
+ </Space>
+ <div className="mt-12 max-w-lg mx-auto grid lg:grid-cols-1 lg:max-w-none">
+ {/* <ul> */}
+ {blogs.map((blog: any, idx: any) => {
+ return BlogListItem(blog)
+ })}
+ {/* </ul> */}
+ </div>{' '}
</div>
- <Space className="mt-6">
- {props.categories.map((categoryId: string) => (
- <Button
- type={category === categoryId ? 'primary' : 'outline'}
- key={categoryId}
- onClick={() => setCategory(categoryId)}
- >
- {categoryId}
- </Button>
- ))}
- </Space>
- <div className="mt-12 max-w-lg mx-auto grid lg:grid-cols-1 lg:max-w-none">
- {/* <ul> */}
- {blogs.map((blog: any, idx: any) => {
- return BlogListItem(blog)
- })}
- {/* </ul> */}
- </div>{' '}
</div>
</div>
- </div>
- </DefaultLayout>
+ </DefaultLayout>
+ </>
)
}
@@ -100,7 +98,7 @@ function FeaturedThumb(blog: any) {
const author = blog.author ? authors[blog.author] : authors['supabase']
return (
- <div key={blog.id} className="my-6">
+ <div key={blog.id} className="my-6 cursor-pointer">
<Link href={`/blog/${blog.slug}`} as={`/blog/${blog.slug}`}>
<div>
<img
@@ -112,7 +110,7 @@ function FeaturedThumb(blog: any) {
<Space className="mb-2">
<Typography.Text type="secondary">{blog.date}</Typography.Text>
<Typography.Text type="secondary">•</Typography.Text>
- <Typography.Text type="secondary">5 min read</Typography.Text>
+ <Typography.Text type="secondary">{blog.readingTime}</Typography.Text>
</Space>
<Space direction="vertical" size={3}>
@@ -155,7 +153,7 @@ function BlogListItem(blog: any) {
// console.log(blog.content.substring(0, 120))
return (
<div key={blog.id} className="py-4 border-b border-gray-100 dark:border-gray-600 mb-8">
- <div className=" mx-auto max-w-7xl">
+ <div className="mx-auto max-w-7xl cursor-pointer">
<Link href={`/blog/${blog.slug}`} as={`/blog/${blog.slug}`}>
<div>
<Space direction="vertical" size={5} className="">
@@ -163,7 +161,7 @@ function BlogListItem(blog: any) {
<Space className="mb-2">
<Typography.Text type="secondary">{blog.date}</Typography.Text>
<Typography.Text type="secondary">•</Typography.Text>
- <Typography.Text type="secondary">5 min read</Typography.Text>
+ <Typography.Text type="secondary">{blog.readingTime}</Typography.Text>
</Space>
<Space direction="vertical" size={3}>
diff --git a/www/pages/blog/[slug].module.css b/www/pages/blog/[slug].module.css
index f3ae82ec426..67fe51f6dec 100644
--- a/www/pages/blog/[slug].module.css
+++ b/www/pages/blog/[slug].module.css
@@ -49,3 +49,15 @@
.header svg:hover {
display: inline-block;
}
+
+.article h1,
+.article h2,
+.article h3,
+.article h4,
+.article h5 {
+ font-weight: 500 !important;
+}
+
+.article {
+ @apply mb-16;
+}
diff --git a/www/pages/blog/[slug].tsx b/www/pages/blog/[slug].tsx
index be5aa1f60c1..a4d7ca04231 100644
--- a/www/pages/blog/[slug].tsx
+++ b/www/pages/blog/[slug].tsx
@@ -1,113 +1,154 @@
// file: pages/blog/[slug].js
import React from 'react'
-import { IconFile, IconLink, Space, Typography } from '@supabase/ui'
-import ReactMarkdown from 'react-markdown'
import DefaultLayout from '~/components/Layouts/Default'
-import authors from 'lib/authors.json'
-import blogStyles from './[slug].module.css'
+import { NextSeo } from 'next-seo'
-import CodeBlock from '~/components/CodeBlock/CodeBlock'
import { getAllPostSlugs, getPostdata, getSortedPosts } from '~/lib/posts'
-
+import { generateReadingTime } from '~/lib/helpers'
+import ReactMarkdown from 'react-markdown'
+import authors from 'lib/authors.json'
import matter from 'gray-matter'
-
import renderToString from 'next-mdx-remote/render-to-string'
import hydrate from 'next-mdx-remote/hydrate'
-import Badge from '~/components/Badge'
+import { IconFile, IconLink, Space, Typography, Badge } from '@supabase/ui'
+import CodeBlock from '~/components/CodeBlock/CodeBlock'
+
+import blogStyles from './[slug].module.css'
+
+// import all components used in blog articles here
+// for instance, if you use a button, you must add `Button` in the components object below.
const components = { CodeBlock }
+// plugins for next-mdx-remote
const gfm = require('remark-gfm')
-const toc = require('markdown-toc')
const slug = require('rehype-slug')
+// table of contents extractor
+const toc = require('markdown-toc')
+
function BlogPostPage(props: any) {
// @ts-ignore
const author = props.blog.author ? authors[props.blog.author] : authors['supabase']
const content = hydrate(props.blog.content, { components })
return (
- <DefaultLayout>
- <div className="bg-white dark:bg-dark-700 overflow-hidden py-12">
- <div className="container px-8 sm:px-16 xl:px-20 mt-16 mx-auto">
- <div className="max-w-6xl mx-auto">
- <div className="py-12 grid grid-cols-12 gap-16">
- <div className="col-span-10">
- <Space className="mb-4">
- <Typography.Text type="secondary">{props.blog.date}</Typography.Text>
- <Typography.Text type="secondary">•</Typography.Text>
- <Typography.Text type="secondary">5 min read</Typography.Text>
- </Space>
- <Typography.Title>{props.blog.title}</Typography.Title>
- {author && (
- <div className="mt-6">
- <Space size={4}>
- {author.author_image_url && (
- <img src={author.author_image_url} className="rounded-full w-10" />
- )}
- <Space direction="vertical" size={0}>
- <Typography.Text>{author.author}</Typography.Text>
- <Typography.Text type="secondary" small>
- {author.position}
- </Typography.Text>
+ <>
+ <NextSeo
+ title={props.blog.title}
+ openGraph={{
+ title: props.blog.title,
+ description: 'Description of open graph article',
+ url: `https://supabase.io/blog/${props.blog.slug}`,
+ type: 'article',
+ article: {
+ //
+ // to do: add expiration and modified dates
+ // https://github.com/garmeeh/next-seo#article
+ publishedTime: props.blog.date,
+ //
+ // to do: author urls should be internal in future
+ // currently we have external links to github profiles
+ authors: [props.blog.author_url],
+ tags: props.blog.tags.map((cat: string) => {
+ return cat
+ }),
+ },
+ images: [
+ {
+ url: `https://supabase.io/new/images/blog/${
+ props.blog.thumb ? props.blog.thumb : props.blog.image
+ }`,
+ },
+ ],
+ }}
+ />
+ <DefaultLayout>
+ <div className="bg-white dark:bg-dark-700 overflow-hidden py-12">
+ <div className="container px-8 sm:px-16 xl:px-20 mt-16 mx-auto">
+ <div className="max-w-6xl mx-auto">
+ <div className="py-12 grid grid-cols-12 gap-16">
+ <div className="col-span-10">
+ <Space className="mb-4">
+ <Typography.Text type="secondary">{props.blog.date}</Typography.Text>
+ <Typography.Text type="secondary">•</Typography.Text>
+ <Typography.Text type="secondary">
+ {generateReadingTime(props.blog.content.renderedOutput)}
+ </Typography.Text>
+ </Space>
+ <Typography.Title>{props.blog.title}</Typography.Title>
+ {author && (
+ <div className="mt-6">
+ <Space size={4}>
+ {author.author_image_url && (
+ <img src={author.author_image_url} className="rounded-full w-10" />
+ )}
+ <Space direction="vertical" size={0}>
+ <Typography.Text>{author.author}</Typography.Text>
+ <Typography.Text type="secondary" small>
+ {author.position}
+ </Typography.Text>
+ </Space>
</Space>
- </Space>
- </div>
- )}
+ </div>
+ )}
+ </div>
</div>
</div>
</div>
</div>
- </div>
- <div className="container px-8 sm:px-16 xl:px-20 mt-16 mx-auto">
- <div className="max-w-6xl mx-auto">
- <div className="py-4 grid grid-cols-12 gap-16">
- <div className="col-span-8">
- {props.blog.thumb && (
- <img
- src={'/new/images/blog/' + props.blog.thumb}
- className="object-cover -mt-32 mb-8"
- style={{ maxHeight: '520px', width: '100%' }}
- />
- )}
- <Typography>{content}</Typography>
- </div>
- <div className="col-span-4">
- <Space direction="vertical" size={8}>
- <Space>
- {props.blog.tags.map((tag: string) => {
- return <Badge>{tag}</Badge>
- })}
- </Space>
- <div>
- <Typography.Title level={5}>Table of contents</Typography.Title>
- <Typography>
- <div className={blogStyles['toc']}>
- <ReactMarkdown plugins={[gfm]}>{props.blog.toc.content}</ReactMarkdown>
- </div>
- </Typography>
- </div>
- <div>
- <Typography.Title className="mb-4" level={5}>
- Related articles
- </Typography.Title>
- <Space direction="vertical">
- {props.relatedPosts.map((post: any) => (
- <Typography.Text>
- <Space>
- <IconFile size={'small'} style={{ minWidth: '1.2rem' }} />
- <span>{post.title}</span>
- </Space>
- </Typography.Text>
- ))}
+ <div className="container px-8 sm:px-16 xl:px-20 mt-16 mx-auto">
+ <div className="max-w-6xl mx-auto">
+ <div className="py-4 grid grid-cols-12 gap-16">
+ <div className="col-span-8">
+ {props.blog.thumb && (
+ <img
+ src={'/new/images/blog/' + props.blog.thumb}
+ className="object-cover -mt-32 mb-8"
+ style={{ maxHeight: '520px', width: '100%' }}
+ />
+ )}
+ <article className={blogStyles['article']}>
+ <Typography>{content}</Typography>
+ </article>
+ </div>
+ <div className="col-span-4">
+ <Space direction="vertical" size={8}>
+ <Space>
+ {props.blog.tags.map((tag: string) => {
+ return <Badge key={`categroy-badge-${tag}`}>{tag}</Badge>
+ })}
</Space>
- </div>
- </Space>
+ <div>
+ <Typography.Title level={5}>Table of contents</Typography.Title>
+ <Typography>
+ <div className={blogStyles['toc']}>
+ <ReactMarkdown plugins={[gfm]}>{props.blog.toc.content}</ReactMarkdown>
+ </div>
+ </Typography>
+ </div>
+ <div>
+ <Typography.Title className="mb-4" level={5}>
+ Related articles
+ </Typography.Title>
+ <Space direction="vertical">
+ {props.relatedPosts.map((post: any) => (
+ <Typography.Text>
+ <Space>
+ <IconFile size={'small'} style={{ minWidth: '1.2rem' }} />
+ <span>{post.title}</span>
+ </Space>
+ </Typography.Text>
+ ))}
+ </Space>
+ </div>
+ </Space>
+ </div>
</div>
</div>
</div>
- </div>
- </DefaultLayout>
+ </DefaultLayout>
+ </>
)
}
@@ -138,6 +179,7 @@ export async function getStaticProps({ params }: any) {
props: {
relatedPosts,
blog: {
+ slug: params.slug,
content: mdxSource,
...data,
toc: toc(content),