From 0418f7bf11fd603c12de74ce62a1f975b00177df Mon Sep 17 00:00:00 2001 From: mbianchidev Date: Thu, 26 Nov 2026 10:27:24 +0100 Subject: [PATCH] Use clean URLs without .html Link pages as /projects and /about (and ./ for home) instead of their .html files, including canonical, og:url and sitemap URLs. GitHub Pages already serves /about from about.html and old .html addresses keep working. Add scripts/serve.mjs, a Node built-ins preview server that resolves clean URLs like Pages, and document it since opening files from disk no longer follows the page links. --- about.html | 10 ++-- docs/deployment.md | 29 +++++++---- docs/maintenance.md | 5 +- index.html | 20 ++++---- projects.html | 12 ++--- scripts/serve.mjs | 119 ++++++++++++++++++++++++++++++++++++++++++++ sitemap.xml | 4 +- 7 files changed, 166 insertions(+), 33 deletions(-) create mode 100644 scripts/serve.mjs diff --git a/about.html b/about.html index 20bc3b0..748f864 100644 --- a/about.html +++ b/about.html @@ -8,10 +8,10 @@ - + - + @@ -20,9 +20,9 @@
@@ -87,7 +87,7 @@

A small website footprint.

diff --git a/docs/deployment.md b/docs/deployment.md index c16ba9d..e4fe83a 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -6,15 +6,21 @@ The repository root contains the finished website. There is no package manager, framework, generator, build command or runtime service. All fonts, images, CSS and JavaScript are local files. Do not run `npm install`. -Open `index.html` in a browser to read the site. For an HTTP preview, use any -static web server. If Python 3 is already available: +Pages link to each other by clean URL, without `.html` (`projects`, +`about#contact`). Those links need a server that maps them to files the way +GitHub Pages does, so opening `index.html` from disk shows a page but not the +links between pages. Preview with the bundled server, which uses only Node.js +built-in modules: ```sh -python3 -m http.server 8080 --bind 127.0.0.1 +node scripts/serve.mjs ``` -Visit `http://127.0.0.1:8080`. Stop the server with Ctrl+C. -Python is an optional preview tool, not a website dependency. +Visit `http://127.0.0.1:8080`; add `--port 3000` to use another port. Stop the +server with Ctrl+C. Like GitHub Pages, it serves `/about` from `about.html`, +still serves `.html` addresses, and answers anything else with `404.html` and +status 404. It serves only the published files. Node.js is an optional preview +tool, not a website dependency, and `scripts/` is not published. ## Set up GitHub Pages @@ -68,8 +74,11 @@ standard `GITHUB_TOKEN` and GitHub's OIDC token. The workflow does not run Jekyll. `CNAME`, `robots.txt` and `sitemap.xml` already describe the intended hostname. Asset and internal-page links are relative, -so the content also works under a Pages repository path. Canonical and -social-preview URLs intentionally use the final custom domain. +so the content also works under a Pages repository path. Page links omit +`.html` (`projects`, `about`, `./` for the home page); GitHub Pages serves +`/about` from `about.html`, and old `.html` addresses keep working. Canonical, +social-preview and sitemap URLs intentionally use the final custom domain with +the same clean URLs, such as `https://synctune.it/projects`. Deploy each site independently. Links to other Synctune subdomains will work when their owners deploy those sites. Denote, Open Playlist, Open Playlist @@ -79,8 +88,10 @@ their websites. ## Other static hosts Publish the repository root as static files. Leave the install and build -commands empty. The site needs no environment variables, API keys, rewrites, -server functions or network API. +commands empty. The site needs no environment variables, API keys, server +functions or network API, but the host must serve clean URLs as GitHub Pages +does: `/about` from `about.html`. Enable the host's clean URL option if that is +not its default. `404.html` is a standalone fallback. GitHub Pages uses it for missing paths; on another host, select it as the not-found page if required. diff --git a/docs/maintenance.md b/docs/maintenance.md index 4f32027..a7543b8 100644 --- a/docs/maintenance.md +++ b/docs/maintenance.md @@ -145,7 +145,10 @@ The Gaming history entry briefly mentions Global Game Jam 2019 in Milan. ## Before publishing a change -Check internal pages, anchors, local assets, project destinations and the +Link pages without `.html` (`projects`, `about#privacy`, `./` for the home +page) and use the same clean URLs in canonical, `og:url` and `sitemap.xml`. +Preview with `node scripts/serve.mjs` (see [deployment](deployment.md)) and +check internal pages, anchors, local assets, project destinations and the custom-domain files. Preview narrow and wide layouts, use the keyboard, try the directory search and reset, and reload with JavaScript disabled. Check that the font licenses remain present. No install or build step is required. diff --git a/index.html b/index.html index dd2606f..5f645fd 100644 --- a/index.html +++ b/index.html @@ -21,11 +21,11 @@
@@ -35,8 +35,8 @@

An orchestra of independent ideas.
In sync.

We build software for the things we care about. Making music. Owning our tools. Learning something difficult. Finding a better way to work.

@@ -87,7 +87,7 @@

An orchestra of independent ideas.
I

A few things we are building

Different problems.
Real projects.

- See the complete portfolio + See the complete portfolio
@@ -133,10 +133,10 @@

