inspired by notion-exporter
hugo <- notion, get formatted hugo post markdown from notion by slug.
- Create a integration copy the
Internal Integration Token, then share your target database to this integration, reference official guildes. - Copy
token_v2from Cookie, reference this. - Duplicate
.env.examplename to.envand configure it. - Install Deno reference https://deno.land/manual/getting_started/installation .
- Run script use Deno.
❯ deno run --allow-net --allow-read --allow-write hution.ts post-title-slug
slug:post-title-slug
title: Post title
date: 2022-01-08T02:37:00.000Z
categories:category-1
tag:tag1
creating export task ...
task created with id: f7f65c5b-0c87-436c-b522-79b34a4650e8
try to fetch export task ...
reading markdown file in zip file
Post title written to /Users/yuhang/codes/blog/content/posts/post-title-slug.md
written markdown's format as follow:
---
title: Post title
date: 2022-01-08T02:37:00.000Z
tags: ["tag1"]
categories: ["category-1"]
---
Content for postthen you only focus on your hugo blog publish workflow.
NOTION_TOKEN=your-notion-api-token
TOKEN_V2=your-token_v2-in-cookie
DRAFTS_DATABASE_ID=database-id
OUT=/repos/blog/content/posts
NOTION_TOKEN: find target page/blockDRAFTS_DATABASE_ID: specify database which to save post drafts.TOKEN_V2: access official inner api to export page to markdown.OUT: blog posts root directory.
Assume there is a database named "Post Drafts", specify it's id to .env, "Post Drafts" has several pages in follow structure:
titlerequiredcreated timerequiredTagsmulti select property requiredCategoriesmulti select property requiredSlugtext property required
git clone https://github.com/yuhangch/hution.git
cd hution
deno run --allow-net --allow-read --allow-write hution.ts post-slugor specify a sub folder, markdown will written to $OUT/category-1
deno run --allow-net --allow-read --allow-write hution.ts post-slug category-1or use online script
deno run --allow-net --allow-read --allow-write https://raw.githubusercontent.com/yuhangch/hution/master/hution.ts post-slugor use cdn https://cdn.jsdelivr.net/gh/yuhangch/hution@master/hution.ts
or compile script as a executable file, reference this.
This script only test by simple content (plain text, numbered list, etc...), in complex cases requires further testing, below is a description of the stability from notion-exporter, it also applies to hution.
This tool completely relies on the export/download feature of the official but internal Notion.so API. The advantage is, that we do not generate any markup ourselves, just download and extract some ZIPs. While the download feature seems to be pretty stable, keep in mind that it still is an internal API, so it may break anytime.