Skip to main content

Converts Notion documents into Markdown format files compatbile with the Hugo framework.

Project description

Notion2Hugo

PyPI GitHub PyPI - Python Version

Export content written in Notion to markdown, compatible for Hugo blog.

You can use Notion as a CMS in order to author, edit, and manage all your content while leverage the power of Hugo in order to serve the content statically on your blog site. This lets you leverage the best of both worlds - powerful and expressive UX of Notion for authoring along with speed and pre-built feature rich themes for personal blog site.

The package ships with a script in order to export content from Notion in a compatible format.

$ pip3 install notion2hugo
$ publish_notion_to_hugo [-h] config_path

Demo

Demo Notion Page --> Hugo Markdown Output

Feel free to use the Demo Notion Page as a template for setting up your blogging Notion database.

Getting Started

Install the package using Pip:

$ pip3 install notion2hugo

Follow the steps below to get started:

  1. Follow the Notion developer guide in order to setup an Access Token and an Integration with at least "Read" access to the relevant database.
  2. Expose the access token and the database ID as environment variables in your shell.
    export NOTION_TOKEN='<your-access-token-here>'
    export NOTION_DATABASE_ID='<database-id-with-read-integration-setup>'
    
  3. Clone the src/notion2hugo/config.sample.toml file as config.toml and add in your custom settings. You can leverage the properties in your Notion database in order to determine the name of the published post.
  4. Run the script mentioned above and profit!
    $ publish_notion_to_hugo /path/to/config.toml
    

Note about output structure

Currently, the output markdown generated has the following directory structure:

  • {parent_dir}/ (provided in the config, cleared at the start of execution)
    • {post1_name}/ (provided in the config or defaults to the "Title" property auto populated for all posts)
      • images/ (contains all the image assets used in the post)
      • index.md (contains the exported post markdown content with an appropriately formatter front matter)
    • {post2_name}/
      • images/
      • index.md
    • ...

Note about index.md front matter

We export all the properties specified in the Notion database for the page to the front matter in the format shown below:

---
prop1: prop1_value
prop2: prop2_value
...
Title: 'Post title"
---

This is intended to mimic the front matter format as shown here. The full list of supported front matter variables is provided here - front matter variables.

The Notion database can be setup in order to have properties as supported by Hugo in order to easily export them and make the best use of the options available. For ex, you could have a property as:

  • "Draft" with a value of "false" or "true" and Hugo will correctly handle them as a draft post or a published post.-
  • Date property can be used to specify the post publish date.
  • Tags, Series...
  • On the flip side, if you'd like to have other arbitrary properties in your Notion database, you should prepend them with a # (eg, # Arbitrary Prop), so that they don't interfere with Hugo front matter format and don't result in an error.

Configuration

Here is the config.sample.toml:

#
# Copy this file to config.toml and update the field below
#

[provider_config]
## override the id here or defaults to NOTION_DATABASE_ID env
# database_id = "<notion_database_id>"
## specify filter here, refer to Notion API Dev resources for format
# filter = {property = "# Status", status = {equals = "Outline"}}
# filter = {property = "# Status", status = {does_not_equal = "Not Started"}}

[formatter_config]

[exporter_config]
parent_dir = "/tmp/notion2hugo_output_dir"
## specify page prop from Notion here or
## remove it in order use page id as dir
post_name_property_key = "Title" # 'Title' prop is added by default.

[runner_config]
exporter_config_cls = "notion2hugo.exporter.MarkdownExporterConfig"
formatter_config_cls = "notion2hugo.formatter.HugoFormatterConfig"
provider_config_cls = "notion2hugo.provider.NotionProviderConfig"

Supported Features

Exporting markdown for the following Notion features is supported:

  • Heading 1/2/3/Paragraphs
  • Text annotations - bold, italics, underline, etc.
  • Table (with markdown in cells)
  • Images (with captions)
  • Code (inline and block)
  • Mermaid diagrams
  • Blockquote
  • Math equations (both inline and block)
  • Text Highlight

Roadmap for future developement

Currently, the following Notion features are not supported for export and will be supported in future versions:

  • Checklist or TODOs
  • Callouts
  • Cross referencing pages in the database, that is, we'd like to update the URL appropriately to refer to the published post on the blog rather than to the notion page.
  • Gist, twitter or other embeds.

Contributions

Contributions are more than welcome! Please feel free to open an issue or a pull request for any bugs/feature request or any other improvements. Cheers!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

notion2hugo-0.2.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

notion2hugo-0.2.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file notion2hugo-0.2.0.tar.gz.

File metadata

  • Download URL: notion2hugo-0.2.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for notion2hugo-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8c91a0ee0aa1f65e520e529cc83c19f767e0ce665520d7125219b173d8376654
MD5 afe04ff457f3a56b033682781c111cde
BLAKE2b-256 812b779fc2d85ee18839635106b9915b0bd61f0303b6a5acac4e910dd8cedda8

See more details on using hashes here.

File details

Details for the file notion2hugo-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: notion2hugo-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for notion2hugo-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a5bde4992ecafdcbee115058b34306679e40b6aa514810b135c89f31542e804
MD5 c2e2216a817a9686e3dac8f97beab49f
BLAKE2b-256 660eefa0c0bb064db7ca5753bc881f67123aed9d3a958e865c5ffe23824d88f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page