Skip to content

Commit

Permalink
alias and slug alternates for widgets too
Browse files Browse the repository at this point in the history
  • Loading branch information
giannik committed Oct 8, 2024
1 parent a88dea5 commit f607f01
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder)
displaying.Shape.Metadata.Alternates.Add("Content_" + displaying.Shape.Metadata.DisplayType + "__Alias__" + encodedAlias);
}
});
builder.Describe("Widget")
.OnDisplaying(displaying =>
{
var shape = displaying.Shape;
var contentItem = shape.GetProperty<ContentItem>("ContentItem");
var aliasPart = contentItem?.As<AliasPart>();
if (aliasPart != null)
{
var encodedAlias = aliasPart.Alias.EncodeAlternateElement();
// Widget__Alias__[Alias] e.g. Widget-Alias-example, Widget-Alias-my-page
displaying.Shape.Metadata.Alternates.Add("Widget__Alias__" + encodedAlias);
// Widget_[DisplayType]__Alias__[Alias] e.g. Widget-Alias-example.Summary, Widget-Alias-my-page.Summary
displaying.Shape.Metadata.Alternates.Add("Widget_" + displaying.Shape.Metadata.DisplayType + "__Alias__" + encodedAlias);
}
});

return ValueTask.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder)
displaying.Shape.Metadata.Alternates.Add("Content_" + displaying.Shape.Metadata.DisplayType + "__Slug__" + encodedSlug);
}
});
builder.Describe("Widget")
.OnDisplaying(displaying =>
{
var shape = displaying.Shape;
var contentItem = shape.GetProperty<ContentItem>("ContentItem");
var autoroutePart = contentItem?.As<AutoroutePart>();
if (autoroutePart != null)
{
var encodedSlug = autoroutePart.Path.EncodeAlternateElement().Replace("/", "__");
// Widget__Slug__[Slug] e.g. Widget-Slug-example, Widget-Slug-blog-my-post
displaying.Shape.Metadata.Alternates.Add("Widget__Slug__" + encodedSlug);
// Widget_[DisplayType]__Slug__[Slug] e.g. Widget-Slug-example.Summary, Widget-Slug-blog-my-post.Summary
displaying.Shape.Metadata.Alternates.Add("Widget_" + displaying.Shape.Metadata.DisplayType + "__Slug__" + encodedSlug);
}
});

return ValueTask.CompletedTask;
}
Expand Down

0 comments on commit f607f01

Please sign in to comment.