The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore: update Posts to contain url with correct /YYYY/MM/DD/ structure
Jonathan Summers-Muir715f8e5a6ff5
diff --git a/www/lib/posts.tsx b/www/lib/posts.tsxindex ab257d4a3e2..5a2068b9314 100644--- a/www/lib/posts.tsx+++ b/www/lib/posts.tsx@@ -3,6 +3,10 @@ import path from 'path'import matter from 'gray-matter'import { generateReadingTime } from './helpers'+// substring amount for file names+// based on YYYY-MM-DD format+const FILENAME_SUBSTRING = 11+//Finding directory named "blog" from the current working directory of Node.const postDirectory = path.join(process.cwd(), '_blog')@@ -24,11 +28,17 @@ export const getSortedPosts = (limit?: number, tags?: any) => {const formattedDate = new Date(data.date).toLocaleDateString('en-IN', options)const readingTime = generateReadingTime(content)+ const dates = getDatesFromFileName(filename)++ // construct url to link to blog posts+ // based on datestamp in file name+ const url = `${dates.year}/${dates.month}/${dates.day}/${slug.substring(FILENAME_SUBSTRING)}`const frontmatter = {...data,date: formattedDate,readingTime,+ url: url,}return {slug,@@ -56,28 +66,21 @@ export const getSortedPosts = (limit?: number, tags?: any) => {return allPostsData}-//Get Slugs+// Get Slugsexport const getAllPostSlugs = () => {const fileNames = fs.readdirSync(postDirectory)return fileNames.map((filename) => {- // extract YYYY, MM, DD from post name- const year = filename.substring(0, 4)- const month = filename.substring(5, 7)- const day = filename.substring(8, 10)-return {params: {- slug: filename.replace('.mdx', '').substring(11),- year,- month,- day,+ slug: filename.replace('.mdx', '').substring(FILENAME_SUBSTRING),+ ...getDatesFromFileName(filename),},}})}-//Get Post based on Slug+// Get Post based on Slugexport const getPostdata = async (slug: string) => {const fullPath = path.join(postDirectory, `${slug}.mdx`)const postContent = fs.readFileSync(fullPath, 'utf8')@@ -98,3 +101,16 @@ export const getAllCategories = () => {return categories}++const getDatesFromFileName = (filename: string) => {+ // extract YYYY, MM, DD from post name+ const year = filename.substring(0, 4)+ const month = filename.substring(5, 7)+ const day = filename.substring(8, 10)++ return {+ year,+ month,+ day,+ }+}diff --git a/www/pages/blog.tsx b/www/pages/blog.tsxindex 5a5cd6e2324..46ede8cb95c 100644--- a/www/pages/blog.tsx+++ b/www/pages/blog.tsx@@ -12,6 +12,7 @@ import authors from 'lib/authors.json'import DefaultLayout from '~/components/Layouts/Default'import { Typography, Badge, Space, Select } from '@supabase/ui'+import PostTypes from '~/types/post'export async function getStaticProps() {const allPostsData = getSortedPosts()@@ -119,13 +120,14 @@ function Blog(props: any) {)}-function FeaturedThumb(blog: any) {+function FeaturedThumb(blog: PostTypes) {+ console.log(blog)// @ts-ignoreconst author = blog.author ? authors[blog.author] : authors['supabase']return (<div key={blog.slug} className="my-6 cursor-pointer">- <Link href={`/blog/${blog.slug}`} as={`/blog/${blog.slug}`}>+ <Link href={`/blog/${blog.url}`} as={`/blog/${blog.url}`}><div><imgclassName="h-96 w-full object-cover"@@ -177,7 +179,7 @@ function FeaturedThumb(blog: any) {)}-function BlogListItem(blog: any) {+function BlogListItem(blog: PostTypes) {// @ts-ignoreconst author = blog.author ? authors[blog.author] : authors['supabase']@@ -185,7 +187,7 @@ function BlogListItem(blog: any) {return (<div key={blog.slug} className="pt-4 pb-12 border-b border-gray-100 dark:border-gray-600 mb-8"><div className="mx-auto max-w-7xl cursor-pointer">- <Link href={`/blog/${blog.slug}`} as={`/blog/${blog.slug}`}>+ <Link href={`/blog/${blog.url}`} as={`/blog/${blog.url}`}><div><Space direction="vertical" size={5} className=""><div>diff --git a/www/pages/blog/[year]/[month]/[day]/[slug].tsx b/www/pages/blog/[year]/[month]/[day]/[slug].tsxindex 5a40d2cae64..9d9598a0b8e 100644--- a/www/pages/blog/[year]/[month]/[day]/[slug].tsx+++ b/www/pages/blog/[year]/[month]/[day]/[slug].tsx@@ -109,7 +109,7 @@ function BlogPostPage(props: any) {const NextCard = (props: any) => {const { post, label, className } = propsreturn (- <Link href={post.slug} as={post.slug}>+ <Link href={`/blog/${post.url}`} as={`/blog/${post.url}`}><div className={className}><Card className="cursor-pointer" hoverable><Space direction="vertical">@@ -251,7 +251,7 @@ function BlogPostPage(props: any) {</Typography.Title><Space direction="vertical">{props.relatedPosts.map((post: any) => (- <Link href={`/blog/${post.slug}`} as={`/blog/${post.slug}`}>+ <Link href={`/blog/${post.url}`} as={`/blog/${post.url}`}><div><Typography.Text className="cursor-pointer"><Space>diff --git a/www/types/post.ts b/www/types/post.tsindex a5f7bb91dd1..78dc49a16bd 100644--- a/www/types/post.ts+++ b/www/types/post.ts@@ -1,6 +1,6 @@import Author from './author'-type PostType = {+type PostTypes = {slug: stringtitle: stringdate: string@@ -11,6 +11,11 @@ type PostType = {url: string}content: string+ thumb: string+ image: string+ readingTime: string+ url: string+ tags: []}-export default PostType+export default PostTypes