Code Monkey home page Code Monkey logo

sitemapify's Introduction

Sitemapify

Provides a ASP.NET HttpHandler to assist with generating a dynamic sitemap.xml file

There is also an Umbraco specific extension to Sitemapify that supports building the sitemap from Umbraco CMS content. See Sitemapify.Umbraco for further documentation

Installation

Install-Package Sitemapify

The installation process should have updated your web.config file to include a httphandler to process requests to sitemap.xml, it should look similar to:

<configuration>
  <system.webServer>
    <handlers>
      <add name="Sitemapify" path="sitemap.xml" verb="GET" type="Sitemapify.SitemapifyHttpHandler, Sitemapify" />
    </handlers>
  </system.webServer>
</configuration>

Customisation

The sitemap handler can be customised by altering the base configuration via the Sitemapify.Configure static configuration class.

Sitemapify.Configure(c => c
  .UsingContentProvider(new YourContentProvider())
  .UsingCacheProvider(new YourCacheProvider())
  .UsingDocumentBuilder(new YourDocumentBuilder())
);

Sitemapify is split into providers that are responsible for elements of the sitemap generation.

Content Provider (ISitemapifyContentProvider)

An implementation of a content provider supplies Sitemapify with a collection of SitemapUrl objects representing the nodes to output within the sitemap.

public interface ISitemapContentProvider
{
    IEnumerable<SitemapUrl> GetSitemapUrls();
    bool Cacheable { get; }
    DateTime CacheUntil { get; }
}

Cache Provider (ISitemapifyCacheProvider)

An implementation of a cache provider allows customisation of the caching mechanism used to optimise delivery of the sitemap to the browser. Once the sitemap document is generated it will be cached via the configured implementation of this interface.

public interface ISitemapCacheProvider
{
    void Add(XDocument sitemapContent, DateTimeOffset? expires);
    bool IsCached { get; }
    XDocument Get();
    void Remove();
}

Document Builder (ISitemapDocumentBuilder)

An implementation of the ISitemapDocumentBuilder provides allows full customisation of the sitemap document itself. The default implementation generates a fully compliant sitemap document based on the official sitemap.xsd.

public interface ISitemapDocumentBuilder
{
    XDocument BuildSitemapXmlDocument(IEnumerable<SitemapUrl> sitemapUrls);
}

Sitemapify.Umbraco Configuration

This version of Sitemapify.Umbraco supports Umbraco 8.1+. For Umbraco v7.* support, please refer to version 0.5.2.

Firstly install the Umbraco extension:

Install-Package Sitemapify.Umbraco

Once you have installed Sitemapify.Umbraco you can create an Component to configure Sitemapify to use the available "Umbraco Content Provider" to generate sitemap url that form the sitemap.xml.

public class SitemapifyComponent : IComponent
{
	public void Initialize()
	{
		Configure.With(config => config.UsingContentProvider(new SitemapifyUmbracoContentProvider()));
	}

	public void Terminate() { }
}

You'll also need to create a UserComposer to register the Component.

public class SitemapifyComposer : IUserComposer
{
	public void Compose(Composition composition)
	{
		composition.Components().Append<SitemapifyComponent>();
	}
}

By default the Umbraco content provider will look for content node properties with specific names to determine whether a particular node should be included in the generated sitemap file, these property names are:

  • umbracoNaviHide - True/False to determine whether this node is included (Default: false)
  • sitemapifyExcludeChildren - True/False to determine whether to ignore all child nodes below this node (Default: false)

If you want to alter these property aliases you can override them via application settings:

<appSettings>
	<add key="Sitemapify.Umbraco:ExcludedFromSitemapPropertyAlias" value="newPropertyAlias" />
	<add key="Sitemapify.Umbraco:ExcludedChildrenFromSitemapPropertyAlias" value="anotherPropertyAlias" />
</appSettings>

sitemapify's People

Contributors

alanwthom avatar philo avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sitemapify's Issues

Consider a Sitemapify.Mvc addition to streamline sitemap creation

This was quite deliberately not done initially to keep things simpler, however it will worth considering whether a specific library addition that has knowledge of the RouteTable.Routes could help to either auto define a sitemap (no likey) or at least provide addtional helper methods to aid in creating the urls.

Locale

Hi there! Google is complaining that the priority is "1,0". I guess the problem is the comma and it expects a dot as separator. I am not sure why, the servers are running an english OS and google should send english locale info - but howevery - can you fix the string representation for doubles to "figures dot decimals"?

Thanks... the rest works quite well ;)

Florian

LastMod date doesn't pass format validation in Google Webmaster

When submitting a generated XML document to Google Webmaster tools, I get the error "An invalid date was found. Please fix the date or formatting before resubmitting."

I can see it's set here https://github.com/stormid/Sitemapify/blob/bcee86c5358ec98e3c08b497eca55c1f2243c950/src/Sitemapify/Extensions/SitemapUrlExtensions.cs#L15, but I'm not sure how to update it to use a differnet format.

I didn't want to just change it to .ToString("yyyy-MM-dd"); as it'd break it for others who have the correct culture settings.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.