hasty 0.0.4
hasty: ^0.0.4 copied to clipboard
A SwiftUI-inspired static site generator for Dart. Build HTML with HStacks, VStacks, and zero CSS stress.
import 'dart:io';
import 'package:hasty/hasty.dart';
// -----------------------------------------------------------------------------
// Shared Site StyleSheet (:root variables, reset, hover states, @media queries)
// -----------------------------------------------------------------------------
final siteStyles = StyleSheet(
includeReset: true,
variables: {
'brand': '#6366f1',
'brand-dark': '#4f46e5',
'surface': '#ffffff',
'canvas': '#f8fafc',
},
rules: [
const CssRule(
'html',
Style(fontFamily: 'system-ui, -apple-system, sans-serif'),
{'scroll-behavior': 'smooth'},
),
CssRule(
'body',
Style(
backgroundColor: Color.cssVar('canvas'),
color: Colors.darkGray,
lineHeight: 1.6,
),
),
const CssRule('a:hover', Style(opacity: 0.85)),
const CssRule(
'button:hover:not(:disabled)',
Style(
opacity: 0.92,
cursor: Cursor.pointer,
transform: 'translateY(-1px)',
),
),
const CssRule(
'button',
Style(transition: 'opacity 0.15s ease, transform 0.15s ease'),
),
CssRule(
'.hover-card',
const Style(transition: 'transform 0.18s ease, box-shadow 0.18s ease'),
),
CssRule(
'.hover-card:hover',
Style(transform: 'translateY(-3px)', boxShadow: Shadows.lg),
),
const CssRule(
'dialog::backdrop',
Style(backgroundColor: Color.rgba(15, 23, 42, 0.55)),
),
const CssRule(
'.markdown-prose h1, .markdown-prose h2, .markdown-prose h3',
Style(color: Colors.slate, marginTop: 20, marginBottom: 8),
),
const CssRule(
'.markdown-prose p, .markdown-prose ul, .markdown-prose ol, .markdown-prose blockquote, .markdown-prose pre',
Style(marginBottom: 14),
),
const CssRule(
'.markdown-prose ul, .markdown-prose ol',
Style(paddingLeft: 22),
),
CssRule(
'.markdown-prose code',
const Style(
fontFamily: 'ui-monospace, monospace',
fontSize: 13,
paddingTop: 2,
paddingBottom: 2,
paddingLeft: 5,
paddingRight: 5,
borderRadius: 4,
),
{'background-color': Colors.indigo.withOpacity(0.1).toString()},
),
const CssRule(
'.markdown-prose pre',
Style(
backgroundColor: Colors.slate,
color: Colors.offWhite,
padding: 16,
borderRadius: 8,
overflowX: 'auto',
),
),
const CssRule(
'.markdown-prose pre code',
Style(
backgroundColor: Colors.transparent,
color: Colors.offWhite,
padding: 0,
),
),
CssRule(
'.markdown-prose blockquote',
Style(
borderLeft: '4px solid ${Colors.indigo}',
paddingLeft: 14,
color: Colors.gray,
fontStyle: FontStyle.italic,
),
),
],
mediaQueries: [
const MediaQuery(
maxWidth: 768,
rules: [
CssRule(
'.split-row',
Style(display: Display.flex, flexWrap: FlexWrap.wrap),
),
CssRule('.split-col', Style(minWidth: 280)),
],
),
],
);
// Reusable base Styles composed with Style.merge / `+` and Style.copyWith
const _sectionSpacing = Style(paddingTop: 8, paddingBottom: 8);
final _surfaceCardStyle = Style(
border: '1px solid ${Colors.lightGray}',
boxShadow: Shadows.sm,
);
final _accentCardStyle =
_surfaceCardStyle +
Style(
border: '1px solid ${Colors.indigo.withOpacity(0.4)}',
boxShadow: Shadows.md,
);
// Inline SVG data URI used for image/avatar demos so local viewing needs no external network
const _demoGraphicDataUri =
'data:image/svg+xml;utf8,'
'<svg xmlns="http://www.w3.org/2000/svg" width="480" height="220" viewBox="0 0 480 220">'
'<defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1">'
'<stop offset="0%" stop-color="%236366f1"/><stop offset="100%" stop-color="%2314b8a6"/>'
'</linearGradient></defs>'
'<rect width="480" height="220" rx="12" fill="url(%23g)"/>'
'<circle cx="90" cy="110" r="42" fill="rgba(255,255,255,0.2)"/>'
'<text x="155" y="105" fill="white" font-family="sans-serif" font-size="24" font-weight="bold">Hasty 0.0.4</text>'
'<text x="155" y="135" fill="rgba(255,255,255,0.88)" font-family="sans-serif" font-size="14">Typed HTML + CSS + Markdown</text>'
'</svg>';
const _avatarSvgDataUri =
'data:image/svg+xml;utf8,'
'<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80" viewBox="0 0 80 80">'
'<rect width="80" height="80" fill="%2306b6d4"/>'
'<circle cx="40" cy="31" r="14" fill="white"/>'
'<path d="M16 72c4-14 16-22 24-22s20 8 24 22" fill="white"/>'
'</svg>';
// -----------------------------------------------------------------------------
// Shared Site Layout (Header, NavBar, Container, Footer & Dialog Script)
// -----------------------------------------------------------------------------
Node siteLayout(
Node pageContent,
SitePage currentPage, {
required bool prettyUrls,
}) {
final homeHref = prettyUrls ? '/' : './index.html';
final mdHref = prettyUrls ? '/markdown-guide/' : './markdown-guide.html';
return div(
children: [
comment('Shared site header generated via emitSite(layout: ...)'),
header(
style: Style(
backgroundColor: Colors.white,
borderBottom: '1px solid ${Colors.lightGray}',
position: Position.sticky,
top: 0,
zIndex: 20,
),
children: [
container(
maxWidth: 980,
padding: 24,
child: padding(
vertical: 14,
child: hStack(
children: [
a(
href: homeHref,
style: const Style(textDecoration: TextDecoration.none),
children: [
hStack(
style: const Style(gap: 10),
children: [
avatar(
initials: 'H',
size: 34,
backgroundColor: Colors.indigo,
),
strong(
'Hasty',
style: const Style(
fontSize: 20,
color: Colors.slate,
),
),
badge(
'v0.0.4',
color: Colors.indigo,
variant: BadgeVariant.subtle,
),
],
),
],
),
spacer(),
navBar(
links: [
navLink(
label: 'Showcase',
href: homeHref,
style: Style(
color: currentPage.path == 'index'
? Colors.indigo
: Colors.darkGray,
fontWeight: currentPage.path == 'index'
? FontWeight.bold
: FontWeight.medium,
textDecoration: TextDecoration.none,
),
),
navLink(
label: 'Layouts',
href: '$homeHref#layouts',
style: const Style(
color: Colors.darkGray,
textDecoration: TextDecoration.none,
),
),
navLink(
label: 'Components',
href: '$homeHref#components',
style: const Style(
color: Colors.darkGray,
textDecoration: TextDecoration.none,
),
),
divider(axis: Axis.vertical, spacing: 4),
navLink(
label: 'Markdown Guide →',
href: mdHref,
style: Style(
color: currentPage.path == 'markdown-guide'
? Colors.indigo
: Colors.teal,
fontWeight: FontWeight.semibold,
textDecoration: TextDecoration.none,
),
),
],
),
],
),
),
),
],
),
main_(
children: [
container(
maxWidth: 980,
padding: 24,
child: padding(vertical: 28, child: pageContent),
),
],
),
footer(
style: Style(
borderTop: '1px solid ${Colors.lightGray}',
backgroundColor: Colors.white,
marginTop: 48,
),
children: [
container(
maxWidth: 980,
padding: 24,
child: padding(
vertical: 24,
child: hStack(
children: [
p([
txt('Built in pure Dart with '),
strong('Hasty'),
txt(' · Updated '),
time('November 2026', datetime: '2026-11-14'),
]),
spacer(),
hStack(
style: const Style(gap: 12, fontSize: 13),
children: [
a(href: homeHref, content: 'Home'),
divider(axis: Axis.vertical),
a(href: mdHref, content: 'Markdown Guide'),
divider(axis: Axis.vertical),
a(href: './sitemap.xml', content: 'Sitemap XML'),
],
),
],
),
),
),
],
),
// Tiny progressive-enhancement script wiring data-dialog-open / close buttons to native <dialog>
script(
content: '''
document.querySelectorAll('[data-dialog-open]').forEach((btn) => {
btn.addEventListener('click', () => {
const dlg = document.getElementById(btn.dataset.dialogOpen);
if (dlg && dlg.showModal) dlg.showModal();
});
});
document.querySelectorAll('[data-dialog-close]').forEach((btn) => {
btn.addEventListener('click', () => {
const dlg = btn.closest('dialog');
if (dlg && dlg.close) dlg.close();
});
});
''',
),
],
);
}
// -----------------------------------------------------------------------------
// Page 1: Comprehensive Feature & Component Showcase (index.html)
// -----------------------------------------------------------------------------
Node buildHomePage({required bool prettyUrls}) {
final mdHref = prettyUrls ? '/markdown-guide/' : './markdown-guide.html';
return vStack(
style: const Style(gap: 40),
children: [
breadcrumb(
items: const [
BreadcrumbItem('Hasty', href: './index.html'),
BreadcrumbItem('Component & Feature Showcase'),
],
),
// Hero banner with gradient background, eyebrow badge, and CTA buttons
card(
padding: 36,
style: Style(
background:
'linear-gradient(135deg, ${Colors.indigo.withOpacity(0.10)}, ${Colors.teal.withOpacity(0.10)})',
border: '1px solid ${Colors.indigo.withOpacity(0.25)}',
borderRadius: 16,
),
children: [
heroSection(
eyebrow: 'SwiftUI-Inspired Static Site Generator',
title: 'Build complete static sites in pure Dart.',
subtitle:
'Compose Flexbox & CSS Grid layouts, type-safe StyleSheets, zero-dependency Markdown, and accessible UI components — with zero templates.',
style: const Style(paddingTop: 8, paddingBottom: 8),
actions: [
a(
href: mdHref,
style: const Style(textDecoration: TextDecoration.none),
children: [
button([
span('📖'),
txt(' Read Markdown Guide'),
], variant: ButtonVariant.primary),
],
),
button(
[span('✨'), txt(' Open Native Dialog')],
variant: ButtonVariant.outline,
data: {'dialog-open': 'release-modal'},
),
],
),
],
),
// Native HTML <dialog> modal
dialog(
id: 'release-modal',
aria: {'labelledby': 'modal-heading'},
style: Style(
border: '1px solid ${Colors.lightGray}',
borderRadius: 12,
padding: 24,
maxWidth: 460,
boxShadow: Shadows.xl,
),
children: [
vStack(
style: const Style(gap: 12),
children: [
hStack(
children: [
h3(
'Native HTML <dialog>',
id: 'modal-heading',
style: const Style(margin: 0),
),
spacer(),
button(
'✕',
variant: ButtonVariant.ghost,
aria: {'label': 'Close dialog'},
data: {'dialog-close': 'true'},
),
],
),
p([
txt('This modal uses Hasty\'s semantic '),
code('dialog(...)'),
txt(' tag, '),
code('data-*'),
txt(' attributes, and '),
code('aria-*'),
txt(' metadata — styled via '),
code('dialog::backdrop'),
txt(' in '),
code('StyleSheet'),
txt('.'),
]),
hStack(
mainAxisAlignment: MainAxisAlignment.end,
children: [
button(
'Got it',
variant: ButtonVariant.primary,
data: {'dialog-close': 'true'},
),
],
),
],
),
],
),
// Stat Cards in a 3-column CSS Grid
section(
id: 'metrics',
style: _sectionSpacing,
children: [
grid(
columns: 3,
gap: 16,
children: [
statCard(
icon: '⚡',
value: '0 deps',
label: 'Zero HTML/Markdown parser bloat',
color: Colors.indigo,
classes: 'hover-card',
),
statCard(
icon: '🧩',
value: '55+ APIs',
label: 'Tags, layouts & pre-styled components',
color: Colors.teal,
classes: 'hover-card',
),
statCard(
icon: '✅',
value: '100%',
label: 'HTML-escaped by construction',
color: Colors.emerald,
classes: 'hover-card',
),
],
),
],
),
divider(),
// Layout Primitives Showcase: Responsive Grid, Split Expanded + Aside, zStack & figure
section(
id: 'layouts',
children: [
h2('Layout Primitives'),
spacer(size: 8),
p([
txt('Combine '),
code('vStack'),
txt(', '),
code('hStack'),
txt(', '),
code('zStack'),
txt(', '),
code('grid'),
txt(', '),
code('wrap'),
txt(', '),
code('expanded'),
txt(', and '),
code('container'),
txt(' without writing raw CSS rules.'),
]),
spacer(size: 16),
// Auto-responsive grid (minChildWidth)
grid(
minChildWidth: 210,
gap: 16,
children: [
_pillarCard(
badgeText: 'grid()',
badgeColor: Colors.indigo,
title: 'Auto-Fit CSS Grid',
body:
'Pass minChildWidth: 210 and columns wrap responsively with zero media queries.',
featured: true,
),
_pillarCard(
badgeText: 'Style + Style',
badgeColor: Colors.purple,
title: 'Composable Styles',
body:
'Merge and override Style objects cleanly with + or copyWith().',
),
_pillarCard(
badgeText: 'StyleSheet',
badgeColor: Colors.teal,
title: 'Hover & @media',
body:
'Hover over these cards to see .hover-card rules rendered from StyleSheet.',
),
_pillarCard(
badgeText: 'emitSite()',
badgeColor: Colors.amber,
title: 'Multi-Page SSG',
body:
'Shared layouts, relative CSS linking, pretty URLs, and XML sitemaps.',
),
],
),
spacer(size: 24),
// Proportional hStack using expanded(flex: 3) + expanded(flex: 2) with zStack + aside
hStack(
classes: 'split-row',
crossAxisAlignment: CrossAxisAlignment.stretch,
style: const Style(gap: 20),
children: [
expanded(
flex: 3,
classes: 'split-col',
child: card(
backgroundColor: Colors.white,
style: _surfaceCardStyle,
children: [
h3(
'Layered Media with zStack + figure',
style: const Style(marginTop: 0),
),
spacer(size: 8),
figure(
children: [
zStack(
children: [
img(
src: _demoGraphicDataUri,
alt: 'Hasty 0.0.4 banner graphic',
loading: 'lazy',
style: const Style(
borderRadius: 10,
display: Display.block,
),
),
div(
style: const Style(
position: Position.absolute,
top: 12,
right: 12,
),
children: [
badge('Pinned via zStack', color: Colors.slate),
],
),
],
),
spacer(size: 8),
figcaption(
[
txt('Figure 1 — '),
code('zStack'),
txt(' layers an absolute '),
code('badge'),
txt(' over a responsive SVG '),
code('img'),
txt('.'),
],
style: const Style(fontSize: 12, color: Colors.gray),
),
],
),
],
),
),
expanded(
flex: 2,
classes: 'split-col',
child: aside(
children: [
card(
backgroundColor: Colors.white,
style: _surfaceCardStyle.copyWith(
borderLeft: '4px solid ${Colors.teal}',
),
children: [
h3(
'Semantic Prose & Specs',
style: const Style(marginTop: 0),
),
spacer(size: 8),
p([
txt('Inline tags support '),
mark('highlighted notes'),
txt(', '),
del('templates'),
txt(' '),
ins('pure functions'),
txt(', '),
abbr('SSG', title: 'Static Site Generator'),
txt(', H'),
sub('2'),
txt('O, and O(n'),
sup('2'),
txt(').'),
]),
spacer(size: 10),
p([
txt('Build shortcut: '),
kbd('Ctrl'),
txt(' + '),
kbd('Shift'),
txt(' + '),
kbd('B'),
]),
divider(spacing: 12),
dl(
style: const Style(fontSize: 13),
children: [
// fragment() returns dt + dd pairs without extra wrapper divs!
_specPair('SDK Target', 'Dart ^3.10.7'),
_specPair(
'Color Modes',
'Hex, RGB(A), HSL(A), CSS Vars',
),
_specPair(
'Lighthouse Gauge',
meter(
value: 98,
min: 0,
max: 100,
low: 50,
high: 85,
optimum: 100,
),
),
],
),
],
),
],
),
),
],
),
],
),
divider(),
// High-Level Components Showcase
section(
id: 'components',
children: [
h2('UI Component Library'),
spacer(size: 16),
vStack(
style: const Style(gap: 28),
children: [
// Buttons & Variants
card(
backgroundColor: Colors.white,
style: _surfaceCardStyle,
children: [
h3(
'Button Variants & Badges',
style: const Style(marginTop: 0),
),
spacer(size: 10),
wrap(
gap: 10,
children: [
button('Primary', variant: ButtonVariant.primary),
button('Secondary', variant: ButtonVariant.secondary),
button('Outline', variant: ButtonVariant.outline),
button('Danger', variant: ButtonVariant.danger),
button('Ghost', variant: ButtonVariant.ghost),
button('Floating', variant: ButtonVariant.floating),
button(
'Disabled',
variant: ButtonVariant.secondary,
disabled: true,
),
],
),
divider(spacing: 16),
wrap(
gap: 8,
children: [
badge('Solid Green', color: Colors.green),
badge(
'Subtle Indigo',
color: Colors.indigo,
variant: BadgeVariant.subtle,
),
badge(
'Outline Teal',
color: Colors.teal,
variant: BadgeVariant.outline,
),
badge(
'Subtle Rose',
color: Colors.rose,
variant: BadgeVariant.subtle,
),
badge('Custom HSL', color: const Color.hsl(265, 83, 57)),
],
),
],
),
// Avatars & Progress Bars
grid(
minChildWidth: 320,
gap: 20,
children: [
card(
backgroundColor: Colors.white,
style: _surfaceCardStyle,
children: [
h3('Avatars', style: const Style(marginTop: 0)),
spacer(size: 12),
wrap(
gap: 14,
children: [
avatar(
imageUrl: _avatarSvgDataUri,
alt: 'Cyan user avatar',
size: 48,
),
avatar(
initials: 'BL',
size: 48,
backgroundColor: Colors.indigo,
),
avatar(
initials: 'DT',
size: 48,
backgroundColor: Colors.emerald,
),
avatar(
initials: 'UI',
size: 40,
backgroundColor: Colors.rose,
),
],
),
spacer(size: 12),
small(
'Supports circular image URLs (object-fit: cover) or automatic initials badges.',
style: const Style(color: Colors.gray),
),
],
),
card(
backgroundColor: Colors.white,
style: _surfaceCardStyle,
children: [
h3('Progress Bars', style: const Style(marginTop: 0)),
spacer(size: 12),
vStack(
style: const Style(gap: 12),
children: [
progressBar(
value: 92,
label: 'Static Route Compilation',
showPercentage: true,
color: Colors.indigo,
),
progressBar(
value: 100,
label: 'Analyzer & Test Coverage',
showPercentage: true,
color: Colors.emerald,
),
progressBar(
value: 68,
label: 'CSS Minification Ratio',
showPercentage: true,
color: Colors.teal,
),
],
),
],
),
],
),
// Alerts (All 4 Variants)
card(
backgroundColor: Colors.white,
style: _surfaceCardStyle,
children: [
h3('Contextual Alerts', style: const Style(marginTop: 0)),
spacer(size: 12),
grid(
minChildWidth: 340,
gap: 12,
children: [
alert(
'Multi-page build includes index.html, markdown-guide.html, styles.css, and sitemap.xml.',
title: 'Info',
variant: AlertVariant.info,
),
alert(
'All 148 unit tests passed with zero analyzer warnings.',
title: 'Build Succeeded',
variant: AlertVariant.success,
),
alert(
'Pass minify: true in production to strip whitespace and HTML comments.',
title: 'Optimization Tip',
variant: AlertVariant.warning,
),
alert(
'Never pass untrusted user input into raw() — prefer standard tags or markdown().',
title: 'Security Reminder',
variant: AlertVariant.error,
),
],
),
],
),
// Zero-JS Accordion
div(
children: [
h3('Zero-JS Accordions (<details> & <summary>)'),
spacer(size: 10),
accordion(
items: [
accordionItem(
title:
'How does Hasty handle hover states and @media queries?',
open: true,
children: [
p([
txt('Define a '),
code('StyleSheet'),
txt(' with '),
code('CssRule'),
txt(' and '),
code('MediaQuery'),
txt(
' entries. Each rule reuses the exact same typed ',
),
code('Style'),
txt(' class as inline styles.'),
]),
],
),
accordionItem(
title: 'Does markdown() require external packages?',
children: [
p([
txt('No! '),
code('markdown()'),
txt(
' is built directly into Hasty with zero external dependencies and emits safe Hasty ',
),
code('Node'),
txt(' trees.'),
]),
],
),
accordionItem(
title:
'Can I generate multi-page websites with shared navigation?',
children: [
p([
txt('Yes — this very example uses '),
code('emitSite()'),
txt(
' to share a sticky header, stylesheet, and footer across ',
),
a(href: './index.html', content: 'index.html'),
txt(' and '),
a(href: mdHref, content: 'markdown-guide.html'),
txt('.'),
]),
],
),
],
),
],
),
],
),
],
),
divider(),
// Markdown Preview & CodeBlock Component
section(
id: 'markdown-preview',
children: [
hStack(
children: [
h2(
'Built-In Markdown & Code Blocks',
style: const Style(margin: 0),
),
spacer(),
a(href: mdHref, content: 'Open Full Markdown Guide →'),
],
),
spacer(size: 16),
grid(
minChildWidth: 360,
gap: 20,
children: [
card(
backgroundColor: Colors.white,
style: _surfaceCardStyle,
children: [
markdown(classes: 'markdown-prose', '''
### Live Markdown Output
Hasty parses **bold**, _italic_, ~~strikethrough~~, `inline code`, and snake_case names like `parse_markdown_nodes` cleanly.
- Automatic slug `id`s on headings
- Safe HTML escaping by default
- Seamless composition inside `card()` or `article()`
> "Simplicity is prerequisite for reliability."
'''),
],
),
vStack(
style: const Style(gap: 12),
children: [
codeBlock(
'''await emitSite(
[
SitePage(path: 'index', title: 'Home', body: home),
SitePage(path: 'markdown-guide', title: 'Guide', body: guide),
],
sharedStyleSheet: siteStyles,
layout: siteLayout,
generateSitemap: true,
baseUrl: 'https://example.com',
);''',
language: 'dart',
filename: 'example/hasty_example.dart',
),
blockquote(
'Every code snippet in codeBlock() and markdown() escapes <, >, and & automatically.',
cite: 'https://github.com/BendyLand/Hasty',
style: Style(
margin: 0,
paddingLeft: 12,
borderLeft: '3px solid ${Colors.indigo}',
fontSize: 13,
color: Colors.gray,
fontStyle: FontStyle.italic,
),
),
],
),
],
),
],
),
divider(),
// Specs Table & Contact Form side-by-side in responsive Grid
section(
id: 'specs-and-contact',
children: [
grid(
minChildWidth: 360,
gap: 24,
alignItems: CrossAxisAlignment.start,
children: [
card(
id: 'specs',
backgroundColor: Colors.white,
style: _surfaceCardStyle,
children: [
h3('Feature Matrix', style: const Style(marginTop: 0)),
spacer(size: 10),
table(
style: const Style(fontSize: 14),
children: [
thead(
children: [
tr(
style: Style(
borderBottom: '2px solid ${Colors.lightGray}',
),
children: [
th(
content: 'Module',
scope: Scope.col,
style: const Style(
textAlign: TextAlign.left,
padding: 8,
),
),
th(
content: 'Highlights',
scope: Scope.col,
style: const Style(
textAlign: TextAlign.left,
padding: 8,
),
),
],
),
],
),
tbody(
children: [
_matrixRow(
'layout',
'vStack, hStack, zStack, grid, wrap, container',
),
_matrixRow(
'style',
'Style.merge (+), Shadows, Color.withOpacity',
),
_matrixRow(
'stylesheet',
'CssRule, MediaQuery, :root variables',
),
_matrixRow(
'markdown',
'Headings, lists, fences, quotes, links',
),
_matrixRow(
'components',
'heroSection, alert, accordion, codeBlock',
),
_matrixRow(
'generator',
'emit, emitSite, emitCss, renderDocument',
),
],
),
],
),
],
),
card(
id: 'contact',
backgroundColor: Colors.white,
style: _surfaceCardStyle,
children: [
h3(
'Interactive Form Controls',
style: const Style(marginTop: 0),
),
spacer(size: 10),
form(
action: '/feedback',
method: 'post',
data: {'controller': 'feedback-form'},
children: [
vStack(
style: const Style(gap: 12),
children: [
vStack(
style: const Style(gap: 4),
children: [
label(htmlFor: 'name', content: 'Name'),
input(
id: 'name',
name: 'name',
placeholder: 'Ada Lovelace',
autocomplete: 'name',
required: true,
style: _inputStyle,
),
],
),
vStack(
style: const Style(gap: 4),
children: [
label(
htmlFor: 'topic',
content: 'Favorite Addition',
),
select(
id: 'topic',
name: 'topic',
style: _inputStyle,
children: [
optgroup(
label: 'Core Engine',
children: [
option(
value: 'grid',
content: 'Responsive CSS Grid',
selected: true,
),
option(
value: 'stylesheet',
content: 'Typed StyleSheet & @media',
),
option(
value: 'markdown',
content: 'Markdown-to-Node Parser',
),
],
),
optgroup(
label: 'Site Builder',
children: [
option(
value: 'emitsite',
content:
'Multi-Page emitSite() & Sitemap',
),
],
),
],
),
],
),
vStack(
style: const Style(gap: 4),
children: [
label(htmlFor: 'notes', content: 'Notes'),
textarea(
id: 'notes',
name: 'notes',
rows: 3,
placeholder: 'What will you build with Hasty?',
style: _inputStyle,
),
],
),
button(
'Send Feedback',
type: 'submit',
variant: ButtonVariant.primary,
),
],
),
],
),
],
),
],
),
],
),
],
);
}
final _inputStyle = Style(
padding: 8,
borderRadius: 6,
border: '1px solid ${Colors.lightGray}',
fontSize: 14,
);
Node _pillarCard({
required String badgeText,
required Color badgeColor,
required String title,
required String body,
bool featured = false,
}) => card(
classes: 'hover-card',
backgroundColor: Colors.white,
style: featured ? _accentCardStyle : _surfaceCardStyle,
children: [
vStack(
crossAxisAlignment: CrossAxisAlignment.start,
style: const Style(gap: 8),
children: [
badge(badgeText, color: badgeColor, variant: BadgeVariant.subtle),
h4(title, style: const Style(margin: 0, color: Colors.slate)),
p(body, style: const Style(margin: 0, fontSize: 14)),
],
),
],
);
Node _specPair(String term, Object definition) => fragment([
dt(
term,
style: const Style(
fontWeight: FontWeight.semibold,
color: Colors.slate,
marginTop: 6,
),
),
dd(definition, style: const Style(marginLeft: 0, color: Colors.gray)),
]);
Node _matrixRow(String module, String highlights) => tr(
style: Style(borderBottom: '1px solid ${Colors.offWhite}'),
children: [
td(style: const Style(padding: 8), children: [code(module)]),
td(
content: highlights,
style: const Style(padding: 8, color: Colors.gray),
),
],
);
// -----------------------------------------------------------------------------
// Page 2: Dedicated Markdown Article & Table-of-Contents Page
// -----------------------------------------------------------------------------
const _guideMarkdownSource = '''
# Authoring Content with Markdown
Hasty includes a zero-dependency `markdown()` parser that converts standard Markdown prose directly into composable `Node` trees — ready to embed inside `article()`, `card()`, or multi-page blog routes.
## Supported Syntax
Write clean, readable prose using familiar formatting:
1. **Bold** and _italic_ emphasis (while preserving identifiers like `emit_site` and `parse_markdown_nodes`)
2. Inline `code` spans and ~~strikethrough~~ annotations
3. Safe external links like [Dart Packages](https://pub.dev) and inline images
4. Nested blockquotes, horizontal rules, and fenced code blocks
---
## Code Blocks & Escaping
Fenced code blocks preserve indentation and attach `language-*` classes automatically, while escaping special HTML characters like `<script>` or `&`:
```dart
import 'package:hasty/hasty.dart';
Node blogPost(String rawMd) => article(
children: [
badge('Tutorial', color: Colors.indigo, variant: BadgeVariant.subtle),
markdown(rawMd, classes: 'markdown-prose'),
],
);
```
## Composing Markdown with Components
> Because `markdown()` returns a standard Hasty `Node`, you can mix Markdown articles alongside `alert()`, `statCard()`, `accordion()`, and `codeBlock()` on the exact same page.
''';
Node buildMarkdownGuidePage({required bool prettyUrls}) {
final homeHref = prettyUrls ? '/' : './index.html';
return vStack(
style: const Style(gap: 24),
children: [
breadcrumb(
items: [
BreadcrumbItem('Hasty', href: homeHref),
const BreadcrumbItem('Markdown Guide'),
],
),
hStack(
classes: 'split-row',
crossAxisAlignment: CrossAxisAlignment.start,
style: const Style(gap: 24),
children: [
expanded(
flex: 3,
classes: 'split-col',
child: article(
children: [
card(
padding: 32,
backgroundColor: Colors.white,
style: _surfaceCardStyle,
children: [
hStack(
style: const Style(gap: 8, marginBottom: 12),
children: [
badge('Documentation', color: Colors.teal),
time(
'Nov 14, 2026',
datetime: '2026-11-14',
style: const Style(fontSize: 13, color: Colors.gray),
),
],
),
markdown(_guideMarkdownSource, classes: 'markdown-prose'),
],
),
],
),
),
expanded(
flex: 1,
classes: 'split-col',
child: aside(
children: [
card(
backgroundColor: Colors.white,
style: _surfaceCardStyle,
children: [
h4(
'On This Page',
style: const Style(
marginTop: 0,
textTransform: TextTransform.uppercase,
letterSpacing: 0.8,
fontSize: 12,
color: Colors.gray,
),
),
ul(
style: const Style(
listStyle: 'none',
paddingLeft: 0,
fontSize: 14,
),
children: [
li(
a(
href: '#authoring-content-with-markdown',
content: 'Overview',
),
style: const Style(paddingBottom: 6),
),
li(
a(
href: '#supported-syntax',
content: 'Supported Syntax',
),
style: const Style(paddingBottom: 6),
),
li(
a(
href: '#code-blocks-escaping',
content: 'Code Blocks & Escaping',
),
style: const Style(paddingBottom: 6),
),
li(
a(
href: '#composing-markdown-with-components',
content: 'Composing with Components',
),
),
],
),
divider(spacing: 14),
a(href: homeHref, content: '← Back to Showcase'),
],
),
],
),
),
],
),
],
);
}
// -----------------------------------------------------------------------------
// CLI Entrypoint
// -----------------------------------------------------------------------------
void main(List<String> args) async {
final parser = Parser()
..register(
'--output',
'Output directory for generated static files',
type: String,
defaultsTo: 'build',
aliases: ['-o', 'output'],
)
..register(
'--base-url',
'Base URL used when generating sitemap.xml',
type: String,
defaultsTo: 'https://bendyland.github.io/Hasty',
)
..register('--minify', 'Minify emitted HTML and CSS files', aliases: ['-m'])
..register(
'--pretty-urls',
'Emit route/index.html directories instead of route.html',
)
..register('--help', 'Show CLI usage information', aliases: ['-h']);
try {
parser.parse(args);
} catch (e) {
print(e);
parser.printFlags();
exit(1);
}
if (parser.flag('--help')) {
print(parser.formatHelp(header: 'Hasty Example Site Builder — Flags:'));
return;
}
final outDir = parser.option<String>('--output')!;
final baseUrl = parser.option<String>('--base-url')!;
final minify = parser.flag('--minify');
final prettyUrls = parser.flag('--pretty-urls');
final pages = [
SitePage(
path: 'index',
title: 'Hasty — Component & Feature Showcase',
description:
'Interactive static showcase of Hasty layouts, StyleSheets, Markdown, and UI components.',
meta: {
'og:title': 'Hasty — Static Site Generator for Dart',
'og:type': 'website',
},
body: buildHomePage(prettyUrls: prettyUrls),
),
SitePage(
path: 'markdown-guide',
title: 'Markdown Guide — Hasty',
description:
'Zero-dependency Markdown-to-Node rendering in Hasty with auto-slug headings.',
meta: {
'og:title': 'Authoring Content with Markdown in Hasty',
'og:type': 'article',
},
body: buildMarkdownGuidePage(prettyUrls: prettyUrls),
),
];
await emitSite(
pages,
outputDir: outDir,
sharedStyleSheet: siteStyles,
layout: (body, page) => siteLayout(body, page, prettyUrls: prettyUrls),
prettyUrls: prettyUrls,
generateSitemap: true,
baseUrl: baseUrl,
minify: minify,
);
}