Skip to content

Commit

Permalink
feat: use notion as a headless cms to display dynamic bio
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrTamer23 committed Sep 6, 2024
1 parent d882c78 commit 1c4d602
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 6 deletions.
Binary file added bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@emailjs/browser": "^3.12.1",
"@iconify/json": "^2.2.218",
"@iconify/tailwind": "^1.1.1",
"@notionhq/client": "^2.2.15",
"@onboardbase/nudgeer-safe": "^0.2.1",
"@vee-validate/zod": "^4.13.1",
"@vueuse/core": "^10.10.1",
Expand Down
47 changes: 41 additions & 6 deletions src/components/Home.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
---
import { Image } from "astro:assets";
import { Client } from "@notionhq/client";
import { sequence } from "astro:middleware";
const notion = new Client({
auth: import.meta.env.NOTION_API_KEY,
});
let title: string = `
I'm a Software Engineer focused on Frontend, AWS Certified Cloud Practitioner and a Computer Science student who is always eager to learn and explore, I've worked with C++, JavaScript, TypeScript, React, Nextjs, Vue, Nuxtjs, Astro, Docker, Node.js, Express.js, Prisma and PostgreSQL.
`;
try {
const response = await fetch(
"https://api.notion.com/v1/pages/0d32acfc4b91411b8b7976be5a9c78a1",
{
headers: {
Authorization: `Bearer ${import.meta.env.NOTION_API_KEY}`,
"Notion-Version": "2022-06-28",
},
}
);
const data = await response.json();
if (
data.properties &&
data.properties.title &&
data.properties.title.title &&
data.properties.title.title[0] &&
data.properties.title.title[0].text
) {
title = data.properties.title.title[0].text.content;
} else {
console.error("Unexpected data structure:", data);
}
} catch (error) {
console.error("Error fetching Notion data:", error);
}
---

<main class="flex select-none flex-col *:mx-auto">
<section class="container flex flex-col gap-4">
<section class="container flex flex-col gap-4 lg:!max-w-5xl">
<div class="flex flex-col-reverse items-center justify-between gap-4">
<div class="flex flex-col items-center">
<h1 class="text-lg font-bold">Amr Tamer</h1>
Expand All @@ -19,11 +56,9 @@ import { Image } from "astro:assets";
height={200}
/>
</div>
<div class="space-y-4 *:text-base [&_span]:block">
<p>
I'm a software engineer focused on Frontend and a computer science
student who is always eager to learn and explore, I've worked with C++,
JavaScript, TypeScript, React, Nextjs, Vue, Nuxtjs, Astro and Docker.
<div class="w-full space-y-4 *:text-base [&_span]:block">
<p id="bio">
{title}
</p>
<div class="leading-[3rem]">
You can <a
Expand Down
1 change: 1 addition & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" />
50 changes: 50 additions & 0 deletions src/lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,53 @@ type Work = {
description: string;
skills: string;
};

interface NotionUser {
object: "user";
id: string;
}

interface NotionTitle {
type: "text";
text: {
content: string;
link: null | string;
};
annotations: {
bold: boolean;
italic: boolean;
strikethrough: boolean;
underline: boolean;
code: boolean;
color: string;
};
plain_text: string;
href: null | string;
}

interface NotionPage {
object: "page";
id: string;
created_time: string;
last_edited_time: string;
created_by: NotionUser;
last_edited_by: NotionUser;
cover: null | any; // You can define a more specific type if needed
icon: null | any; // You can define a more specific type if needed
parent: {
type: "workspace";
workspace: boolean;
};
archived: boolean;
in_trash: boolean;
properties: {
title: {
id: string;
type: "title";
title: NotionTitle[];
};
};
url: string;
public_url: string;
request_id: string;
}

0 comments on commit 1c4d602

Please sign in to comment.