Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

challenge solved #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
282 changes: 280 additions & 2 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
"dependencies": {
"@mapbox/rehype-prism": "^0.8.0",
"@netlify/plugin-nextjs": "4.14",
"@supabase/supabase-js": "^2.45.2",
"@tailwindcss/typography": "^0.5.0",
"axios": "^0.27.2",
"axios": "^1.7.5",
"classnames": "^2.3.1",
"cypress": "^10.1.0",
"gray-matter": "^4.0.2",
Expand Down
73 changes: 73 additions & 0 deletions posts/[id].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { getGlobalData } from '../utils/global-data';
import {
getPostBySlug,
} from '../utils/mdx-utils';

import { MDXRemote } from 'next-mdx-remote';
import Head from 'next/head';
import Link from 'next/link';
import ArrowIcon from '../components/ArrowIcon';
import CustomLink from '../components/CustomLink';
import Footer from '../components/Footer';
import Header from '../components/Header';
import Layout, { GradientBackground } from '../components/Layout';
import SEO from '../components/SEO';


const components = {
a: CustomLink,
Head,
};

export default function PostPage({
posts,
globalData,
}) {
return (
<Layout>
<SEO
title={`${posts.title} - ${globalData.name}`}
description={posts.description}
/>
<Header name={globalData.name} />
<article className="px-6 md:px-0">
<header>
<h1 className="text-3xl md:text-5xl dark:text-white text-center mb-12">
{posts?.title}
</h1>
{posts?.description && (
<p className="text-xl mb-4">{posts?.description}</p>
)}
</header>
<main>
<article className="prose dark:prose-dark">
{posts.body}
</article>
</main>
</article>
<Footer copyrightText={globalData.footerText} />
<GradientBackground
variant="large"
className="absolute -top-32 opacity-30 dark:opacity-50"
/>
<GradientBackground
variant="small"
className="absolute bottom-0 opacity-20 dark:opacity-10"
/>
</Layout>
);
}

export const getServerSideProps = async ({ params }) => {
const globalData = getGlobalData();
const posts = await getPostBySlug(params.id);


return {
props: {
globalData,
posts,
},
};
};

6 changes: 3 additions & 3 deletions services/api.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import axios from 'axios';

export const api = axios.create({
baseURL: 'https://nuareafrukmnjnaakplk.supabase.co/rest/v1',
baseURL: 'https://ejhicwomoulkriutmhwi.supabase.co/rest/v1',
headers: {
apikey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im51YXJlYWZydWttbmpuYWFrcGxrIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NjAyMjc0MjEsImV4cCI6MTk3NTgwMzQyMX0.3qUEldVsmcr_yrpf8N1-qBGdHLB1QCy9nB6-nApVQIA",
authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im51YXJlYWZydWttbmpuYWFrcGxrIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NjAyMjc0MjEsImV4cCI6MTk3NTgwMzQyMX0.3qUEldVsmcr_yrpf8N1-qBGdHLB1QCy9nB6-nApVQIA"
apikey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImVqaGljd29tb3Vsa3JpdXRtaHdpIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjQ4Njg3MjEsImV4cCI6MjA0MDQ0NDcyMX0.8YbNKmYMj_obqE9m6yBaoPw6mJ0nHqWfG5M3PT0mX0U",
authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImVqaGljd29tb3Vsa3JpdXRtaHdpIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjQ4Njg3MjEsImV4cCI6MjA0MDQ0NDcyMX0.8YbNKmYMj_obqE9m6yBaoPw6mJ0nHqWfG5M3PT0mX0U"
}
})
4 changes: 2 additions & 2 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
mode: 'jit',
content: [
'./pages/**/*.{js,ts,jsx,tsx}',
'./components/**/*.{js,ts,jsx,tsx}',
'./src/pages/**/*.{js,ts,jsx,tsx}',
'./src/components/**/*.{js,ts,jsx,tsx}',
],
darkMode: 'class', // or 'media' or 'class'
presets: [require('./utils/tailwind-preset')],
Expand Down
28 changes: 19 additions & 9 deletions utils/mdx-utils.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { api } from '../services/api'
import supabase from '../utils/supabase'; // Ajuste o caminho conforme necessário

export const getPosts = async () => {
const {data} = await api.get('/posts');
const { data, error } = await supabase
.from('posts')
.select('*');

if(data){
return data;
if (error) {
console.error('Error fetching posts:', error);
return [];
}

return []
return data;
}

export const getPostBySlug = async (id) => {
const { data, error } = await supabase
.from('posts')
.select('*')
.eq('id', id)
.single();

//TODO: BUSCAR UM POST EM ESPECIFICO.
//const {data} = await api.get(`/post?id=eq.${id}`)
if (error) {
console.error('Error fetching post:', error);
return {};
}

return {}
}
return data;
}
8 changes: 8 additions & 0 deletions utils/supabase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// utils/supabase.js
import { createClient } from '@supabase/supabase-js';

const supabaseUrl = 'https://ejhicwomoulkriutmhwi.supabase.co'; // Substitua pelo URL do seu Supabase
const supabaseKey = 'your-supabase-key'; // Substitua pela sua chave API
const supabase = createClient(supabaseUrl, supabaseKey);

export default supabase;
Loading