Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ const demoDecks = [
type: 'demo',
external: true,
url: 'public/demo/branch-prediction/index.html',
links: [
{
url: 'public/demo/index.html?search=branch-prediction',
external: false,
translations: {
en: 'View in directory tree',
zh: '在目录树中查看'
}
}
],
translations: {
en: {
title: 'Branch Prediction Lab',
Expand All @@ -197,6 +207,16 @@ const demoDecks = [
type: 'demo',
external: true,
url: 'public/demo/compute-god-standard-model-validator/index.html',
links: [
{
url: 'public/demo/index.html?search=compute-god-standard-model-validator',
external: false,
translations: {
en: 'View in directory tree',
zh: '在目录树中查看'
}
}
],
translations: {
en: {
title: 'Compute-God Validator',
Expand All @@ -221,6 +241,16 @@ const demoDecks = [
type: 'demo',
external: true,
url: 'public/demo/agi-asi-reaction-chamber/index.html',
links: [
{
url: 'public/demo/index.html?search=agi-asi-reaction-chamber',
external: false,
translations: {
en: 'View in directory tree',
zh: '在目录树中查看'
}
}
],
translations: {
en: {
title: 'AGI / ASI Reaction Chamber',
Expand All @@ -245,6 +275,16 @@ const demoDecks = [
type: 'demo',
external: true,
url: 'public/demo/ambient-sketch/index.html',
links: [
{
url: 'public/demo/index.html?search=ambient-sketch',
external: false,
translations: {
en: 'View in directory tree',
zh: '在目录树中查看'
}
}
],
translations: {
en: {
title: 'Ambient Music Sketch',
Expand Down
37 changes: 32 additions & 5 deletions public/demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ const metaEl = document.getElementById('demoMeta');
let treeData = [];
let totalDemoCount = 0;

function getInitialQuery() {
const params = new URLSearchParams(window.location.search);
return params.get('search') || params.get('q') || '';
}

function updateUrlQuery(query) {
const params = new URLSearchParams(window.location.search);
if (query) {
params.set('search', query);
} else {
params.delete('search');
params.delete('q');
}

const newQuery = params.toString();
const newUrl = `${window.location.pathname}${newQuery ? `?${newQuery}` : ''}${window.location.hash}`;
window.history.replaceState(null, '', newUrl);
}

async function fetchDemoTree() {
const response = await fetch('demo-tree.json', { cache: 'no-store' });
if (!response.ok) {
Expand Down Expand Up @@ -194,6 +213,13 @@ function updateStatus(query, visibleNodes) {
}
}

function applyQuery(query) {
const filtered = filterTree(treeData, query);
renderTree(filtered, query);
updateStatus(query, filtered);
updateUrlQuery(query);
}

function updateMeta(nodes) {
const directoryCount = nodes.length;
metaEl.innerHTML = '';
Expand All @@ -216,8 +242,11 @@ async function initialise() {
treeData = data;
totalDemoCount = treeData.reduce((total, node) => total + countDemos(node), 0);
updateMeta(treeData);
renderTree(treeData, '');
updateStatus('', treeData);
const initialQuery = getInitialQuery();
if (initialQuery) {
searchInput.value = initialQuery;
}
applyQuery(initialQuery);
treeContainer.hidden = false;
} catch (error) {
console.error(error);
Expand All @@ -227,9 +256,7 @@ async function initialise() {

searchInput.addEventListener('input', (event) => {
const query = event.target.value.trim();
const filtered = filterTree(treeData, query);
renderTree(filtered, query);
updateStatus(query, filtered);
applyQuery(query);
});
}

Expand Down