Skip to content

Get formatted hugo post markdown from notion by slug.

Notifications You must be signed in to change notification settings

yuhangch/hution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Hution

inspired by notion-exporter

hugo <- notion, get formatted hugo post markdown from notion by slug.

Use

  1. Create a integration copy the Internal Integration Token, then share your target database to this integration, reference official guildes.
  2. Copy token_v2 from Cookie, reference this.
  3. Duplicate .env.example name to .env and configure it.
  4. Install Deno reference https://deno.land/manual/getting_started/installation .
  5. 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 post

then you only focus on your hugo blog publish workflow.

.env

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/block
  • DRAFTS_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.

Expected page format

Assume there is a database named "Post Drafts", specify it's id to .env, "Post Drafts" has several pages in follow structure:

  • title required
  • created time required
  • Tags multi select property required
  • Categories multi select property required
  • Slug text property required

Run

git clone https://github.com/yuhangch/hution.git
cd hution
deno run --allow-net --allow-read --allow-write hution.ts post-slug

or specify a sub folder, markdown will written to $OUT/category-1

deno run --allow-net --allow-read --allow-write hution.ts post-slug category-1

or use online script

deno run --allow-net --allow-read --allow-write https://raw.githubusercontent.com/yuhangch/hution/master/hution.ts post-slug

or use cdn https://cdn.jsdelivr.net/gh/yuhangch/hution@master/hution.ts

or compile script as a executable file, reference this.

More

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.

About

Get formatted hugo post markdown from notion by slug.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published