serve a declared slug as an address, leaving the key alone
The human chose the second option: a route sits beside the key rather than replacing it. So `slug` renames what a bundle is served at, in every language, and identity stays derived from the path — which is exactly what keeps ADR-0033 intact, since series membership is the directory. A series landing page can now be renamed without orphaning its chapters, and there is a test that says so. `Site` resolves routes at index time, because only it can see whether every variant agrees. Disagreement is dropped rather than resolved, as is a slug landing where another bundle already answers — the same rule colliding keys and contested aliases already follow. The key a slug moved away from stops answering, so the old address does not quietly keep working. Two bugs surfaced doing this, both older than this change: An alias naming its own bundle's former key was rejected as "an alias that names a real bundle" — which made rename-plus-alias, the entire point of ADR-0008's alias mechanism, impossible. The check now asks what a request asks: is anything actually served there. Aliases were counted per declaring *file*, so a bundle whose two language variants both listed the same alias looked like two rival claimants and lost the alias. It is a set of keys now. This one only appears with translated content, which is why no fixture had caught it since entry 4 — the real binary did, on the first multilingual rename.
This commit is contained in:
@@ -240,3 +240,38 @@ func TestQueryFiltersByTagAndSection(t *testing.T) {
|
||||
t.Errorf("unknown tag = %v, want none", titles)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEveryVariantMayDeclareTheSameAlias(t *testing.T) {
|
||||
// An alias belongs to the bundle, so a translated bundle repeats it in each variant. Counting those as
|
||||
// rival claimants dropped exactly the aliases a multilingual rename needs — found by serving it, since
|
||||
// every fixture until now declared an alias in one variant only.
|
||||
site := NewSite(mustScan(t, fstest.MapFS{
|
||||
"content/posts/new.md": {Data: []byte("---\ntitle: New\naliases: [posts/old]\n---\n")},
|
||||
"content/posts/new.bn.md": {Data: []byte("---\ntitle: নতুন\naliases: [posts/old]\n---\n")},
|
||||
}))
|
||||
if got, ok := site.Alias("posts/old"); !ok || got != "posts/new" {
|
||||
t.Errorf("Alias(posts/old) = %q %v, want posts/new", got, ok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestASlugMovesTheRouteAndLeavesTheKeyAlone(t *testing.T) {
|
||||
site := NewSite(mustScan(t, fstest.MapFS{
|
||||
"content/posts/hello-world.md": {Data: []byte("---\ntitle: Hello\nslug: ekti-post\n---\n")},
|
||||
"content/posts/hello-world.bn.md": {Data: []byte("---\ntitle: একটি\n---\n")},
|
||||
}))
|
||||
for _, lang := range []string{"en", "bn"} {
|
||||
b, _, ok := site.Lookup("posts/hello-world", lang)
|
||||
if !ok {
|
||||
t.Fatalf("the key is still the identity, in %s", lang)
|
||||
}
|
||||
if b.Route != "posts/ekti-post" {
|
||||
t.Errorf("%s route = %q, want posts/ekti-post — a slug renames every variant (ADR-0035)", lang, b.Route)
|
||||
}
|
||||
}
|
||||
if key, live := site.KeyFor("posts/ekti-post"); !live || key != "posts/hello-world" {
|
||||
t.Errorf("KeyFor(route) = %q %v, want the key", key, live)
|
||||
}
|
||||
if _, live := site.KeyFor("posts/hello-world"); live {
|
||||
t.Error("the derived path must stop answering once a slug moves the bundle")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user