Skip to content

Commit

Permalink
Merge pull request #2 from LyonSyonII/dev
Browse files Browse the repository at this point in the history
Fix #1
  • Loading branch information
LyonSyonII authored Jun 16, 2024
2 parents 4933c4f + 9545528 commit a901592
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ jobs:
with:
node-version: latest
cache: 'pnpm'
cache-dependency-path: frontend/pnpm-lock.yaml
cache-dependency-path: example/pnpm-lock.yaml
- name: Install dependencies and Build
run: |
cd example
mv astro.config.preview.mjs astro.config.mjs
pnpm install
pnpm build
- uses: afc163/surge-preview@v1
Expand Down
14 changes: 14 additions & 0 deletions example/astro.config.preview.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'astro/config';
import compress from "astro-compress";

import compressor from "astro-compressor";

// https://astro.build/config
export default defineConfig({
// site: "https://garriga.dev",
// base: "/rubri",
integrations: [compress(), compressor({
brotli: false,
fileExtensions: [".css", ".js", ".html", ".xml", ".cjs", ".mjs", ".svg", ".txt"]
})]
});
7 changes: 5 additions & 2 deletions example/src/interpreter/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function initInterpreter(): Promise<Interpreter> {
"-Zmir-emit-retag=false",
"-Zmiri-disable-isolation",
"-Zmiri-panic-on-unsupported",
"--color=always"
"--color=always",
];
const wasi = new WASI(args, env, fds, { debug: false });

Expand Down Expand Up @@ -150,7 +150,10 @@ async function load_external_file(path: string) {
async function cached_or_fetch(path: string) {
// Downloads or caches the file from `path`
// Files of more than 10MB aren't cached by fetch, so it must be done manually
path = import.meta.env.BASE_URL + path;
const base = import.meta.env.BASE_URL === "/" ? "" : import.meta.env.BASE_URL;
console.log({base, url: import.meta.url, path});

path = base + path;
try {
caches
} catch (e) {
Expand Down
10 changes: 8 additions & 2 deletions example/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
const base = import.meta.env.BASE_URL === "/" ? "" : import.meta.env.BASE_URL;
---

<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/rubri/favicon.svg" />
<link rel="icon" type="image/svg+xml" href={ base + "/favicon.svg" } />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Rust Browser Interpreter</title>
Expand Down Expand Up @@ -77,6 +78,7 @@
input.readOnly = true;

// Interpreter initialization
let lastInput = "";
const interpreter = new Interpreter();

// Add libraries downloaded to list
Expand All @@ -99,13 +101,17 @@
interpreter.onResult(result => {
termElement.innerHTML = ansiUp.ansi_to_html(result.replaceAll("\n", "\r"));
button.disabled = false;
if (lastInput && lastInput !== input.value) {
input.dispatchEvent(new Event("input"));
}
});

// Run the Interpreter when on "Live Edit" or the "Run" button is clicked
input.addEventListener("input", async () => {
if (!liveEdit.checked || button.disabled) {
return;
}
lastInput = input.value;
interpreter.run(input.value || "");
});
button.addEventListener("click", async () => {
Expand Down

0 comments on commit a901592

Please sign in to comment.