mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-19 08:07:51 -06:00
chore: merge origin/main
install/games regenerated over both sides.
This commit is contained in:
commit
2589099f2d
72 files changed
+840
-52
No files matched your search
@@ -3,6 +3,7 @@
|
||||
// the components and the styles.
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { copyFile } from 'node:fs/promises';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { defineConfig } from 'astro/config';
|
||||
import starlight from '@astrojs/starlight';
|
||||
@@ -36,6 +37,21 @@ const readRedirects = () => {
|
||||
};
|
||||
|
||||
// The sitemap keeps the address MkDocs gave it: sitemap.xml, beside the index.
|
||||
// Each page as Markdown beside its HTML, and llms-full.txt, written from the
|
||||
// built pages by scripts/site_markdown.py: what an assistant reads to help a
|
||||
// reader. Every page's head names its copy (rel="alternate" below), so a
|
||||
// build that cannot write them fails rather than link to nothing.
|
||||
const markdownCopies = {
|
||||
name: 'retrobios-markdown',
|
||||
hooks: {
|
||||
'astro:build:done': ({ dir }) => {
|
||||
const script = fileURLToPath(new URL('../scripts/site_markdown.py', import.meta.url));
|
||||
const run = spawnSync(process.env.PYTHON || 'python3', [script, fileURLToPath(dir)], { stdio: 'inherit' });
|
||||
if (run.status !== 0) throw new Error(`site_markdown.py exited with ${run.status ?? run.error}`);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const sitemapAlias = {
|
||||
name: 'retrobios-sitemap-alias',
|
||||
hooks: {
|
||||
@@ -80,6 +96,8 @@ export default defineConfig({
|
||||
// What an AI agent reads first (scripts/siteagents.py): the ARD manifest lists
|
||||
// llms.txt and the JSON API.
|
||||
{ tag: 'link', attrs: { rel: 'ard', type: 'application/json', href: `${BASE}ard.json` } },
|
||||
// The page as Markdown (scripts/site_markdown.py), beside its index.html.
|
||||
{ tag: 'link', attrs: { rel: 'alternate', type: 'text/markdown', href: 'index.md' } },
|
||||
],
|
||||
social: [{ icon: 'github', label: 'RetroBIOS on GitHub', href: 'https://github.com/Abdess/retrobios' }],
|
||||
customCss: ['./src/styles/retrobios.css'],
|
||||
@@ -162,5 +180,6 @@ export default defineConfig({
|
||||
},
|
||||
}),
|
||||
sitemapAlias,
|
||||
markdownCopies,
|
||||
],
|
||||
});
|
||||
@@ -117,6 +117,68 @@ const searchSite: Tool = {
|
||||
},
|
||||
};
|
||||
|
||||
// What a setup reads, from the data the file picker reads
|
||||
// (data/picker/<setup>.json, written by scripts/generate_site.py): the BIOS
|
||||
// folder and, per system, each file's exact name and size. An assistant
|
||||
// that answers from it names no file and no folder the data does not hold.
|
||||
type PickerIndex = { platform: string; name: string; files: number }[];
|
||||
type PickerSystem = { id: string; title: string; native: string[] };
|
||||
type PickerData = { platform: string; name: string; folder: string; systems: PickerSystem[]; files: [string, number, number[]][] };
|
||||
|
||||
const words = (text: string) => text.toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
|
||||
|
||||
const setupFiles: Tool = {
|
||||
name: 'setup_bios_files',
|
||||
description:
|
||||
'The BIOS folder of a setup (RetroArch, Batocera, EmuDeck, RetroBat, Recalbox, KNULLI, ROCKNIX, AmberELEC, MiSTer and others) '
|
||||
+ 'and the exact file names it reads for a system, from the site\'s data. Use it instead of guessing a folder or a file name: names '
|
||||
+ 'are case-sensitive and must not be renamed.',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
setup: { type: 'string', description: 'The setup, for example "batocera", "RetroArch" or "EmuDeck".' },
|
||||
system: { type: 'string', description: 'A system, for example "PlayStation 2", "psx" or "gba". Without it, the systems are listed.' },
|
||||
},
|
||||
required: ['setup'],
|
||||
},
|
||||
annotations: { readOnlyHint: true },
|
||||
async execute({ setup, system }) {
|
||||
const asked = words(String(setup ?? ''));
|
||||
const index = await json<PickerIndex>('data/picker/index.json');
|
||||
const found = index.find((item) => item.platform === asked.replace(/ /g, '') || words(item.name) === asked);
|
||||
if (!found) return `No setup named "${String(setup)}". Setups: ${index.map((item) => item.name).join(', ')}.`;
|
||||
const data = await json<PickerData>(`data/picker/${found.platform}.json`);
|
||||
const page = absolute(`${BASE}platforms/${found.platform}/`);
|
||||
// RetroArch and EmuDeck keep no single folder: it depends on the device.
|
||||
const folder = data.folder || `Depends on the device and its system: ${page}#where-the-files-go`;
|
||||
const wanted = words(String(system ?? ''));
|
||||
if (!wanted) {
|
||||
return JSON.stringify({ setup: data.name, bios_folder: folder, page,
|
||||
systems: data.systems.map((item) => ({ id: item.id, title: item.title })) }, null, 1);
|
||||
}
|
||||
const matches = data.systems
|
||||
.map((item, position) => ({ item, position }))
|
||||
.filter(({ item }) => [item.id, item.title, ...item.native].some((name) => {
|
||||
const said = words(name);
|
||||
return said === wanted || said.split(' ').includes(wanted) || said.includes(wanted);
|
||||
}));
|
||||
if (!matches.length) return `${data.name} lists no system matching "${String(system)}". Call again without system to list them.`;
|
||||
const positions = new Set(matches.map(({ position }) => position));
|
||||
const files = data.files.filter(([, , systems]) => systems.some((position) => positions.has(position)));
|
||||
return JSON.stringify({
|
||||
setup: data.name,
|
||||
bios_folder: folder,
|
||||
systems: matches.map(({ item }) => item.title),
|
||||
note: 'Every file the emulators of this setup read for these systems: an emulator reads only some of them '
|
||||
+ '(its page names them, emulator_bios_files lists them). Keep each name exactly as written.',
|
||||
files: files.slice(0, 200).map(([name, bytes]) => ({ name, bytes })),
|
||||
more: Math.max(files.length - 200, 0),
|
||||
page,
|
||||
install: 'device_setup_command gives the command that installs and checks these files.',
|
||||
}, null, 1);
|
||||
},
|
||||
};
|
||||
|
||||
// The command an agent runs to set up its user's device, from the same
|
||||
// options wiki/installer.md documents: the fewest files the games on the
|
||||
// card need, unless the user asks for everything.
|
||||
@@ -177,7 +239,7 @@ const setupCommand: Tool = {
|
||||
|
||||
const context = (document as Document & { modelContext?: ModelContext }).modelContext;
|
||||
if (context?.registerTool) {
|
||||
for (const tool of [setupCommand, lookupHash, emulatorFiles, searchSite]) {
|
||||
for (const tool of [setupCommand, setupFiles, lookupHash, emulatorFiles, searchSite]) {
|
||||
Promise.resolve(context.registerTool(tool)).catch((error) => console.warn(`WebMCP: ${tool.name}:`, error));
|
||||
}
|
||||
}
|
||||
+135
-11
@@ -1282,19 +1282,142 @@ const filterFiles = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// The 404 page: a search button, and the list a moved page belongs to.
|
||||
// "Start with" names the file to get first and links its card, where the
|
||||
// download is. A console's first file is the most downloaded of the site
|
||||
// (the PS2's: 436 in three days): its download sits beside its name too,
|
||||
// the card's own link reused, never a second address.
|
||||
const startDownloads = () => {
|
||||
for (const strong of document.querySelectorAll<HTMLElement>('.sl-markdown-content strong')) {
|
||||
if (strong.textContent?.trim() !== 'Start with') continue;
|
||||
const block = strong.closest('p')?.nextElementSibling?.matches('ul') && !strong.closest('p')?.querySelector('a[href^="#sha1-"]')
|
||||
? strong.closest('p')!.nextElementSibling!
|
||||
: strong.closest('p');
|
||||
for (const named of block?.querySelectorAll<HTMLAnchorElement>('a[href^="#sha1-"]') ?? []) {
|
||||
const card = document.getElementById(named.hash.slice(1))?.closest('.rb-sys-file');
|
||||
const source = card?.querySelector<HTMLAnchorElement>('a.rb-download');
|
||||
if (!source || named.nextElementSibling?.classList.contains('rb-start-download')) continue;
|
||||
const download = document.createElement('a');
|
||||
download.className = 'rb-start-download';
|
||||
download.href = source.href;
|
||||
download.textContent = 'Download';
|
||||
download.setAttribute('aria-label', source.getAttribute('aria-label') ?? 'Download');
|
||||
named.after(' ', download);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// The 404 page: a search button, and what the address it was asked for
|
||||
// looks like. The addresses readers reached (counted, wiki/privacy.md): a
|
||||
// command pasted as a link (/i.ps1%20%7C%20iex), a file name under files/,
|
||||
// a GitHub path (/blob/main/bios), a section below a page
|
||||
// (/platforms/emudeck/install). The address is only ever set as text.
|
||||
const INSTALL_COMMANDS: [string, string][] = [
|
||||
['Windows (PowerShell)', 'irm https://abdess.github.io/retrobios/i.ps1 | iex'],
|
||||
['Linux, macOS, Steam Deck, handhelds', 'curl -fsSL https://abdess.github.io/retrobios/i | sh'],
|
||||
];
|
||||
|
||||
const openSearch = (query = '') => {
|
||||
document.querySelector<HTMLButtonElement>('site-search button[data-open-modal]')?.click();
|
||||
if (!query) return;
|
||||
// The search box exists once the search has loaded: fill it then.
|
||||
const fill = (tries: number) => {
|
||||
const input = document.querySelector<HTMLInputElement>('.pagefind-ui__search-input');
|
||||
if (input) {
|
||||
input.value = query;
|
||||
input.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
} else if (tries > 0) {
|
||||
setTimeout(() => fill(tries - 1), 100);
|
||||
}
|
||||
};
|
||||
fill(30);
|
||||
};
|
||||
|
||||
const hintLine = (...parts: (string | Node)[]) => {
|
||||
const line = document.createElement('p');
|
||||
line.append(...parts);
|
||||
return line;
|
||||
};
|
||||
|
||||
const notFound = () => {
|
||||
document.querySelector('[data-rb-open-search]')?.addEventListener('click', () => {
|
||||
document.querySelector<HTMLButtonElement>('site-search button[data-open-modal]')?.click();
|
||||
});
|
||||
document.querySelector('[data-rb-open-search]')?.addEventListener('click', () => openSearch());
|
||||
const hint = document.getElementById('rb-notfound-hint');
|
||||
const match = location.pathname.match(/\/(emulators|systems|platforms)\/([^/]+)\/?$/);
|
||||
if (!hint || !match) return;
|
||||
const link = document.createElement('a');
|
||||
link.href = new URL(`${match[1]}/`, siteRoot()).href;
|
||||
link.textContent = `the list of ${match[1]}`;
|
||||
hint.append(`No page is named ${decodeURIComponent(match[2])} here. It may be listed under another name in `, link, '.');
|
||||
hint.hidden = false;
|
||||
if (!hint) return;
|
||||
const base = siteRoot().pathname;
|
||||
let rest = location.pathname.startsWith(base) ? location.pathname.slice(base.length) : location.pathname;
|
||||
try {
|
||||
rest = decodeURIComponent(rest);
|
||||
} catch {
|
||||
// A malformed escape stays as typed.
|
||||
}
|
||||
const show = (...lines: HTMLElement[]) => {
|
||||
hint.replaceChildren(...lines);
|
||||
hint.hidden = false;
|
||||
};
|
||||
|
||||
// A command that a chat or a forum turned into a link.
|
||||
if (/^i(\.ps1)?[\s|)(;'"&-]/.test(rest)) {
|
||||
const list = document.createElement('ul');
|
||||
for (const [where, command] of INSTALL_COMMANDS) {
|
||||
const item = document.createElement('li');
|
||||
const code = document.createElement('code');
|
||||
code.textContent = command;
|
||||
item.append(`${where}: `, code);
|
||||
list.append(item);
|
||||
}
|
||||
show(hintLine('This address is an install command, not a page. Paste the command into a terminal, not into the browser:'), list);
|
||||
return;
|
||||
}
|
||||
// A GitHub path: the files are browsed on the repository.
|
||||
const github = rest.match(/^(blob|tree|raw)\/(.+)$/);
|
||||
if (github) {
|
||||
const link = document.createElement('a');
|
||||
link.href = `https://github.com/Abdess/retrobios/${github[1] === 'raw' ? 'blob' : github[1]}/${github[2]}`;
|
||||
link.textContent = 'the same path on GitHub';
|
||||
show(hintLine('This is a path of the GitHub repository. Open ', link, '.'));
|
||||
return;
|
||||
}
|
||||
// A file name: the search finds the pages that list it.
|
||||
const file = rest.match(/(?:^|\/)([^/]+\.[a-z0-9]{1,5})\/?$/i);
|
||||
const word = file ? file[1] : rest.replace(/\/$/, '').split('/').pop() ?? '';
|
||||
const lines: HTMLElement[] = [];
|
||||
const known = rest.match(/^(emulators|systems|platforms)\/([^/]+)\/?$/);
|
||||
if (known) {
|
||||
const link = document.createElement('a');
|
||||
link.href = new URL(`${known[1]}/`, siteRoot()).href;
|
||||
link.textContent = `the list of ${known[1]}`;
|
||||
lines.push(hintLine(`No page is named ${known[2]} here. It may be listed under another name in `, link, '.'));
|
||||
}
|
||||
if (word && word.length <= 60) {
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'rb-notfound-search';
|
||||
button.textContent = `Search for ${word}`;
|
||||
button.addEventListener('click', () => openSearch(word));
|
||||
lines.push(hintLine(button));
|
||||
}
|
||||
if (lines.length) show(...lines);
|
||||
// A section below a page: the nearest page above it that exists.
|
||||
// Empty segments dropped: "//host/x" would read as another site's address.
|
||||
const parts = rest.split('/').filter((part) => part && part !== '.' && part !== '..');
|
||||
const parents = parts.slice(0, -1).map((_, index) => parts.slice(0, parts.length - 1 - index).join('/'));
|
||||
(async () => {
|
||||
for (const parent of parents) {
|
||||
const url = new URL(`${parent}/`, siteRoot());
|
||||
// Only a page of this site, under its base, is fetched or linked.
|
||||
if (url.origin !== siteRoot().origin || !url.pathname.startsWith(siteRoot().pathname)) return;
|
||||
try {
|
||||
if ((await fetch(url, { method: 'HEAD' })).ok) {
|
||||
const link = document.createElement('a');
|
||||
link.href = url.href;
|
||||
link.textContent = url.pathname;
|
||||
show(...lines, hintLine('The page above it: ', link, '.'));
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
}
|
||||
})();
|
||||
};
|
||||
|
||||
resolveFileAddress();
|
||||
@@ -1310,4 +1433,5 @@ filterFiles();
|
||||
osTabs();
|
||||
installPickers();
|
||||
showCurrentPage();
|
||||
startDownloads();
|
||||
notFound();
|
||||
@@ -504,6 +504,21 @@ body:has(.rb-sys-file, .rb-file-entry) { --sl-content-width: var(--rb-grid-width
|
||||
vertical-align: middle;
|
||||
}
|
||||
.rb-download:hover { background: var(--sl-color-accent-low); }
|
||||
/* The download beside a "Start with" file (site.ts startDownloads): the
|
||||
card's button, at the size of the line it sits in. */
|
||||
.sl-markdown-content a.rb-start-download {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-height: 24px;
|
||||
padding: 0 0.6rem;
|
||||
border: 1px solid var(--rb-link);
|
||||
border-radius: 4px;
|
||||
font-size: 0.8em;
|
||||
font-weight: 600;
|
||||
color: var(--rb-link);
|
||||
text-decoration: none;
|
||||
}
|
||||
.sl-markdown-content a.rb-start-download:hover { background: var(--sl-color-accent-low); }
|
||||
|
||||
/* The facts of a file card: label column, value column, one column on a phone. */
|
||||
.sl-markdown-content dl.rb-facts {
|
||||
|
||||
Reference in new issue
Block a user