Najova

DocsBuilt-in functions

Page parts

Build a page from parts instead of HTML. Blocks close like $if: $row ... $endrow. Settings go after the values, like gap=12 or look=primary.

$pagewebNaja page

$page ... $endpage

In a webNaja page: the whole page: its title, then the parts in it. Settings: lang=, description=.

index.wnaj
$page[Najova;description=A language for bots, games and sites]
  $heading[Write less, build more]
  $paragraph[Every page gets a light and a dark look.]
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<h1 class="nj-heading">Write less, build more</h1>
<p class="nj-paragraph">Every page gets a light and a dark look.</p>
</main>

$headingwebNaja page

$heading[text] or $heading[text;level]

In a webNaja page: a heading (the first is level 1, later ones 2).

index.wnaj
$page[Levels]
  $heading[Levels]
  $heading[World 1]
  $heading[Secrets;3]
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<h1 class="nj-heading">Levels</h1>
<h2 class="nj-heading" id="world-1">World 1</h2>
<h3 class="nj-heading" id="secrets">Secrets</h3>
</main>

$paragraphwebNaja page

$paragraph[text]

In a webNaja page: a paragraph of text.

index.wnaj
$page[About]
  $paragraph[Text is shown as written: <tags> & all.]
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<p class="nj-paragraph">Text is shown as written: &lt;tags&gt; &amp; all.</p>
</main>

$sectionwebNaja page

$section ... $endsection

In a webNaja page: a part of the page, with an optional title.

index.wnaj
$page[Shop]
  $section[Swords]
    $paragraph[Sharp ones.]
  $endsection
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<section class="nj-section">
<h2>Swords</h2>
<p class="nj-paragraph">Sharp ones.</p>
</section>
</main>

$rowwebNaja page

$row ... $endrow

In a webNaja page: parts side by side (they wrap on narrow screens). Settings: gap=, align=, justify=.

index.wnaj
$page[Links]
  $row[gap=12]
    $link[Install;/install;look=primary]
    $link[Docs;/docs]
  $endrow
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<div class="nj-row" style="gap:12px">
<a href="/install" class="nj-button primary">Install</a>
<a href="/docs" class="nj-link">Docs</a>
</div>
</main>

$columnwebNaja page

$column ... $endcolumn

In a webNaja page: parts one under another. Settings: gap=, align=.

index.wnaj
$page[Steps]
  $column[gap=8]
    $paragraph[1. Install]
    $paragraph[2. Write]
  $endcolumn
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<div class="nj-column" style="gap:8px">
<p class="nj-paragraph">1. Install</p>
<p class="nj-paragraph">2. Write</p>
</div>
</main>

$gridwebNaja page

$grid ... $endgrid

In a webNaja page: parts in columns that become one column on phones. Settings: cols=, gap=.

index.wnaj
$page[Features]
  $grid[cols=3]
    $section[Fast]
    $endsection
    $section[Simple]
    $endsection
    $section[Yours]
    $endsection
  $endgrid
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<div class="nj-grid" style="--cols:3">
<section class="nj-section">
<h2>Fast</h2>
</section>
<section class="nj-section">
<h2>Simple</h2>
</section>
<section class="nj-section">
<h2>Yours</h2>
</section>
</div>
</main>

$itemswebNaja page

$items ... $enditems

In a webNaja page: a list: each part inside is one item.

index.wnaj
$page[Todo]
  $items
    $paragraph[Feed the cat]
    $link[Read the guide;/guide]
  $enditems
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<ul class="nj-items">
<li><p class="nj-paragraph">Feed the cat</p></li>
<li><a href="/guide" class="nj-link">Read the guide</a></li>
</ul>
</main>

$imagewebNaja page

$image[file;what it shows]

In a webNaja page: a picture, with words for people who cannot see it.

index.wnaj
$page[Gallery]
  $image[/cat.png;A cat asleep on a keyboard]
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<img src="/cat.png" alt="A cat asleep on a keyboard" loading="lazy" class="nj-image">
</main>

$buttonwebNaja page

$button[text] or $button[text;where]

In a webNaja page: a button; with a name= its click reaches $on[name.Clicked]; look=primary|quiet.

index.wnaj
$page[Hello]
  $button[Say hi;name=hi]
  $paragraph[ ;name=answer]
$endpage
$on[hi.Clicked]
  $setProperty[$get[answer];text;Hi there!]
$endon
naja serve, then open /, /
GET /  →  200
<main class="nj-page">
<button type="button" class="nj-button" data-nj="hi">Say hi</button>
<p class="nj-paragraph" data-nj="answer"></p>
</main>