Have something
worth building?

- + diff --git a/projects.html b/projects.html index d7cebe9..e3c72f5 100644 --- a/projects.html +++ b/projects.html @@ -8,10 +8,10 @@ - + - + @@ -21,9 +21,9 @@
@@ -137,8 +137,8 @@

Follow your
curiosity.

This is a hand-maintained directory, not a live release feed. Public source does not imply a finished release. Some projects still use Matteo's GitHub namespace while organization transfers are pending. Private projects have no repository link.

diff --git a/scripts/serve.mjs b/scripts/serve.mjs new file mode 100644 index 0000000..810a3de --- /dev/null +++ b/scripts/serve.mjs @@ -0,0 +1,119 @@ +// Local preview that serves the published files the way GitHub Pages does. +// Node built-ins only. +// node scripts/serve.mjs http://127.0.0.1:8080 +// node scripts/serve.mjs --port 3000 +// +// /foo serves foo.html +// /dir/ serves dir/index.html +// /dir redirects (301) to /dir/ when only dir/index.html exists +// /foo.html is still served +// anything else returns 404.html with status 404 +import { createServer } from 'node:http'; +import { readFile, stat } from 'node:fs/promises'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); +const portArg = process.argv.indexOf('--port'); +const port = Number(portArg === -1 ? process.env.PORT || 8080 : process.argv[portArg + 1]); +const host = '127.0.0.1'; +if (!Number.isInteger(port) || port < 0 || port > 65535) { + console.error(`Invalid port: ${portArg === -1 ? process.env.PORT : process.argv[portArg + 1]}`); + process.exit(1); +} + +// Mirrors the public files packaged by .github/workflows/pages.yml. +const publishedDirs = ['assets']; +const publishedRootFiles = ['robots.txt', 'sitemap.xml', 'CNAME', '.nojekyll']; +const isPublished = (rel) => { + const [first, ...rest] = rel.split('/'); + if (rest.length) return publishedDirs.includes(first); + return first.endsWith('.html') || publishedRootFiles.includes(first); +}; + +const types = { + '.html': 'text/html; charset=utf-8', + '.css': 'text/css; charset=utf-8', + '.js': 'text/javascript; charset=utf-8', + '.svg': 'image/svg+xml', + '.png': 'image/png', + '.jpg': 'image/jpeg', + '.jpeg': 'image/jpeg', + '.webp': 'image/webp', + '.avif': 'image/avif', + '.ttf': 'font/ttf', + '.ico': 'image/x-icon', + '.xml': 'application/xml; charset=utf-8', + '.txt': 'text/plain; charset=utf-8', + '.json': 'application/json; charset=utf-8', +}; + +async function publishedFile(rel) { + if (!rel || !isPublished(rel)) return null; + try { + return (await stat(path.join(root, rel))).isFile() ? rel : null; + } catch { + return null; + } +} + +async function resolve(pathname) { + const segments = pathname.split('/').slice(1); + if (segments.some((segment) => segment === '..' || segment === '.' || segment.includes('\\') || segment.includes('\0'))) { + return { status: 404 }; + } + const rel = segments.join('/'); + if (rel === '' || rel.endsWith('/')) { + const file = await publishedFile(`${rel}index.html`); + return file ? { status: 200, file } : { status: 404 }; + } + const exact = await publishedFile(rel); + if (exact) return { status: 200, file: exact }; + const page = await publishedFile(`${rel}.html`); + if (page) return { status: 200, file: page }; + if (await publishedFile(`${rel}/index.html`)) return { status: 301, location: `${pathname}/` }; + return { status: 404 }; +} + +const server = createServer(async (request, response) => { + const url = new URL(request.url, `http://${request.headers.host || host}`); + if (request.method !== 'GET' && request.method !== 'HEAD') { + response.writeHead(405, { allow: 'GET, HEAD' }).end(); + return; + } + let pathname; + try { + pathname = decodeURIComponent(url.pathname); + } catch { + pathname = null; + } + const result = pathname ? await resolve(pathname) : { status: 404 }; + if (result.status === 301) { + response.writeHead(301, { location: `${encodeURI(result.location)}${url.search}` }).end(); + console.log(`301 ${url.pathname}`); + return; + } + const file = result.file ?? '404.html'; + let body; + try { + body = await readFile(path.join(root, file)); + } catch (error) { + response.writeHead(500).end(); + console.error(`500 ${url.pathname}: ${error.message}`); + return; + } + response.writeHead(result.status, { + 'content-type': types[path.extname(file).toLowerCase()] ?? 'application/octet-stream', + 'content-length': body.length, + 'cache-control': 'no-store', + }); + response.end(request.method === 'HEAD' ? undefined : body); + console.log(`${result.status} ${url.pathname}`); +}); + +server.on('error', (error) => { + console.error(`Preview server failed: ${error.message}`); + process.exitCode = 1; +}); + +server.listen(port, host, () => console.log(`Previewing on http://${host}:${port}/ (Ctrl+C to stop)`)); diff --git a/sitemap.xml b/sitemap.xml index 4643bba..235fa48 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -1,6 +1,6 @@ https://synctune.it/ - https://synctune.it/projects.html - https://synctune.it/about.html + https://synctune.it/projects + https://synctune.it/about