File size: 1,558 Bytes
46a6b71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32f12c3
 
 
 
 
 
 
 
 
 
 
 
 
 
46a6b71
 
 
 
32f12c3
 
 
46a6b71
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Function to load and render JSON into a specific element
async function renderJSON(filePath, elementId) {
    try {
        const response = await fetch(filePath);
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        const data = await response.json();

        // Convert JSON object back to a beautifully formatted string
        // The 'null, 4' adds the necessary indentation/whitespace
        document.querySelector(`#${elementId} pre`).textContent = JSON.stringify(data, null, 4);
    } catch (error) {
        console.error(`Could not load ${filePath}:`, error);
        document.querySelector(`#${elementId} pre`).textContent = `Error loading data.`;
    }
}

async function render_text(filePath, elementId) {
    try {
        const response = await fetch(filePath);
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        const text = await response.text();
        document.querySelector(`#${elementId} pre`).textContent = text;
    } catch (error) {
        console.error(`Could not load ${filePath}:`, error);
        document.querySelector(`#${elementId} pre`).textContent = `Error loading data.`;
    }
}

// Call the function for both of your files
document.addEventListener("DOMContentLoaded", e => {
    renderJSON('./state.json', 'state');
    renderJSON('./identity.json', 'identity');
    render_text("./tables.sql", "sql")
    render_text("concept.txt", 'concept')
    render_text('concept.py', 'python')
})