mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#17620: Refactoring how the Title is generated in Document shape
Work Item: 17620 --HG-- branch : 1.x
This commit is contained in:
@@ -2,20 +2,16 @@
|
||||
@using Orchard.UI.Resources;
|
||||
@{
|
||||
RegisterLink(new LinkEntry {Type = "image/x-icon", Rel = "shortcut icon", Href = Url.Content("~/modules/orchard.themes/Content/orchard.ico")});
|
||||
//todo: (heskew) get conditions (as in conditional comments) hooked up for script tags too
|
||||
Script.Include("html5.js").AtLocation(ResourceLocation.Head);
|
||||
Script.Include("html5.js").AtHead();
|
||||
|
||||
//a bit opinionated - only the site name on the homepage
|
||||
var title = (Request.Path.TrimEnd('/') != Request.ApplicationPath && HasText(Model.Title)
|
||||
? Model.Title + WorkContext.CurrentSite.PageTitleSeparator
|
||||
: "") +
|
||||
WorkContext.CurrentSite.SiteName;
|
||||
string title = Model.Title;
|
||||
string siteName = WorkContext.CurrentSite.SiteName;
|
||||
}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" class="static @Html.ClassForPage()">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>@title</title>
|
||||
<title>@Html.Title(title, siteName)</title>
|
||||
@Display(Model.Head)
|
||||
<script>(function(d){d.className="dyn"+d.className.substring(6,d.className.length);})(document.documentElement);</script>
|
||||
</head>
|
||||
|
@@ -34,7 +34,7 @@ namespace Orchard.Mvc.Html {
|
||||
public static MvcHtmlString Title(this HtmlHelper html, params string[] titleParts) {
|
||||
IPageTitleBuilder pageTitleBuilder = html.Resolve<IPageTitleBuilder>();
|
||||
|
||||
html.AppendTitleParts(titleParts);
|
||||
html.AddTitleParts(titleParts);
|
||||
|
||||
return MvcHtmlString.Create(html.Encode(pageTitleBuilder.GenerateTitle()));
|
||||
}
|
||||
|
@@ -1,7 +1,22 @@
|
||||
namespace Orchard.UI.PageTitle {
|
||||
public interface IPageTitleBuilder : IDependency {
|
||||
|
||||
/// <summary>
|
||||
/// Adds some strings at the end of the title.
|
||||
/// </summary>
|
||||
/// <param name="titleParts">A set of strings to add at the end of the title.</param>
|
||||
void AddTitleParts(params string[] titleParts);
|
||||
|
||||
/// <summary>
|
||||
/// Inserts some strings at the beginning of the title.
|
||||
/// </summary>
|
||||
/// <param name="titleParts">A set of strings to insert at the beginning of the title.</param>
|
||||
void AppendTitleParts(params string[] titleParts);
|
||||
|
||||
/// <summary>
|
||||
/// Concatenates every title parts using the separator defined in settings.
|
||||
/// </summary>
|
||||
/// <returns>A string representing the aggregate title for the current page.</returns>
|
||||
string GenerateTitle();
|
||||
}
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Settings;
|
||||
@@ -15,21 +16,23 @@ namespace Orchard.UI.PageTitle {
|
||||
}
|
||||
|
||||
public void AddTitleParts(params string[] titleParts) {
|
||||
if (titleParts != null)
|
||||
if (titleParts.Length > 0)
|
||||
foreach (string titlePart in titleParts)
|
||||
if (!string.IsNullOrEmpty(titlePart))
|
||||
_titleParts.Add(titlePart);
|
||||
}
|
||||
|
||||
public void AppendTitleParts(params string[] titleParts) {
|
||||
if (titleParts != null)
|
||||
if (titleParts.Length > 0)
|
||||
foreach (string titlePart in titleParts)
|
||||
if (!string.IsNullOrEmpty(titlePart))
|
||||
_titleParts.Insert(0, titlePart);
|
||||
}
|
||||
|
||||
public string GenerateTitle() {
|
||||
return string.Join(_titleSeparator, _titleParts.AsEnumerable().Reverse().ToArray());
|
||||
return _titleParts.Count == 0
|
||||
? String.Empty
|
||||
: String.Join(_titleSeparator, _titleParts.AsEnumerable().Reverse().ToArray());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user