FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
yakuzadave
yakuzadavenotionWidgets
A way to be able to host your own Notion Widgets using ValTown
Public
Like
notionWidgets
Home
Code
5
README.md
H
advanced_dice_roller.tsx
H
base_widget.ts
H
click_counter.tsx
H
dice_roller.tsx
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in miliseconds.
Sign up now
Code
/
Code
/
Search
README.md

Notion Widgets on Val Town

A collection of embeddable Notion widgets hosted on Val Town, allowing you to serve interactive UI directly within your Notion pagesβ€”no external servers required.

πŸš€ Project Overview

This repo demonstrates how to build, deploy, and embed serverless widgets using Val Town Projects. Widgets include:

  • Base Widget (base_widget.ts) β€” Example static HTML/JS export
  • Click Counter (click_counter.tsx) β€” Persistent click counter using blob storage
  • Simple Dice Roller (dice_roller.ts) β€” D&D-style expression roller with history and clear functionality
  • Advanced Dice Roller (advanced_dice_roller.tsx) β€” Adds presets, advantage/disadvantage, keep/drop, exploding dice

πŸ“ File Structure

notionWidgets/ β”œβ”€ base_widget.ts # Minimal example of a static UI val β”œβ”€ click_counter.tsx # Click counter with blob persistence β”œβ”€ dice_roller.ts # Simple expression-based dice roller β”œβ”€ advanced_dice_roller.tsx # Full-featured dice roller with advanced mechanics └─ README.md # This documentation

πŸ› οΈ Prerequisites

  • A Val Town account (free or pro) with the Projects feature enabled
  • Basic familiarity with TypeScript/TSX and serverless concepts
  • Notion workspace where you can embed iframes via /embed

πŸ“¦ Installation & Deployment

  1. Clone or Remix this project in Val Town:

    • Click Remix on the project page, or

    • Use the Val Town CLI:

      vt clone <username>/notionWidgets cd notionWidgets vt push
  2. Publish your project (ensure it’s public or unlisted).

  3. Access each widget at:

    https://<your-username>.val.run/<file-name-without-extension>
    
    • E.g.: /click_counter, /dice_roller, /advanced_dice_roller
  4. Embed in Notion:

    1. In Notion, type /embed β†’ Embed URL.
    2. Paste the widget URL (e.g. https://<username>.val.run/dice_roller).
    3. Resize the iframe as needed.

πŸ“œ Widget Summaries

1. base_widget.ts

A minimal example exporting a static HTML page via a default export.

2. click_counter.tsx

  • Routes: / (UI), /count (GET/POST API)
  • Blob storage: std/blob for persistent { count }
  • Features: Click button, see live count, persists across reloads.

3. dice_roller.ts

  • Routes: /, /roll, /history, /clear

  • Parsing: NdM+K expressions

  • UI: Input + roll button + history list + clear history

  • Improvements:

    • Dynamic BASE detection via window.location.pathname
    • Full breakdown: individual rolls, modifiers, totals
    • HTTP caching patterns (ETag) in expanded versions

4. advanced_dice_roller.tsx

  • Advanced Mechanics:

    • Presets: Attack, Damage, Stat, Advantage, Disadvantage
    • Advantage/Disadvantage: advdM / disdM
    • Exploding Dice: NdM!
    • Keep/Drop: NdMkhK / NdMklK (e.g. 4d6kh3)
  • UI Enhancements:

    • Styled themes (dark/light)
    • Error handling in client JS
    • Full history with timestamp and breakdown

πŸ”§ Key Techniques

  • Dynamic Base Path: derive BASE from window.location.pathname for embeds
  • Blob Persistence: blob.getJSON / blob.setJSON for stateful data
  • Modular Parsing: extensible parseExpression() covering multiple RPG mechanics
  • TSX Parsing: avoid nested backticks by using single-quoted JS strings and concatenation

🎯 Next Steps

  • Add statistics dashboards (mean/median/histogram)
  • Implement CSV/JSON export or clipboard copy
  • Integrate with Notion API to write rolls back into a database
  • Enhance accessibility and keyboard support
  • Add sound/animation for tactile feedback

πŸ“– References

  • Val Town Docs
  • Deno std/blob
  • Notion Embed Blocks

Enjoy building and embedding your own custom Notion widgets with Val Town! Feel free to extend and remix this template.

Code
README.md
H
advanced_dice_roller.tsx
H
base_widget.ts
H
click_counter.tsx
H
dice_roller.tsx
Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
Β© 2025 Val Town, Inc.