Skip to content

Commit 7414c8e

Browse files
improved readme.md
1 parent c050fb2 commit 7414c8e

File tree

8 files changed

+705
-63
lines changed

8 files changed

+705
-63
lines changed

README.md

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,79 @@
1-
# create-svelte
1+
# Introduction
22

3-
Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
3+
This is a plug and play library for [`Sveltekit`](https://kit.svelte.dev/) projects to create blogs quickly in your website's subdirectory using [`Notion`](https://www.notion.so/) as a CMS.
44

5-
Read more about creating a library [in the docs](https://kit.svelte.dev/docs/packaging).
5+
## Getting started
66

7-
## Creating a project
7+
### Notion Setup
8+
1. Duplicate this [`Notion template`] into your workspace.
9+
2. Create an internal Notion connection from the settings [(Link)](https://www.notion.so/my-integrations), Notion's documentation on how to create an internal connection [(link)] (https://developers.notion.com/docs/create-a-notion-integration)
10+
3. Connect the newly created connection with the blogs template duplicated in step 1 by clicking on the 3 dots on top-right. Then click on **Add Connections** and search for the connection you created in the step 3. Done!
11+
4. New blogs will be added in the **Blogs** page of the template.
812

9-
If you're seeing this, you've probably already done this step. Congrats!
13+
### Initialize the library in the root +layout.ts
1014

1115
```bash
12-
# create a new project in the current directory
13-
npm create svelte@latest
16+
import { PUBLIC_NOTION_DATABASE_ID, PUBLIC_NOTION_TOKEN } from "$env/static/public";
17+
import { initNotion } from "sveltekit-notion-blog";
1418

15-
# create a new project in my-app
16-
npm create svelte@latest my-app
19+
export const prerender = true;
20+
21+
initNotion({
22+
databaseId: PUBLIC_NOTION_DATABASE_ID, //from .env
23+
notionToken: PUBLIC_NOTION_TOKEN, //from .env
24+
});
1725
```
1826
19-
## Developing
27+
### Code Setup
2028
21-
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
29+
1. Install the package
2230
2331
```bash
24-
npm run dev
25-
26-
# or start the server and open the app in a new browser tab
27-
npm run dev -- --open
32+
npm i sveltekit-notion-blog
2833
```
2934
30-
Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
31-
32-
## Building
33-
34-
To build your library:
35+
2. In your existing project, create a subdirectory names **blog** and create ```+page.svelte``` and ```+page.server.ts``` files in this directory and call the _getAllPosts_ method in the ```+page.server.ts```
3536
3637
```bash
37-
npm run package
38+
import type { PageServerLoad } from './$types';
39+
import { getAllPosts } from "sveltekit-notion-blog";
40+
export const load: PageServerLoad = () => getAllPosts();
3841
```
3942
40-
To create a production version of your showcase app:
43+
3. In the ```+page.svelte```, import the ```PostsList`` component
4144

4245
```bash
43-
npm run build
46+
<script lang="ts">
47+
import type { PageData } from './$types';
48+
import { PostsList } from "sveltekit-notion-blog";
49+
export let data: PageData;
50+
</script>
51+
52+
<div class="max-w-4xl m-auto">
53+
<PostsList {data} />
54+
</div>
4455
```
4556
46-
You can preview the production build with `npm run preview`.
57+
4. Create a new directory inside the blog directory named **[slug]** and create ```+page.svelte``` and ```+page.server.ts``` files in this directory.
4758
48-
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
59+
5. In the ```+page.server.ts``` call the **getBlogPageBySlug** method
4960
50-
## Publishing
61+
```bash
62+
import type { ServerLoadEvent } from '@sveltejs/kit';
63+
import { getBlogPageBySlug } from 'sveltekit-notion-blog';
5164
52-
Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
65+
export const load = (event: ServerLoadEvent) => getBlogPageBySlug(event);
66+
```
5367
54-
To publish your library to [npm](https://www.npmjs.com):
68+
6. In the ```+page.svelte```
5569
5670
```bash
57-
npm publish
71+
<script lang="ts">
72+
import { BlogPost } from 'sveltekit-notion-blog';
73+
import type { PageData } from './$types';
74+
75+
export let data: PageData;
76+
</script>
77+
78+
<BlogPost {data} />
5879
```

0 commit comments

Comments
 (0)