Skip to content

Commit 97e625c

Browse files
committed
Serve the legacy extensionless article address as HTML
1 parent 9a96562 commit 97e625c

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎scripts/postbuild.mjs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const baseline = JSON.parse(fs.readFileSync('migration/baseline.json', 'utf8'));
55
for (const post of baseline.filter(post => post.published)) {
66
for (const legacyUrl of post.legacyUrls || []) {
77
const destination = path.join('dist', decodeURI(legacyUrl).replace(/^\//, ''));
8-
if (fs.existsSync(destination) && fs.statSync(destination).isDirectory()) continue;
9-
fs.mkdirSync(path.dirname(destination), { recursive: true });
10-
// Preserve the old extensionless document, including query-string links to it.
11-
fs.copyFileSync(path.join('dist', post.url, 'index.html'), destination);
8+
if (fs.existsSync(destination) && fs.statSync(destination).isFile()) fs.unlinkSync(destination);
9+
fs.mkdirSync(destination, { recursive: true });
10+
// A directory index gives the old extensionless address an HTML response.
11+
fs.copyFileSync(path.join('dist', post.url, 'index.html'), path.join(destination, 'index.html'));
1212
}
1313
}
1414
console.log('Legacy URL compatibility files ready.');

‎scripts/verify-migration.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def inner(node):
4343
check(len(body) == 1 and inner(body[0]) == inner(snapshot), f"Rendered body changed: {post['url']}")
4444
check(document.xpath('string(//h1)') == post['title'], f"Article title mismatch: {post['url']}")
4545
for url in item['legacyUrls']:
46-
check((ROOT / 'dist' / url.lstrip('/')).is_file(), f"Legacy compatibility URL missing: {url}")
46+
check((ROOT / 'dist' / url.lstrip('/') / 'index.html').is_file(), f"Legacy compatibility URL missing: {url}")
4747

4848
assets = json.loads((ROOT / 'migration/assets.json').read_text())
4949
for asset in assets:

0 commit comments

Comments
 (0)