Monorepo for Aesthetic.Computer
aesthetic.computer
1#!/usr/bin/env node
2
3// Simple Node.js script to encode kidlisp using the same function as kidlisp.mjs
4// Usage: node encode_kidlisp.mjs "your kidlisp code here"
5
6import { readFileSync } from 'fs';
7import { dirname, join } from 'path';
8import { fileURLToPath } from 'url';
9
10// Try to import the actual encodeKidlispForUrl function from kidlisp.mjs
11let encodeKidlispForUrl;
12
13try {
14 // Attempt to load the actual kidlisp.mjs module
15 const __dirname = dirname(fileURLToPath(import.meta.url));
16 const kidlispPath = join(__dirname, '../system/public/aesthetic.computer/lib/kidlisp.mjs');
17
18 // Since kidlisp.mjs may not export the function, we'll use our own implementation
19 // that matches the original exactly, plus handles quotes properly for URLs
20 encodeKidlispForUrl = function(source) {
21 // First do the basic encoding like kidlisp.mjs
22 let encoded = source.replace(/ /g, "_").replace(/\n/g, "~");
23
24 // Then encode quotes for URL safety (this is what browsers do automatically)
25 encoded = encoded.replace(/"/g, "%22");
26
27 return encoded;
28 };
29} catch (error) {
30 // Fallback implementation
31 encodeKidlispForUrl = function(source) {
32 const encoded = source.replace(/ /g, "_").replace(/\n/g, "~");
33 return encoded;
34 };
35}
36
37// Get the kidlisp code from command line arguments
38const args = process.argv.slice(2);
39if (args.length === 0) {
40 console.error("Usage: node encode_kidlisp.mjs \"kidlisp code\" [baseUrl]");
41 process.exit(1);
42}
43
44const kidlispCode = args[0];
45const baseUrl = args[1] || 'https://localhost:8888';
46const encoded = encodeKidlispForUrl(kidlispCode);
47
48// Construct full URL with parameters
49const fullUrl = `${baseUrl}/${encoded}?nolabel=true&nogap=true`;
50console.log(fullUrl);