Added support for rel="canonical" meta.

This commit is contained in:
Dario Solera 2011-09-01 18:07:45 +02:00
parent 9d52f36079
commit 78d4d07a73
5 changed files with 37 additions and 9 deletions

View file

@ -16,5 +16,5 @@ using System.Reflection;
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("3.0.5.609")]
[assembly: AssemblyFileVersion("3.0.5.609")]
[assembly: AssemblyVersion("3.0.5.610")]
[assembly: AssemblyFileVersion("3.0.5.610")]

View file

@ -103,6 +103,24 @@ namespace ScrewTurn.Wiki {
return buffer.ToString();
}
/// <summary>
/// Gets the canonical URL tag for a page.
/// </summary>
/// <param name="requestUrl">The request URL.</param>
/// <param name="currentPage">The current page.</param>
/// <param name="nspace">The namespace.</param>
/// <returns>The canonical URL, or an empty string if <paramref name="requestUrl"/> is already canonical.</returns>
public static string GetCanonicalUrlTag(string requestUrl, PageInfo currentPage, NamespaceInfo nspace) {
string url = "";
if(nspace == null && currentPage.FullName == Settings.DefaultPage) url = Settings.GetMainUrl().ToString();
else url = Settings.GetMainUrl() + "/" + currentPage.FullName + Settings.PageExtension;
url = url.Replace("//", "/");
// Case sensitive
if(url == requestUrl) return "";
else return "<link rel=\"canonical\" href=\"" + url + "\" />";
}
/// <summary>
/// Converts a byte number into a string, formatted using KB, MB or GB.
/// </summary>

View file

@ -81,6 +81,12 @@ namespace ScrewTurn.Wiki {
SetupEmailNotification();
SetupPageContent(canPostDiscussion, canManageDiscussion);
if(currentPage != null) {
Literal canonical = new Literal();
canonical.Text = Tools.GetCanonicalUrlTag(Request.Url.ToString(), currentPage, Pages.FindNamespace(NameTools.GetNamespace(currentPage.FullName)));
Page.Header.Controls.Add(canonical);
}
}
/// <summary>

View file

@ -17,7 +17,7 @@ using ScrewTurn.Wiki.PluginFramework;
namespace ScrewTurn.Wiki {
public partial class MasterPage : System.Web.UI.MasterPage {
public partial class MasterPage : System.Web.UI.MasterPage {
private string currentNamespace = null;
private PageInfo currentPage = null;
@ -98,12 +98,12 @@ namespace ScrewTurn.Wiki {
Literal c = new Literal();
c.Text = h.Replace("######______INCLUDES______######", Tools.GetIncludes(currentNamespace)).Replace("######______NAMESPACE______######", nspace);
Page.Header.Controls.Add(c);
}
}
/// <summary>
/// Prints the header.
/// </summary>
public void PrintHeader() {
public void PrintHeader() {
string h = Content.GetPseudoCacheValue(GetPseudoCacheItemName("Header"));
if(h == null) {
h = FormattingPipeline.FormatWithPhase1And2(Settings.Provider.GetMetaDataItem(MetaDataItem.Header, currentNamespace),
@ -111,12 +111,12 @@ namespace ScrewTurn.Wiki {
Content.SetPseudoCacheValue(GetPseudoCacheItemName("Header"), h);
}
lblHeaderDiv.Text = FormattingPipeline.FormatWithPhase3(h, FormattingContext.Header, currentPage);
}
}
/// <summary>
/// Prints the sidebar.
/// </summary>
public void PrintSidebar() {
public void PrintSidebar() {
string s = Content.GetPseudoCacheValue(GetPseudoCacheItemName("Sidebar"));
if(s == null) {
s = FormattingPipeline.FormatWithPhase1And2(Settings.Provider.GetMetaDataItem(MetaDataItem.Sidebar, currentNamespace),
@ -124,7 +124,7 @@ namespace ScrewTurn.Wiki {
Content.SetPseudoCacheValue(GetPseudoCacheItemName("Sidebar"), s);
}
lblSidebarDiv.Text = FormattingPipeline.FormatWithPhase3(s, FormattingContext.Sidebar, currentPage);
}
}
/// <summary>
/// Prints the footer.

View file

@ -39,9 +39,13 @@ namespace ScrewTurn.Wiki {
content = Content.GetPageContent(page, true);
Literal canonical = new Literal();
canonical.Text = Tools.GetCanonicalUrlTag(Request.Url.ToString(), page, Pages.FindNamespace(NameTools.GetNamespace(page.FullName)));
Page.Header.Controls.Add(canonical);
Page.Title = FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, page) + " - " + Settings.WikiTitle;
PrintContent();
PrintContent();
}
/// <summary>