Skip to content
Merged
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
7 changes: 7 additions & 0 deletions content/blog/don't-publish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Don’t publish
date: 2025-12-30T11:54:00.000Z
draft: true

---
undefined
22 changes: 22 additions & 0 deletions content/blog/example-page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: Example page
description: Description test
date: 2025-12-30T11:50:00.000Z
draft: false

---

## Test


This is an example of a post that I wrote using Notion. This way it’ll be easier to update my blog.


More complicated things

- list
- of
- items

Here’s a [link](https://patworld.world/)

65 changes: 65 additions & 0 deletions eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,73 @@ import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";

import pluginFilters from "./_config/filters.js";

import * as fs from 'fs';
import { Client } from '@notionhq/client';
import { NotionToMarkdown } from 'notion-to-md';
import slugify from 'slugify';
import * as YAML from 'yaml';

/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
export default async function(eleventyConfig) {

eleventyConfig.on("eleventy.beforeConfig", async ({ directories, runMode, outputMode }) => {
const database_id = process.env.NOTION_DATABASE_ID

if (!database_id || !process.env.NOTION_API_KEY) return

const notion = new Client({
auth: env.NOTION_API_KEY
});

const { data_sources } = await notion.databases.retrieve({
database_id,
});

const data_source_id = data_sources[0].id

const { results } = await notion.dataSources.query({
data_source_id,
})

const pageProperties = results.reduce((res, { id, properties }) => ({
...res,
[id]: {
title: properties["Name"].title[0]?.plain_text,
description: properties["Description"].rich_text[0]?.plain_text,
date: properties["Last edited time"]?.last_edited_time,
draft: !properties["Live"].checkbox,
}
}), {})

const block_ids = results.map(({ id }) => id)

// passing notion client to the option
const n2m = new NotionToMarkdown({
notionClient: notion,
});

await Promise.all(
block_ids.map(async (block_id) => {
const mdblocks = await n2m.pageToMarkdown(block_id);
const mdString = n2m.toMarkdownString(mdblocks);

const { title } = pageProperties[block_id];

const filename = `${slugify(title.toLowerCase())}.md`;

const frontmatter = "---\n"+ YAML.stringify(pageProperties[block_id]) + "\n---\n"

try {
fs.writeFileSync(`content/blog/${filename}`, frontmatter + mdString.parent)
} catch (e) {
console.log(`Writing ${filename} failed: ${e}`)
}

console.log(`Wrote ${filename} successfully.`)
})
)
})

// Drafts, see also _data/eleventyDataSchema.js
eleventyConfig.addPreprocessor("drafts", "*", (data, content) => {
if (data.draft) {
Expand Down
105 changes: 103 additions & 2 deletions package-lock.json

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

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
"zod-validation-error": "^3.5.2"
},
"dependencies": {
"@zachleat/heading-anchors": "^1.0.5"
"@zachleat/heading-anchors": "^1.0.5",
"@notionhq/client": "^5.6.0",
"markdown-it-footnote": "^4.0.0",
"notion-to-md": "^3.1.9",
"slugify": "^1.6.6",
"yaml": "^2.8.2"
}
}
Loading