Skip to content

Commit a9a322e

Browse files
Merge pull request #130 from neherlab/docs/fix-routing
chore: rewrite url in docs site
2 parents 1b17e69 + a767343 commit a9a322e

5 files changed

+48
-4
lines changed

Diff for: docs/bun.lockb

31 KB
Binary file not shown.

Diff for: docs/deploy

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ pushd "build" >/dev/null
2222
# Remove non-HTML files
2323
find . -type f \( ! -iname "*.html" \) -exec rm {} \+
2424

25-
# Remove .html extension
26-
rename --filename 's/\.html//' **/*.html || true
27-
2825
# Upload extensionless HTML files
2926
aws s3 sync \
3027
--delete \
@@ -33,6 +30,7 @@ pushd "build" >/dev/null
3330
--cache-control "max-age=0, must-revalidate" \
3431
--metadata-directive REPLACE \
3532
--exclude "*.*" \
33+
--include "*.html" \
3634
. "s3://${AWS_S3_BUCKET}/"
3735

3836
# Update Cloudfront cache

Diff for: docs/infra/serve-index-html-for-directories.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Add index.html to request URLs without a file name in a CloudFront Functions viewer request event
2+
// https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/example_cloudfront_functions_url_rewrite_single_page_apps_section.html
3+
async function handler(event) {
4+
const request = event.request;
5+
let uri = request.uri;
6+
7+
// Check whether the URI ends with a slash (indicating it's likely a directory)
8+
if (uri.endsWith('/')) {
9+
request.uri += 'index.html';
10+
}
11+
12+
// Check whether the URI is missing a file extension (indicating it might be a directory)
13+
else if (!uri.includes('.')) {
14+
request.uri += '/index.html';
15+
}
16+
17+
return request;
18+
}
19+
20+
if (typeof module !== 'undefined') {
21+
module.exports = handler;
22+
}

Diff for: docs/infra/serve-index-html-for-directories.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { describe, expect, it } from 'vitest';
2+
import handler from './serve-index-html-for-directories.js';
3+
4+
const testCases = [
5+
{ uri: '', expected: '/index.html' },
6+
{ uri: '/', expected: '/index.html' },
7+
{ uri: '/foo', expected: '/foo/index.html' },
8+
{ uri: '/foo/', expected: '/foo/index.html' },
9+
{ uri: '/foo.html', expected: '/foo.html' },
10+
{ uri: '/foo/bar', expected: '/foo/bar/index.html' },
11+
{ uri: '/foo/bar/', expected: '/foo/bar/index.html' },
12+
{ uri: '/foo/bar/baz.html', expected: '/foo/bar/baz.html' },
13+
];
14+
15+
describe('CloudFront URL Rewriter Tests', () => {
16+
testCases.forEach(({ uri, expected }) => {
17+
it(`handles URI '${uri}' correctly`, async () => {
18+
const event = { request: { uri } };
19+
const result = await handler(event);
20+
expect(result.uri).toBe(expected);
21+
});
22+
});
23+
});

Diff for: docs/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"@docusaurus/tsconfig": "3.5.2",
3333
"@docusaurus/types": "3.5.2",
3434
"prettier": "^3.3.3",
35-
"typescript": "~5.5.2"
35+
"typescript": "~5.5.2",
36+
"vitest": "^3.0.5"
3637
},
3738
"browserslist": {
3839
"production": [

0 commit comments

Comments
 (0)