Notion4ever

repository·main·Indexed 41 days ago

https://github.com/merkulovdaniil/notion4ever

A Python-based tool that exports Notion pages into Markdown and HTML files via the official Notion API to create lightweight, responsive static websites. It features a three-step pipeline for data download, structuring via a modified notion2md library, and site generation using jinja templates and libsass-python.

Tokens
1.5K
Snippets
2
Records
4
Agent score
2%

What's inside Notion4ever

  1. How Notion4ever processes content

    main

    Notion4ever follows a three-step pipeline to transform Notion data into a static website:

    1. Data Download: Using the Notion token and Page ID, it downloads all content from the specified page and its nested subpages into a raw JSON file named notion_content.json.
    2. Structuring: It parses the raw JSON to create notion_structured.json. This file contains the markdown content of all pages and defines the relationships between them. It uses a modified version of the notion2md library for markdown parsing.
    3. Site Generation: It uses the structured content to render a site via jinja templates (found in ./_templates). Styles are managed in ./_sass and compiled using libsass-python. By default, the final static site is output to the ./_site directory.
  2. Configure Notion API access

    main

    Before using Notion4ever, you must prepare your Notion workspace:

    1. Get Page ID: Extract the ID from your Notion page URL. For example, in https://fmin.notion.site/Danya-Merkulov-12e3d1659a444678b4e2b6a989a3c625, the ID is 12e3d1659a444678b4e2b6a989a3c625.
    2. Create Integration: Go to Notion.so/my-integrations, create a new integration, and copy the Internal Integration Token (starts with secret_).
    3. Grant Access: In Notion, open the target page, go to Share -> invite, and select your integration name to allow it to access the page content.
  3. Run Notion4ever locally

    main

    To run Notion4ever on your local machine, clone or copy the repository and execute the module using the Python CLI. You must provide your Notion API token and the target Notion Page ID. Use the -bl flag to enable/disable certain behaviors (e.g., downloading images/files).

    python -m notion4ever -n NOTION_TOKEN -p NOTION_PAGE_ID -bl True
  4. Deploy Notion4ever automatically with GitHub Actions

    main

    You can automate the export of your Notion pages to a static site hosted on GitHub Pages.

    1. Set up Repository Secrets

    In your target GitHub repository, navigate to Settings -> Secrets -> Actions -> New repository secret and add:

    • NOTION_PAGE_ID: Your Notion page ID.
    • NOTION_TOKEN: Your Notion Internal Integration Token.

    2. Configure the Workflow

    Create a .github/workflows/publish.yml file in your repository. The workflow performs the following steps:

    1. Installs Google Chrome (required for certain rendering tasks).
    2. Sets up Python 3.10.
    3. Checks out the notion4ever repository.
    4. Installs dependencies via pip install -r requirements.txt.
    5. Checks out your static site repository to a specific path (e.g., _site).
    6. Runs python -m notion4ever using environment variables for configuration.
    7. Deploys the generated content to your main branch using JamesIves/github-pages-deploy-action.

    Note: You must set the SITE_URL environment variable in the workflow to your actual website URL (e.g., https://<username>.github.io).

    name: Deploy from Notion to Pages
    
    on:
      schedule:
        - cron: "0 */12 * * *" 
        
    jobs:
      download_old-generate-push:
        runs-on: ubuntu-latest
        
        steps:
          - name: Submodule Update
            run: |
              wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
              sudo apt install ./google-chrome-stable_current_amd64.deb
              sudo apt-get update
              
          - name: Set up Python
            uses: actions/setup-python@v2
            with:
              python-version: 3.10.0
              
          - name: Download notion4ever
            uses: actions/checkout@v2
            with:
              repository: 'MerkulovDaniil/notion4ever'
              
          - name: Install packages
            run: pip install -r requirements.txt
            
          - name: Download current version of the site
            uses: actions/checkout@v2
            with:
              repository: 'YOUR_REPOSITORY_HERE'
              ref: main
              path: _site
              
          - name: Run notion4ever
            run: python -m notion4ever
            env:
                SITE_URL: "https://your-site-url.com"
                NOTION_TOKEN: ${{secrets.NOTION_TOKEN}}
                NOTION_PAGE_ID: ${{secrets.NOTION_PAGE_ID}}
          
          - name: Deploy to Pages
            uses: JamesIves/github-pages-deploy-action@3.7.1
            with:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
              BRANCH: main
              FOLDER: _site
              COMMIT_MESSAGE: 🤖 Deployed via notion4ever.