Skip to content

Docs menu // site

[ SDK ] /docs/sdk/site

site

The page, its content, and how scripts plug into it.

import
import site from "site"

Modelled on Rex's Lua API: a script registers actions (they show up in the command palette and can be bound to keys), listens for events, and changes the page. Look changes made at the top level describe the whole customisation: each run starts from the default page. Handlers, timers and actions stay alive after the script's last line until the next run.

Limits. A run or dispatch faults with a runtime error, never silently truncated, when it passes any of these:

note
- a string argument over 2048 bytes, an array argument over 256 elements
  (the page clamps text far lower: toasts to 160 characters, and so on)
- more than 10,000 calls that change the page, or 512 KiB of them
- 2,000,000 steps (loop turns and calls), 16 MB of script memory, at most
  256 live callbacks
- more than 40,000 units of host calls: a call costs 1, reading
  site.projects costs 20 because it copies every project. Read it once.
- native work counts as steps too: an array insert or remove moves one
  step per 16 elements, a string search or count one step per 32 bytes

Every dispatch starts with fresh allowances.

Values#

ValueDescription
let projects: []ProjectEvery project on this site, in the order of the portfolio data.
let time: TimeThe time in the Maldives (UTC+5) when the script or callback started.
let visits: i64page loads that replayed a saved script, this one included

Functions#

Commands and events#

SignatureDescription
fn action(spec: Action) -> voidRegisters a command. It appears in the command palette and can be bound to a key; the callback runs each time it is invoked.
fn invoke(name: string) -> voidrun any action by name
fn on(event: string, handler: ?fn(Event) -> void) -> voidThe handler is optional only because a host function cannot take a plain function value with a struct parameter; a lambda converts implicitly, and a null handler is a fault.
fn stop() -> voiddrop this script's actions, handlers, bindings and timers

Content#

SignatureDescription
fn title(text: string) -> voidthe large name in the hero
fn order(slugs: []string) -> voidproject order, unlisted ones follow
fn hide(slug: string) -> voidHides a project card. An unknown slug is ignored.
fn highlight(slug: string) -> voidLights up a project card with a frame. An unknown slug is ignored.
fn badge(slug: string, text: string) -> voida small tag on a project card
fn readout(label: string, value: string) -> voida row in the SYS.READOUT panel (same label replaces)
fn goto(section: string) -> voidscroll to "top", "work", "log", "systems" or "contact"
fn open(slug: string) -> voidgo to a project page
fn print(text: string) -> voidconsole output

Types#

enum Status#

.Active.Shipped.Experiment.Archived

struct Project#

FieldTypeNotes
slugstring
namestring
kindstring
yeari64
statusStatus
featuredbool
stack[]string

struct Time#

FieldTypeNotes
houri640-23, Maldives time (UTC+5)
minutei64
secondi64
weekdayi640 is Sunday

struct Event#

What happened, for site.on handlers. Fields that do not apply are null.

note
"project.hover"  "project.leave"  "project.click"   slug
"section"        a section scrolled into view        section
"key"            a key nobody bound was pressed       key ("shift+g")
"idle"           no input for 30 seconds
"active"         input again after idle
"visible" "hidden"  the tab was shown or hidden
"konami"         up up down down left right left right b a
FieldTypeNotes
namestring
slug?string
section?string
key?string
xf64pointer position, 0-1 across the viewport
yf64

struct Action#

A command, in the spirit of rex.action. Script action names are lowercase letters, digits and underscores (no dots: dotted names are built in, such as "console.open", "look.reset", "go.vyr", "section.work").

FieldTypeNotes
namestring
titlestringshown in the command palette
descriptionstring
categorystringpalette group, "" means "Script"
keywords[]string
runfn() -> void

Examples#

Changing the content
import site from "site"

site.title("hello")
site.order(["eitri", "vyr"])
site.highlight("eitri")
site.badge("eitri", "MINE")
site.hide("helix-rpc")
site.readout("PROJECTS", "${site.projects.len()}")
site.print("visit number ${site.visits}")
Actions and invoke
import site from "site"

site.action(site.Action {
    name: "ping",
    title: "Ping",
    description: "Print one line",
    category: "Docs",
    keywords: ["test"],
    run: () => site.print("pong"),
})

site.action(site.Action {
    name: "ping_twice",
    title: "Ping twice",
    description: "Run the ping action two times",
    category: "Docs",
    keywords: [],
    run: () => {
        site.invoke("ping")
        site.invoke("ping")
    },
})
Events
import site from "site"

site.on("section", e => {
    if let name = e.section {
        site.readout("SECTION", name)
    }
})

site.on("key", e => {
    if let k = e.key {
        site.print("unbound key: ${k}")
    }
})

site.on("idle", e => site.print("idle for 30 seconds"))
Going places
import site from "site"

site.action(site.Action {
    name: "tour",
    title: "Open the first project",
    description: "Scroll to the work section, then open a project",
    category: "Docs",
    keywords: [],
    run: () => {
        site.goto("work")
        site.open("eitri")
    },
})
Stopping a script
import site from "site"
import time from "site/time"

time.every(5000, () => site.print("tick"))

site.action(site.Action {
    name: "quiet",
    title: "Stop the script",
    description: "Drop the timer and this action",
    category: "Docs",
    keywords: [],
    run: () => site.stop(),
})

Limits#

  • Script action names are lowercase letters, digits and underscores, up to 32 characters. At most 64 actions; titles are cut to 48 characters, descriptions to 120, categories to 24, and each action keeps up to 8 keywords of 24 characters.
  • At most 16 handlers per event. The events are project.hover, project.leave, project.click, section, key, idle, active, visible, hidden and konami. Noisy events are rate limited: project.hover to 10 a second per project, the others to 20 a second.
  • The hero title is cut to 24 characters. The readout panel has 8 rows (labels 16 characters, values 40); a row with the same label, ignoring case, is replaced. A project card carries up to 3 badges of 12 characters.
  • Slugs that do not match a project are ignored by order, hide, highlight, badge and open.
  • The console keeps the last 500 lines of output.

Declaration file#

This page is generated from the file below, served as /eitri/sdk/site.eith. Types and signatures are exactly what the compiler checks scripts against. Back to all modules.

site.eith
// site: the page, its content, and how scripts plug into it.
//
// Modelled on Rex's Lua API: a script registers actions (they show up in the
// command palette and can be bound to keys), listens for events, and changes
// the page. Look changes made at the top level describe the whole
// customisation: each run starts from the default page. Handlers, timers and
// actions stay alive after the script's last line until the next run.
//
// Limits. A run or dispatch faults with a runtime error, never silently
// truncated, when it passes any of these:
//   - a string argument over 2048 bytes, an array argument over 256 elements
//     (the page clamps text far lower: toasts to 160 characters, and so on)
//   - more than 10,000 calls that change the page, or 512 KiB of them
//   - 2,000,000 steps (loop turns and calls), 16 MB of script memory, at most
//     256 live callbacks
//   - more than 40,000 units of host calls: a call costs 1, reading
//     site.projects costs 20 because it copies every project. Read it once.
//   - native work counts as steps too: an array insert or remove moves one
//     step per 16 elements, a string search or count one step per 32 bytes
// Every dispatch starts with fresh allowances.

pub enum Status {
    Active
    Shipped
    Experiment
    Archived
}

pub struct Project {
    pub slug: string
    pub name: string
    pub kind: string
    pub year: i64
    pub status: Status
    pub featured: bool
    pub stack: []string
}

pub struct Time {
    pub hour: i64       // 0-23, Maldives time (UTC+5)
    pub minute: i64
    pub second: i64
    pub weekday: i64    // 0 is Sunday
}

// What happened, for site.on handlers. Fields that do not apply are null.
//   "project.hover"  "project.leave"  "project.click"   slug
//   "section"        a section scrolled into view        section
//   "key"            a key nobody bound was pressed       key ("shift+g")
//   "idle"           no input for 30 seconds
//   "active"         input again after idle
//   "visible" "hidden"  the tab was shown or hidden
//   "konami"         up up down down left right left right b a
pub struct Event {
    pub name: string
    pub slug: ?string
    pub section: ?string
    pub key: ?string
    pub x: f64          // pointer position, 0-1 across the viewport
    pub y: f64
}

// A command, in the spirit of rex.action. Script action names are lowercase
// letters, digits and underscores (no dots: dotted names are built in, such
// as "console.open", "look.reset", "go.vyr", "section.work").
pub struct Action {
    pub name: string
    pub title: string           // shown in the command palette
    pub description: string
    pub category: string        // palette group, "" means "Script"
    pub keywords: []string
    pub run: fn() -> void
}

// What the page knows.
pub let projects: []Project
pub let time: Time
pub let visits: i64     // page loads that replayed a saved script, this one included

// Commands and events.
pub fn action(spec: Action) -> void
pub fn invoke(name: string) -> void                     // run any action by name
// The handler is optional only because a host function cannot take a plain
// function value with a struct parameter; a lambda converts implicitly, and a
// null handler is a fault.
pub fn on(event: string, handler: ?fn(Event) -> void) -> void
pub fn stop() -> void                                   // drop this script's actions, handlers, bindings and timers

// Content.
pub fn title(text: string) -> void          // the large name in the hero
pub fn order(slugs: []string) -> void       // project order, unlisted ones follow
pub fn hide(slug: string) -> void
pub fn highlight(slug: string) -> void
pub fn badge(slug: string, text: string) -> void    // a small tag on a project card
pub fn readout(label: string, value: string) -> void // a row in the SYS.READOUT panel (same label replaces)
pub fn goto(section: string) -> void        // scroll to "top", "work", "log", "systems" or "contact"
pub fn open(slug: string) -> void           // go to a project page
pub fn print(text: string) -> void          // console output