Added support for XML sitemaps.

This commit is contained in:
Dario Solera 2009-10-19 07:51:42 +00:00
parent ab22f73cbb
commit 5722ba895a
5 changed files with 85 additions and 2 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 // You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("3.0.1.404")] [assembly: AssemblyVersion("3.0.1.405")]
[assembly: AssemblyFileVersion("3.0.1.404")] [assembly: AssemblyFileVersion("3.0.1.405")]

View file

@ -0,0 +1 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sitemap.aspx.cs" Inherits="ScrewTurn.Wiki.Sitemap" %>

View file

@ -0,0 +1,58 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using ScrewTurn.Wiki.PluginFramework;
namespace ScrewTurn.Wiki {
public partial class Sitemap : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
Response.ClearContent();
Response.ContentType = "text/xml;charset=UTF-8";
Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
string mainUrl = Settings.MainUrl;
using(XmlWriter writer = XmlWriter.Create(Response.OutputStream)) {
writer.WriteStartDocument();
writer.WriteStartElement("urlset");
writer.WriteAttributeString("schemaLocation", "xsi", "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/09/sitemap.xsd");
foreach(PageInfo page in Pages.GetPages(null)) {
WritePage(mainUrl, page, writer);
}
foreach(NamespaceInfo nspace in Pages.GetNamespaces()) {
foreach(PageInfo page in Pages.GetPages(nspace)) {
WritePage(mainUrl, page, writer);
}
}
writer.WriteEndElement();
writer.WriteEndDocument();
}
}
/// <summary>
/// Writes a page to the output XML writer.
/// </summary>
/// <param name="mainUrl">The main wiki URL.</param>
/// <param name="page">The page.</param>
/// <param name="writer">The writer.</param>
private void WritePage(string mainUrl, PageInfo page, XmlWriter writer) {
writer.WriteStartElement("url");
writer.WriteElementString("loc", mainUrl + Tools.UrlEncode(page.FullName) + Settings.PageExtension);
writer.WriteElementString("priority", "0.5");
writer.WriteElementString("changefreq", "daily");
writer.WriteEndElement();
}
}
}

16
WebApplication/Sitemap.aspx.designer.cs generated Normal file
View file

@ -0,0 +1,16 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.4927
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ScrewTurn.Wiki {
public partial class Sitemap {
}
}

View file

@ -581,6 +581,13 @@
<Compile Include="SessionRefresh.aspx.designer.cs"> <Compile Include="SessionRefresh.aspx.designer.cs">
<DependentUpon>SessionRefresh.aspx</DependentUpon> <DependentUpon>SessionRefresh.aspx</DependentUpon>
</Compile> </Compile>
<Compile Include="Sitemap.aspx.cs">
<DependentUpon>Sitemap.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Sitemap.aspx.designer.cs">
<DependentUpon>Sitemap.aspx</DependentUpon>
</Compile>
<Compile Include="Thumb.aspx.cs"> <Compile Include="Thumb.aspx.cs">
<DependentUpon>Thumb.aspx</DependentUpon> <DependentUpon>Thumb.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType> <SubType>ASPXCodeBehind</SubType>
@ -2363,6 +2370,7 @@
<Content Include="Images\Editor\UL.png" /> <Content Include="Images\Editor\UL.png" />
<Content Include="JS\SearchHighlight.js" /> <Content Include="JS\SearchHighlight.js" />
<Content Include="PageListBuilder.ascx" /> <Content Include="PageListBuilder.ascx" />
<Content Include="Sitemap.aspx" />
<Content Include="Themes\Default-v2\Icon.ico" /> <Content Include="Themes\Default-v2\Icon.ico" />
<Content Include="Themes\Default-v2\Images\Attachment.png" /> <Content Include="Themes\Default-v2\Images\Attachment.png" />
<Content Include="Themes\Default-v2\Images\Background.gif" /> <Content Include="Themes\Default-v2\Images\Background.gif" />