Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sveltekit-notion-blog",
"version": "0.1.1",
"version": "0.1.3",
"scripts": {
"dev": "vite dev",
"build": "vite build && npm run package",
Expand Down
8 changes: 3 additions & 5 deletions src/lib/components/PostsList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
{#if data.pages}
<div class="min-h-screen bg-white py-8 flex flex-col gap-20 relative overflow-hidden lg:py-8">
<div class="relative w-full px-6 py-12 md:max-w-3xl md:mx-auto lg:max-w-4xl lg:pt-12 lg:pb-28">
<div class="flex flex-col gap-12 mb-8">
<h1 class="font-bold text-4xl">Welcome to StoreBud blog - Platform for growing D2C brands!</h1>
<div class="flex flex-col gap-6 mb-8">
<h1 class="font-bold text-4xl">{ data.settings.blogTitle }</h1>

<p class="text-lg">
StoreBud blogs cover variuos topics related to setting up your own ecommerce website in India and
other parts of the world, including tips and tricks, best practices and success stroies of the
growing D2C brands.
{ data.settings.blogDescription }
</p>
</div>

Expand Down
27 changes: 15 additions & 12 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ import BlogPost from "$lib/components/BlogPost.svelte";
import PostsList from "$lib/components/PostsList.svelte";

type Tokens = { notionToken: string, databaseId: string, vercelByPassToken?: string };
export type BlogClient = {client: Client, config: Tokens};
type BlogSettings = { blogTitle: string, blogDescription: string };
type InitConfig = { tokens: Tokens, settings: BlogSettings };
export type BlogClient = { client: Client, config: Tokens, settings: BlogSettings };

let notionCLient: BlogClient;

export const initNotion = ( config: Tokens ): BlogClient | null => {
if(config?.notionToken && config?.notionToken){
const client = new Client({
auth: config.notionToken,
});
notionCLient = { client, config};
return notionCLient;
}else{
return null;
}
export const initNotionBlog = ( config: InitConfig ): BlogClient | null => {
if(config?.tokens?.notionToken && config?.tokens?.notionToken){
const client = new Client({
auth: config.tokens.notionToken,
});
notionCLient = { client, config: config.tokens, settings: config.settings };
return notionCLient;
}else{
return null;
}
}

export const getAllPosts = async () => {
Expand All @@ -38,7 +40,8 @@ export const getAllPosts = async () => {
if(res.isOk()){
if(res.value?.length > 0){
return {
pages: res.value
pages: res.value,
settings: notionCLient.settings
}
}else{
return {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/notion/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BlogClient } from "$lib";
import type { FAQ } from "$lib/types";
import { Client, APIErrorCode, isNotionClientError, ClientErrorCode, isFullPage, isFullBlock } from "@notionhq/client";
import { APIErrorCode, isNotionClientError, ClientErrorCode, isFullPage, isFullBlock } from "@notionhq/client";
import type { BlockObjectResponse, PageObjectResponse, UserObjectResponse } from "@notionhq/client/build/src/api-endpoints";
import { ok, err, Result } from 'neverthrow';

Expand Down
14 changes: 10 additions & 4 deletions src/routes/+layout.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { PUBLIC_NOTION_TOKEN, PUBLIC_NOTION_DATABASE_ID } from "$env/static/public";
import { initNotion } from "$lib";
import { initNotionBlog } from "$lib";

export const prerender = true;

initNotion({
databaseId: PUBLIC_NOTION_DATABASE_ID,
notionToken: PUBLIC_NOTION_TOKEN,
initNotionBlog({
tokens: {
databaseId: PUBLIC_NOTION_DATABASE_ID,
notionToken: PUBLIC_NOTION_TOKEN,
},
settings: {
blogTitle: "Notion Blog",
blogDescription: "A blog powered by Notion"
}
});