One brick at a time contributing to the DKIW pyramid fundation


categories: i d e a

Authors: Oberron , Rezpe , Rezpe & Oberron , sebas ,

Notion to .md

  1. a simple gist to convert notion pages to markdown

  1. a simple github action clones the gist and uses it to create markdown files

source: frenchtouch/.github/workflows/notion2pelican.yml

name: Notion2Pelican
# Controls when the workflow will run
  # Allows you to run this workflow manually from the Actions tab
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
  # This workflow contains a single job called "build"
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
    # Steps represent a sequence of tasks that will be executed as part of the job
    environment: env  # THIS WAS MISSING
      - name: Checkout website source
        id: checkout-master
        uses: actions/checkout@v3
      - name : setup notion key
        env: # Or as an environment variable
          NOTIONKEY: ${{ secrets.NOTIONKEY }}
        run: python

a wrapper file


import subprocess
from os import environ

gist = "28939ddb1fd4ea4721475cf2edf474e8"
gist_url = f"{gist}.git"
output =["git", "clone", gist_url])
if not output==0:
  print(f"gist error code: {output}")
output =["mv",f"{gist}/","./"])
if not output==0:
  print(f"mv error code: {output}")

from notion2md import readDatabase, process_page_results
from notion2md import get_notion_headers, pageid_2_md

# notion db id for is:
FT_dbid = 'af9dd2942ef74d7c9faf32e694055a7e'
# get the GitHub secret which has the Notion Key
my_secret = environ.get("NOTIONKEY")
headers = get_notion_headers(my_secret)
res = readDatabase(databaseId=FT_dbid, notion_headers=headers)
res2 = process_page_results(res, headers)

res_t = readDatabase(databaseId=res2["page_children_ids"][1], notion_headers=headers)
md = pageid_2_md(res_t, headers)