diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/index.html | 7 | ||||
-rw-r--r-- | examples/isRoute.js | 3 | ||||
-rw-r--r-- | examples/src.js | 11 |
3 files changed, 21 insertions, 0 deletions
diff --git a/examples/index.html b/examples/index.html new file mode 100644 index 000000000..3bb25f55e --- /dev/null +++ b/examples/index.html @@ -0,0 +1,7 @@ +<!DOCTYPE html> +<html> + <head> + <script type="module" src="REPLACE_ME"></script> + </head> + <body></body> +</html> diff --git a/examples/isRoute.js b/examples/isRoute.js new file mode 100644 index 000000000..d1717a0e9 --- /dev/null +++ b/examples/isRoute.js @@ -0,0 +1,3 @@ +export function isRoute(expr, env) { + return env.url.pathname.includes(expr.arguments[0].toString()); +} diff --git a/examples/src.js b/examples/src.js new file mode 100644 index 000000000..ad9fda6f4 --- /dev/null +++ b/examples/src.js @@ -0,0 +1,11 @@ +import { getProducts } from "macro:./getProducts.js"; +import { isRoute } from "macro:./isRoute.js"; + +if (isRoute("/rickroll")) { + document.body.innerHTML = `<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ?autoplay=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>`; +} else if (isRoute("/products")) { + const products = getProducts({ ProductName: "name", Id: "id" }); + document.body.innerHTML = `<ul>${products + .map(({ name, id }) => `<li>${name}</li>`) + .join("")}</ul>`; +} |