mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 19:34:40 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
@{
|
||||
Html.AddTitleParts(T("Manage Blog").ToString());
|
||||
}
|
||||
// Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type
|
||||
@* Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type *@
|
||||
@Display(Model)
|
||||
|
@@ -11,3 +11,7 @@ Features:
|
||||
Category: Designer
|
||||
Description: Displays all currently displayed shapes and some information to customize them
|
||||
Dependencies: Orchard.jQuery
|
||||
UrlAlternates:
|
||||
Name: Url Alternates
|
||||
Category: Designer
|
||||
Description: Adds shape alternates for specific urls
|
||||
|
@@ -83,6 +83,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Services\ObjectDumper.cs" />
|
||||
<Compile Include="Services\ShapeTracingFactory.cs" />
|
||||
<Compile Include="Services\UrlAlternatesFactory.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\ShapeTracing.Wrapper.cshtml" />
|
||||
|
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Mvc;
|
||||
|
||||
namespace Orchard.DesignerTools.Services {
|
||||
[OrchardFeature("UrlAlternates")]
|
||||
public class UrlAlternatesFactory : ShapeDisplayEvents {
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly List<string> _urlAlternates;
|
||||
|
||||
public UrlAlternatesFactory(IHttpContextAccessor httpContextAccessor) {
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
|
||||
var request = _httpContextAccessor.Current().Request;
|
||||
|
||||
// extract each segment of the url
|
||||
var urlSegments = VirtualPathUtility.ToAppRelative(request.Path.ToLower())
|
||||
.Split('/')
|
||||
.Skip(1) // ignore the heading ~ segment
|
||||
.Select(url => url.Replace("-", "__").Replace(".", "_")) // format the alternate
|
||||
.ToArray();
|
||||
|
||||
if ( String.IsNullOrWhiteSpace(urlSegments[0]) ) {
|
||||
urlSegments[0] = "homepage";
|
||||
}
|
||||
|
||||
_urlAlternates = Enumerable.Range(1, urlSegments.Count()).Select(range => String.Join("__", urlSegments.Take(range))).ToList();
|
||||
}
|
||||
|
||||
public override void Displaying(ShapeDisplayingContext context) {
|
||||
|
||||
context.ShapeMetadata.OnDisplaying(displayedContext => {
|
||||
// appends Url alternates to current ones
|
||||
displayedContext.ShapeMetadata.Alternates = displayedContext.ShapeMetadata.Alternates.SelectMany(
|
||||
alternate => new [] { alternate }.Union(_urlAlternates.Select(a => alternate + "__url__" + a))
|
||||
).ToList();
|
||||
|
||||
// appends [ShapeType__url__[Url] alternates
|
||||
displayedContext.ShapeMetadata.Alternates = _urlAlternates.Select(url => displayedContext.ShapeMetadata.Type + "__url__" + url)
|
||||
.Union(displayedContext.ShapeMetadata.Alternates)
|
||||
.ToList();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -25,8 +25,12 @@ namespace Orchard.Widgets {
|
||||
widget.Classes.Add("widget-" + contentItem.ContentType.HtmlClassify());
|
||||
|
||||
var zoneName = contentItem.As<WidgetPart>().Zone;
|
||||
displaying.ShapeMetadata.Alternates.Add("Widget__" + contentItem.ContentType);
|
||||
|
||||
// Widget__[ZoneName] e.g. Widget-SideBar
|
||||
displaying.ShapeMetadata.Alternates.Add("Widget__" + zoneName);
|
||||
|
||||
// Widget__[ContentType] e.g. Widget-BlogArchive
|
||||
displaying.ShapeMetadata.Alternates.Add("Widget__" + contentItem.ContentType);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user