### GitHub Actions Workflow for Notion Site Generation and Deployment Source: https://github.com/merkulovdaniil/notion4ever/blob/main/README.md This workflow automates the process of downloading content from a Notion page, generating a static site using notion4ever, and deploying it to GitHub Pages. It includes steps for setting up the environment, checking out repositories, installing dependencies, running the generation script, and deploying the output. The workflow is triggered on a schedule and can also be run manually via workflow_dispatch. ```yaml on: workflow_dispatch: 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: 'Merkulov Daniil/notion4ever' - name: Install packages run: pip install -r requirements.txt - name: Download current version of the site uses: actions/checkout@v2 with: repository: 'Merkulov Daniil/merkulovdaniil.github.io' ref: main path: _site - name: Run notion4ever run: python -m notion4ever env: SITE_URL: "https://merkulov.top" 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. ``` -------------------------------- ### Automated Deployment Workflow with GitHub Actions Source: https://context7.com/merkulovdaniil/notion4ever/llms.txt Automates the deployment of a Notion-generated static site to GitHub Pages. This workflow runs on a schedule or manually, checks out the Notion4ever repository, installs dependencies, downloads the existing site for incremental updates, runs Notion4ever to generate the site, and then deploys the output to GitHub Pages. ```yaml # .github/workflows/publish.yml name: Deploy from Notion to Pages on: schedule: - cron: "0 */12 * * *" # Run every 12 hours workflow_dispatch: # Manual trigger jobs: deploy: runs-on: ubuntu-latest steps: - name: Set up Python uses: actions/setup-python@v2 with: python-version: "3.10" - name: Download notion4ever uses: actions/checkout@v2 with: repository: 'MerkulovDaniil/notion4ever' - name: Install dependencies run: pip install -r requirements.txt - name: Download existing site (for incremental updates) uses: actions/checkout@v2 with: repository: '${{ github.repository_owner }}/my-site' ref: main path: _site - name: Run notion4ever run: python -m notion4ever env: SITE_URL: "https://mysite.github.io" NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }} NOTION_PAGE_ID: ${{ secrets.NOTION_PAGE_ID }} INCLUDE_FOOTER: "true" INCLUDE_SEARCH: "true" - name: Deploy to GitHub 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" ``` -------------------------------- ### Parse Notion Page with notion2json.notion_page_parser Source: https://context7.com/merkulovdaniil/notion4ever/llms.txt Recursively downloads all Notion pages, databases, and nested content starting from a root page ID using the Notion API. Saves raw Notion API responses incrementally to a JSON file for caching and offline processing. ```python from notion_client import Client from notion4ever import notion2json # Initialize Notion client with API token notion = Client(auth="secret_your_notion_token") # Storage for raw Notion data raw_notion = {} filename = "./notion_content.json" # Parse the root page and all nested content # This recursively fetches all child pages, databases, and blocks notion2json.notion_page_parser( page_id="12e3d1659a444678b4e2b6a989a3c625", notion=notion, filename=filename, notion_json=raw_notion ) # Result: raw_notion dict with page IDs as keys # { # "12e3d165-9a44-4678-b4e2-b6a989a3c625": { # "object": "page", # "id": "12e3d165-9a44-4678-b4e2-b6a989a3c625", # "properties": {...}, # "blocks": [ # {"type": "paragraph", "paragraph": {"text": [...]}}, # {"type": "child_page", "id": "89ae66ca-..."}, # ... # ] # }, # "89ae66ca-44a5-4819-9797-5bf321572676": {...} # } ``` -------------------------------- ### Generate Full Static Site with Python Source: https://context7.com/merkulovdaniil/notion4ever/llms.txt Orchestrates the entire static site build process. It verifies templates, compiles SASS, generates HTML pages from Notion data, creates archive and 404 pages, and copies fonts. Requires structured Notion data and a configuration dictionary. ```python from pathlib import Path from notion4ever import site_generation structured_notion = { "root_page_id": "page123", "base_url": "https://example.com", "include_footer": True, "include_search": True, "search_index": [], "sorted_id_by_year": {}, "pages": { "page123": { "type": "page", "title": "Home", "url": "https://example.com", "md_content": "# Welcome\n\nHello world", "cover": None, "icon": None, "emoji": "🏠", "parent": None, "children": [], "family_line": [], "last_edited_time": "2024-01-25T22:35:00.000Z" } } } config = { "output_dir": Path("./_site"), "templates_dir": "./_templates", "sass_dir": "./_sass", "site_url": "https://example.com", "build_locally": False } # Generate the complete static site site_generation.generate_site(structured_notion, config) # Output structure: # _site/ # index.html # Home page # 404.html # Error page # Archive/index.html # Archive page # search_index.json # Search index (if enabled) # css/ # main.css # Compiled SASS # fonts/ # Copied fonts # Home.md # Markdown source ``` -------------------------------- ### Run Notion4ever CLI Source: https://context7.com/merkulovdaniil/notion4ever/llms.txt Execute the Notion4ever command-line interface to export Notion content. Requires a Notion API token and page ID. Supports various configuration options for output directory, templates, site URL, and build behavior. ```bash # Basic usage with required parameters python -m notion4ever -n "secret_your_notion_token" -p "12e3d1659a444678b4e2b6a989a3c625" # Full usage with all configuration options python -m notion4ever \ --notion_token "secret_your_notion_token" \ --notion_page_id "12e3d1659a444678b4e2b6a989a3c625" \ --output_dir "./_site" \ --templates_dir "./_templates" \ --sass_dir "./_sass" \ --site_url "https://example.com" \ --build_locally False \ --download_files True \ --remove_before False \ --include_footer True \ --include_search True \ --logging_level INFO # Build for local preview (uses file:// paths) python -m notion4ever -n $NOTION_TOKEN -p $NOTION_PAGE_ID -bl True # Using environment variables (recommended for CI/CD) export NOTION_TOKEN="secret_your_notion_token" export NOTION_PAGE_ID="12e3d1659a444678b4e2b6a989a3c625" export SITE_URL="https://example.com" python -m notion4ever ``` -------------------------------- ### HTML Templating and Content Rendering in Notion4ever Source: https://github.com/merkulovdaniil/notion4ever/blob/main/_templates/page.html This snippet demonstrates the use of HTML includes and block templating within the Notion4ever project. It defines the structure for page headers, content, and footers, dynamically rendering elements based on page properties and types. It utilizes Jinja-like syntax for conditional logic and includes. ```html {% include '\_head.html' %} {% include '\_header.html' %} {% block page_header %} {% block page_title %} {{ page.title }} {% endblock page_title %} {% block page_date %} {% if page.date_end %} Dates: {{ page['date'].strftime("%d %b, %Y") }} - {{ page['date_end'].strftime("%d %b, %Y") }} {% elif page.date %} Date: {{ page['date'].strftime("%d %b, %Y") }} {% else %} Last edited: {{ page['last_edited_time'].strftime("%d %b, %Y") }} {% endif %} {% endblock page_date %} {% if page.type == 'db_entry' %} {% if page.properties_md|length > 1 %} {% block page_properties %} {% include '\_properties_table.html' %} {% endblock page_properties %} {% endif %} {% endif %} {% endblock page_header %} {% block page_content %} {% if 'db_list' in page.keys() %} {% include '\_list.html' %} {% elif page.type == 'database' %} {% include '\_gallery.html' %} {% else %} {{ content }} {% endif %} {% endblock page_content %} {% block footer %} {% if site["include_footer"] %} {% include '\_footer.html' %} {% endif %} {% endblock footer %} ``` -------------------------------- ### Jinja2 Template for Page Output Source: https://context7.com/merkulovdaniil/notion4ever/llms.txt This Jinja2 template defines the structure for individual content pages. It includes the head, header, footer, breadcrumb navigation, page cover, title, markdown content, and a section for child pages displayed as a list or gallery. It relies on partial templates like _head.html, _header.html, _footer.html, _list.html, and _gallery.html. ```html {% include "_head.html" %}
{% include "_header.html" %}