POST /  →  200
{"changes":[{"part":"answer","what":"text","value":"Hi there!"}]}

$inputwebNaja page

$input[name;label]

In a webNaja page: a field to type in. Settings: type=text|email|password|number|textarea|checkbox, placeholder=, value=, required=yes.

index.wnaj
$page[Sign up]
  $form[method=post]
    $input[email;Your email;type=email;required=yes]
    $button[Join]
  $endform
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<form method="post" class="nj-form">
<label class="nj-field"><span>Your email</span><input type="email" name="email" required class="nj-input" data-nj="email" value=""></label>
<button type="submit" class="nj-button">Join</button>
</form>
</main>

$formwebNaja page

$form ... $endform

In a webNaja page: fields and a button that send to the page (or the path given). Settings: method=post|get, name= for $on[name.Submitted].

index.wnaj
$if[$request[method] == "POST"]
  $redirect[/thanks]
$endif
$page[Contact]
  $form[method=post]
    $input[message;Message;type=textarea]
    $button[Send]
  $endform
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<form method="post" class="nj-form">
<label class="nj-field"><span>Message</span><textarea name="message" class="nj-input" data-nj="message"></textarea></label>
<button type="submit" class="nj-button">Send</button>
</form>
</main>

$themewebNaja page

$theme ... $endtheme

In a webNaja page: the theme's named values, one per line: accent = #a690ff, and page = #0f1017 ; dark for the dark look only.

index.wnaj
$theme
  accent = #6a4cf0
  accent = #a690ff ; dark
  font = Onest
$endtheme
$page[Themed]
  $link[Go;/go;look=primary]
$endpage
naja serve, then open /
GET /  →  200
:root{color-scheme:light dark;--page:#ffffff;--text:#1d1d26;--muted:#5b5b6b;--surface:#f4f3fa;--border:#e3e1ee;--accent:#6a4cf0;--on-accent:#ffffff;--font:Onest, system-ui, sans-serif;--mono:ui-monospace, monospace;--radius:10px;--space:16px;--code-bg:#f7f6fc;--code-call:#5b3fd9;--code-text:#0b7a62;--code-num:#b4541a}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){--page:#0f1017;--text:#ecebf5;--muted:#a3a2b5;--surface:#181926;--border:#2a2b3d;--accent:#a690ff;--on-accent:#0f1017;--code-bg:#14151f;--code-call:#a690ff;--code-text:#46e3c2;--code-num:#f0a46b;--font:Onest, system-ui, sans-serif}}
:root[data-theme="dark"]{color-scheme:dark;--page:#0f1017;--text:#ecebf5;--muted:#a3a2b5;--surface:#181926;--border:#2a2b3d;--accent:#a690ff;--on-accent:#0f1017;--code-bg:#14151f;--code-call:#a690ff;--code-text:#46e3c2;--code-num:#f0a46b;--font:Onest, system-ui, sans-serif}
<main class="nj-page">
<a href="/go" class="nj-button primary">Go</a>
</main>

$stylewebNaja page

$style[name] ... $endstyle

In a webNaja page: a named style parts take with style=name. Lines are name = value (padding, corner, text, background ... or CSS names like margin), and can end with when they count: ; hover, ; phone, ; below 960, ; dark, ; for link.

index.wnaj
$style[card]
  padding = 24
  corner = 12
  background = theme.surface
  border = theme.border
  border-color = theme.accent ; hover
  text = theme.accent ; for link
  padding = 16 ; phone
  box-shadow = 0 0 0 1px theme.border ; dark
$endstyle
$page[Cards]
  $section[Hello;style=card]
    $link[Read more;/more]
  $endsection
$endpage
naja serve, then open /
GET /  →  200
.s-card{padding:24px;border-radius:12px;background:var(--surface);border:1px solid var(--border)}
.s-card a{color:var(--accent)}
.s-card:hover{border-color:var(--accent)}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]) .s-card{box-shadow:0 0 0 1px var(--border)}}
:root[data-theme="dark"] .s-card{box-shadow:0 0 0 1px var(--border)}
@media (max-width:640px){.s-card{padding:16px}}
<main class="nj-page">
<section class="nj-section s-card">
<h2>Hello</h2>
<a href="/more" class="nj-link">Read more</a>
</section>
</main>
A line can end with when it counts: ; hover, ; focus, ; press, ; open, ; current, ; first, ; last, ; odd, ; even, ; before or ; after (a decorative line), ; phone, ; below 960 or ; above 1440 (screen widths), ; still (for people who want less motion), ; dark or ; light, and ; for link (or heading, button, image, item, or another style) for the parts inside. Besides Najova's own names, CSS names like margin, display or line-height work, and their values are checked.

$motionwebNaja page

$motion[name] ... $endmotion

In a webNaja page: an animation styles use with animation = name 0.3s ease. Lines say when: opacity = 0 ; from, opacity = 1 ; to (or ; 50%).

index.wnaj
$motion[fade-in]
  opacity = 0 ; from
  transform = translateY(8px) ; from
  opacity = 1 ; to
  transform = none ; to
$endmotion
$style[hero]
  animation = fade-in 0.4s ease
  animation = none ; still
$endstyle
$page[Welcome]
  $heading[Hello;style=hero]
$endpage
naja serve, then open /
GET /  →  200
@keyframes fade-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
.s-hero{animation:fade-in 0.4s ease}
@media (prefers-reduced-motion:reduce){.s-hero{animation:none}}
<main class="nj-page">
<h1 class="nj-heading s-hero">Hello</h1>
</main>

$fontwebNaja page

$font[name;file]

In a webNaja page: a font file the page uses, like $font[Onest;fonts/onest.woff2;weight=100 900]. Then font = Onest in $theme.

index.wnaj
$font[Onest;fonts/onest.woff2;weight=100 900]
$theme
  font = Onest
$endtheme
$page[Fonts]
  $paragraph[Set in Onest.]
$endpage
naja serve, then open /
GET /  →  200
@font-face{font-family:"Onest";src:url("fonts/onest.woff2") format("woff2");font-weight:100 900;font-style:normal;font-display:swap}
:root{color-scheme:light dark;--page:#ffffff;--text:#1d1d26;--muted:#5b5b6b;--surface:#f4f3fa;--border:#e3e1ee;--accent:#6a4cf0;--on-accent:#ffffff;--font:Onest, system-ui, sans-serif;--mono:ui-monospace, monospace;--radius:10px;--space:16px;--code-bg:#f7f6fc;--code-call:#5b3fd9;--code-text:#0b7a62;--code-num:#b4541a}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){--page:#0f1017;--text:#ecebf5;--muted:#a3a2b5;--surface:#181926;--border:#2a2b3d;--accent:#a690ff;--on-accent:#0f1017;--code-bg:#14151f;--code-call:#a690ff;--code-text:#46e3c2;--code-num:#f0a46b;--font:Onest, system-ui, sans-serif}}
:root[data-theme="dark"]{color-scheme:dark;--page:#0f1017;--text:#ecebf5;--muted:#a3a2b5;--surface:#181926;--border:#2a2b3d;--accent:#a690ff;--on-accent:#0f1017;--code-bg:#14151f;--code-call:#a690ff;--code-text:#46e3c2;--code-num:#f0a46b;--font:Onest, system-ui, sans-serif}
<main class="nj-page">
<p class="nj-paragraph">Set in Onest.</p>
</main>
Put the font file in your site's folder: naja build --web copies it with the pages.

$tabswebNaja page

$tabs ... $endtabs

In a webNaja page: tabs. Each $tab[title] ... $endtab inside is one; the first shows, arrow keys move between them.

index.wnaj
$page[Install]
  $tabs
    $tab[Windows]
      $paragraph[Run the installer.]
    $endtab
    $tab[Linux]
      $paragraph[Unpack the archive.]
    $endtab
  $endtabs
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<div class="nj-tabs">
<div role="tablist"><button type="button" role="tab" id="nj-tabs1-0-b" aria-controls="nj-tabs1-0" aria-selected="true">Windows</button><button type="button" role="tab" id="nj-tabs1-1-b" aria-controls="nj-tabs1-1" aria-selected="false">Linux</button></div>
<div class="nj-tab" role="tabpanel" id="nj-tabs1-0" aria-labelledby="nj-tabs1-0-b" tabindex="0"><h3 class="nj-tab-title">Windows</h3>
<p class="nj-paragraph">Run the installer.</p>
</div>
<div class="nj-tab" role="tabpanel" id="nj-tabs1-1" aria-labelledby="nj-tabs1-1-b" tabindex="0"><h3 class="nj-tab-title">Linux</h3>
<p class="nj-paragraph">Unpack the archive.</p>
</div>
</div>
</main>

$tabwebNaja page

$tab[title] ... $endtab

In a webNaja page: one tab of a $tabs.

index.wnaj
$page[Plans]
  $tabs
    $tab[Free]
      $paragraph[For trying it out.]
    $endtab
    $tab[Team]
      $paragraph[For groups.]
    $endtab
  $endtabs
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<div class="nj-tabs">
<div role="tablist"><button type="button" role="tab" id="nj-tabs1-0-b" aria-controls="nj-tabs1-0" aria-selected="true">Free</button><button type="button" role="tab" id="nj-tabs1-1-b" aria-controls="nj-tabs1-1" aria-selected="false">Team</button></div>
<div class="nj-tab" role="tabpanel" id="nj-tabs1-0" aria-labelledby="nj-tabs1-0-b" tabindex="0"><h3 class="nj-tab-title">Free</h3>
<p class="nj-paragraph">For trying it out.</p>
</div>
<div class="nj-tab" role="tabpanel" id="nj-tabs1-1" aria-labelledby="nj-tabs1-1-b" tabindex="0"><h3 class="nj-tab-title">Team</h3>
<p class="nj-paragraph">For groups.</p>
</div>
</div>
</main>

$sheetwebNaja page

$sheet[column;column...] ... $endsheet

In a webNaja page: a table with the columns named, and a $cells[...] line for each row.

index.wnaj
$page[Prices]
  $sheet[Plan;Price]
    $cells[Free;0]
    $cells[Team;12 a month]
  $endsheet
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<div class="nj-sheet"><table><thead><tr><th scope="col">Plan</th><th scope="col">Price</th></tr></thead><tbody>
<tr><td>Free</td><td>0</td></tr>
<tr><td>Team</td><td>12 a month</td></tr>
</tbody></table></div>
</main>

$cellswebNaja page

$cells[value;value...]

In a webNaja page: one row of a $sheet.

index.wnaj
$page[Scores]
  $sheet[Player;Score]
    $each[p;$list[Sam;Ada]]
      $cells[$get[p];$random[1;100]]
    $endeach
  $endsheet
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<div class="nj-sheet"><table><thead><tr><th scope="col">Player</th><th scope="col">Score</th></tr></thead><tbody>
<tr><td>Sam</td><td>81</td></tr>
<tr><td>Ada</td><td>37</td></tr>
</tbody></table></div>
</main>
Each visit picks new random scores.

$codewebNaja page

$code[code;file=name]

In a webNaja page: a code panel with Najova code coloured, the file name on top and a Copy button. lang=plain shows other text as it is.

index.wnaj
$page[Hello]
  $code["$print[Hello, world!]";file=hello.naja]
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<figure class="nj-code"><figcaption>hello.naja</figcaption><pre><code><span class="t-call">$print</span><span class="t-punct">[</span>Hello, world<span class="t-op">!</span><span class="t-punct">]</span></code></pre><button type="button" class="nj-copy">Copy</button></figure>
</main>
Code from a file or a value keeps its ; and [ ]: $code[$readFile[hello.naja];file=hello.naja].

$themePickwebNaja page

$themePick[light text;dark text]

In a webNaja page: Light and Dark buttons; the pick is remembered, else the computer's look is used.

index.wnaj
$page[Settings]
  $themePick
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<div class="nj-theme" role="group" aria-label="Light or dark"><button type="button" data-theme-set="light" aria-pressed="false">Light</button><button type="button" data-theme-set="dark" aria-pressed="false">Dark</button></div>
</main>
Until someone picks, the page follows the computer's light or dark look.

$markdownwebNaja page

$markdown[text or file.md]

In a webNaja page: Markdown as page parts: # headings, lists, tables, > quotes and ``` code (Najova coloured). Give the text, or a .md file in the site's folder. level=3 makes a # heading an h3 (2 if not set).

index.wnaj
$page[About]
  $markdown["# Bots

Make **bots** with `$slash`.

- Fast
- Small"]
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<div class="nj-markdown"><p>&quot;# Bots</p>
<p>Make <strong>bots</strong> with <code>$slash</code>.</p>
<ul><li>Fast</li><li>Small&quot;</li></ul>
</div>
</main>
Give a .md file in the site's folder to show it: $markdown[README.md]. $paragraph, $heading and $cells take the same marks inside a line: `code`, **bold**, *italic* and [text](/address). There, a $name with no [ after it stays text.

$childrenwebNaja page

$children

In a $function: where the parts written inside it go. Then $card[Title] ... $endcard holds other parts, like $section does.

index.wnaj
$function[card;title]
  $section[$get[title];style=card]
    $children
  $endsection
$endfunction
$page[Cards]
  $card[Fast]
    $paragraph[Starts in a blink.]
  $endcard
$endpage
naja serve, then open /
GET /  →  200
<main class="nj-page">
<section class="nj-section s-card">
<h2>Fast</h2>
<p class="nj-paragraph">Starts in a blink.</p>
</section>
</main>
A $function with $children in it holds other parts: $card[...] ... $endcard. Once a page has $endcard, every $card in it is closed with one.