Skip to content

Using Database as Remote file Source #540

Closed Answered by sagarchoudhary96
sagarchoudhary96 asked this question in Q&A
Discussion options

You must be logged in to vote

Can be done as below, the example below is with using supabase as db and reading from a posts table:

import { createClient } from '@supabase/supabase-js';
import { writeFile } from 'fs/promises';
import { join } from 'path';
import { defineDocumentType } from '@contentlayer/source-files';
import { makeSource } from '@contentlayer/source-remote-files';

// Initialize Supabase client
const supabase = createClient('YOUR_SUPABASE_URL', 'YOUR_ANON_KEY');

const Post = defineDocumentType(() => ({
  name: 'Post',
  filePathPattern: `posts/**/*.mdx`,
  fields: {
    title: { type: 'string', required: false },
    content: { type: 'string', required: false },
  },
}));

const syncContentFromSupaba…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sagarchoudhary96
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant