Skip to content
blank-orgPublic

About

Notion based CMD for the Cutie framework

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

31 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NCMS Fetch Script

This script is responsible for fetching content from a Notion database, transforming it, and generating the necessary files for the "Cutie" PHP framework.

Role

This script acts as the bridge between Notion (as a headless CMS) and the static site generator. It automates the content pipeline, ensuring that changes made in Notion are reflected on the website.

Setup

  1. Install Dependencies: This project uses Python. Install the required packages using pip:

    pip install -r requirements.txt
  2. Configure Environment Variables: Create a .env file in this directory by copying the .env.template. Fill in the following values:

    • NOTION_API_KEY: Your Notion API integration key.
    • NOTION_DATABASE_ID: The ID of the Notion database you are fetching content from.
    • OUTPUT_DIR: The absolute path to the directory where the generated PHP component files will be saved. This typically corresponds to the HTML/Component directory in your "Cutie" framework project.
    • PROJECT_DIR: The absolute path to the root of the website project. This is used for placing project-level files like firebase.json and sitemap.xml and for running git commands.

Operation

To run the script and fetch the latest content from Notion, execute the following command:

python ncms_fetch.py

The script will perform the following actions:

  1. Connect to the Notion API using your key.
  2. Query the specified database for pages with a "Status" of "publish".
  3. Process the content of each page, transforming Notion blocks into PHP/HTML.
  4. Generate and place the PHP files into the OUTPUT_DIR.
  5. Generate/update configuration files (ID.tsv, Url.tsv, firebase.json, sitemap.xml) and place them in the appropriate locations within the PROJECT_DIR and OUTPUT_DIR.
  6. Commit the changes to the git repository located at PROJECT_DIR and push them to the publish branch.
  7. If the git push is successful, the script will update the status of the fetched Notion pages to "published".

Directory Roles

  • output/ (defined by OUTPUT_DIR): This is the destination for the dynamically generated PHP files that represent the content from Notion (e.g., individual articles, pages). It also contains generated configuration files like ID.tsv, Url.tsv, and sitemap.xml.
  • project/ (defined by PROJECT_DIR): This path points to the root of the target website project. The script places high-level configuration files like firebase.json here. It is also the working directory for git operations.

Notion Database Properties

Each page in the Notion database requires these properties:

Property Type Description
Id Title The URL slug/path (e.g. world/philosophy/life)
Status Select Set to publish to trigger generation, becomes published after
Label Rich text Navigation label text
Title Rich text Page title
JS Select 0 or 1 — loads page.js if 1
Description Rich text Page description for meta tags

Nested translations

The database contains exactly one canonical row per article slug. English content and all shared properties stay on that base page. Do not add Language or TranslationGroup database properties, and do not create a separate database row for a translation.

Create each translation as a direct child page inside the canonical article. Name it (), for example हिन्दी (hi). Its first block must be a 🌐 callout with one field per line:

Language: hi
Label: छोटा नेविगेशन लेबल
Title: स्थानीयकृत पृष्ठ शीर्षक
Description: स्थानीयकृत मेटा विवरण

The remaining child-page blocks are the translated article body. Language, Label, Title, and Description are publication metadata and the 🌐 callout is not rendered as body content.

Queue only the canonical database row by setting its status to publish. NCMS discovers all recognized translation child pages and emits the English base plus every translation in one bundle. The publisher must deploy and verify that bundle atomically; a malformed translation causes the whole publication to fail.

To publish one language only, pass a language-prefixed public slug such as --slug hi/world/philosophy/hindu. NCMS still selects the canonical Notion page by its unprefixed Id, then emits only that language's variant. The publisher merges the translation into Translations.tsv without clearing other languages.

Block Type Mapping

Standard Notion Blocks

These Notion blocks map directly to HTML output:

Notion Block HTML Output
Paragraph <p>...</p>
Heading 1 <h3>...</h3>
Heading 2 <h2>...</h2>
Heading 3 <h4>...</h4>
Bulleted list <ul class="list-bullet content-list"><li><div>...</div></li></ul>
Numbered list <ol class="list-bullet content-list"><li><div>...</div></li></ol>
Table <table><tr><td>...</td></tr></table>
Quote <blockquote>...</blockquote>
Code <pre class='indent-c'><code class='block'>...</code></pre>
Divider <div id='content-body-separator' class='center'></div>

Consecutive list items of the same type are automatically wrapped in <ul> or <ol> tags.

Rich Text Formatting

Inline formatting from Notion is preserved in all text blocks:

Notion Format HTML Output
Bold <strong>...</strong>
Italic <em>...</em>
Code <code class='inline'>...</code>
Strikethrough <s>...</s>
Underline <u>...</u>
Link (internal, ujnotes.com) <a class="content-link XURL" href='...' data-target='...' data-title='...'>
Link (external) <a class="content-link" href="..." target="_blank">

Callout Blocks (Emoji-tagged PHP Components)

Callout blocks with specific emoji icons generate PHP component includes. The callout's text content provides parameters.

First-letter high / drop cap — 🔠

Use this callout only when the author explicitly wants the paragraph's first letter enlarged. Rich-text formatting and links inside the callout are preserved.

Notion: Callout with 🔠 icon containing the paragraph text Output:

<p class='first-letter-high'>Author-selected paragraph...</p>

Ordinary Notion paragraphs generate plain <p> elements without this class. During website-to-Notion upload, only paragraphs already carrying class='first-letter-high' become 🔠 callouts.

Cover Image — 🖼️

Generates the cover image component. The callout text is the image alt text.

Notion: Callout with 🖼️ icon, text: A sculpture of a man thinking deeply Output:

<?php $alt='A sculpture of a man thinking deeply'; require('../HTML/Fragment/Component_cover.php') ?>
<h2 class='center'><?php echo $desc; ?></h2>

Content Image — 🏞️

Generates an inline content image. Text format: img_title|ext|alt|center

Notion: Callout with 🏞️ icon, text: paths|svg||true Output:

<?php $img_title='paths'; $ext='svg'; $alt=''; $center='true'; require('Fragment/Component_image.php') ?>

Two-way image synchronization

Image callouts are the durable rendering metadata; image blocks are the visible Notion copy of the same asset.

  • Notion to website: publication downloads the first Notion image block as the article cover, stores it under Resource/<slug>/index.jpg, injects the cover component, and commits the source asset with the article.
  • Website to Notion: ncms_upload.py pairs an existing cover callout with an image block using the canonical https://ujnotes.com/<slug>.jpg URL. It also pairs each content-image callout with its existing https://ujnotes.com/<slug>/<img_title>.<ext> asset.

The semantic callout and visible image block must stay together. NCMS renders the callout and intentionally ignores the paired image block, preventing a duplicate image on the website. Missing local assets do not produce broken Notion image blocks.

Link XURL — 🔗

Generates PHP link_xurl() calls. One link per line, format: path|label

Notion: Callout with 🔗 icon, text:

world/philosophy/life|Life
world/philosophy/death|Death

Output:

<?php link_xurl('world/philosophy/life', 'Life') ?>
<?php link_xurl('world/philosophy/death', 'Death') ?>

Page layout — 📐

Selects a Cutie layout so a custom page can take its data from Notion while keeping site CSS.

Notion: Callout with 📐 icon. First line is the layout name:

me-table

Optional second line: bottom: nav or bottom: default. me-table defaults to bottom: nav (no Facebook comments / updated date). Nested translations inherit the canonical layout unless they include their own 📐 callout.

me-table: Each Heading 1–3 is a left-hand label (.R1). Paragraphs until the next heading become the value (.R2), joined with <br>. A divider ends the table; following blocks (such as the AI disclosure) render normally. Well-known profile URLs keep badge element ids (linkedin-badge, stackoverflow-badge, facebook-badge).

Output shell:

<div id='message' class='center'>
	<div id='me-table'>...</div>
</div>
<?php require('../HTML/Fragment/Component_bottom_nav.php') ?>

Do not paste About_me.php markup or Component_bottom_nav.php into a 🔧 callout for this layout.

Raw PHP/HTML — 🔧

Outputs the callout text verbatim with no transformation. Use this for any complex PHP/HTML that doesn't fit other patterns (e.g. group_image() calls, Facebook components, custom includes).

Treat this callout as trusted code. Normal Notion text, links, code blocks, and PHP string parameters are escaped; only the 🔧 callout intentionally bypasses escaping.

Notion: Callout with 🔧 icon, text: <?php group_image('paths', 3, 'svg') ?> Output:

<?php group_image('paths', 3, 'svg') ?>

Homepage and navigation — 📐 home, 🏠, 🧭

The published root row in the Website database owns the homepage intro and both menus. Put home in a 📐 layout callout. Ordinary paragraphs and links become the text inside #home-message; NCMS supplies the profile image, homepage tree, and page shell. The Hindi child keeps its 🌐 metadata and translated intro; it inherits the home layout.

Add a 🏠 callout with one JSON code child for the homepage tree policy, and a 🧭 callout with one JSON code child for the side menu policy. The JSON blocks are configuration and are never displayed in the article body. NCMS validates both policies before writing Config/Home.json and Config/Menu.json. Published Config/ID.tsv rows supply the actual tree and labels; the home policy declares synthetic hub children, selected subsets, caps, leaves, and full-width groups. Side menu groups select published slugs; includeHomeHubs: true appends the current synthetic hub children automatically. Side menu labels use the localized Notion page Label, with optional per-language labels overrides in the 🧭 JSON for cases such as the Home tile.

To refresh the local source after editing the published Notion row:

[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
$OutputEncoding = [Console]::OutputEncoding
$env:PYTHONUTF8 = '1'
$env:PYTHONIOENCODING = 'utf-8'
.\.venv\Scripts\python.exe ncms_fetch.py sync-home --site-project D:\Ujnotes\Website\site\project

Run this from the NCMS directory. It updates the English and Hindi homepage components and both menu JSON files locally; it does not bake, push, or change the Notion status. The reverse uploader skips root so it cannot replace the Notion policy with generated PHP.

Verification

Run the offline parser and configuration checks:

.\.venv\Scripts\python.exe -m unittest discover -v

Run the isolated live verification against the Notion page whose Id is test/ncms-blocks and whose Status is test:

.\.venv\Scripts\python.exe test_e2e.py

The live verifier writes to a new temporary directory. It forcibly disables git push and Notion status updates, checks all expected generated artifacts, and confirms that the PHP example inside the Notion code block is emitted as display text rather than executable PHP.

CI publication commands

Render exactly one Status=publish page into an isolated bundle:

python ncms_fetch.py publish \
  --bundle-dir /tmp/ncms-bundle \
  --metadata-file /tmp/ncms-article.json

When more than one page is queued, pass --slug world/philosophy/example. --allow-empty turns an empty queue into a successful no-op (for a scheduler). Scheduled Notion polling is parked; publication is started by a manual workflow_dispatch or by the local publish-notion*.ps1 scripts. Multiple queued pages remain an error.

The publish command always disables NCMS git pushes and Notion updates. After the generated article has been deployed and independently verified, mark the same page published with:

python ncms_fetch.py mark-published \
  --page-id NOTION_PAGE_ID \
  --expected-slug world/philosophy/example

mark-published re-fetches the page, verifies its slug and current status, applies the update, and verifies the final status. It refuses any status other than publish or the already-idempotent published state.

About

Notion based CMD for the Cutie framework

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages