Origami comics

How paths find files

Origami expressions can directly refer to files using inline paths - but how do those paths work?

site.ori
// An Origami inline path can find a file further up the folder tree
{
  index.html: `Hello from ${ package.json/name }!`
}
site.js
// JavaScript needs a file import with an explicit relative path
import packageJson from "../../package.json" with { type: "json" };

export default {
  "index.html": `Hello from ${packageJson.name}!`,
};

JavaScript and Origami resolve variable references using a scope, searching up until they find the variable.

sumTo.js
// Return the sum of 1 to n
export default function sumTo(n) {
  let total = 0;
  for (let i = 1; i <= n; i++) {
    // Both these references search up to find the closest declaration
    total += i;
  }
  return total;
}

But Origami extends its scope to the file system, searching up the folder tree until it finds a file.

The package.json file is one level above this folder:

$ cat ../package.json
{
  "name": "my-origami-project",
  "type": "module"
}

Origami can still find it by searching parent folders:

$ ori package.json
{
  "name": "my-origami-project",
  "type": "module"
}

Your file paths can be concise and still find exactly the right file!

site.ori
// An Origami inline path can find a file further up the folder tree
{
  index.html: `Hello from ${ package.json/name }!`
}
$ ori src/site.ori/
index.html: Hello from my-origami-project!
$

Read more: Scope in Origami expressions

  Comic index