Skip to content

softawaregmbh/library-sitemap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Sitemap

Example

using softaware.Sitemap;

var sitemap = new Sitemap();
sitemap.AddNode(new SitemapNode("https://www.example.com"));
var result = sitemap.GenerateSitemap();

Result:

<urlset xmlns:xhtml="http://www.w3.org/1999/xhtml" 
		xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<url>
		<loc>https://www.example.com</loc>
	</url>
</urlset>

Localized Sitemap

using softaware.Sitemap;

var sitemap = new Sitemap();

// Option 1) Specify alternates url:
sitemap.AddNode(new SitemapNode("https://www.example.com")
{
    Alternates = new List<(string, string)>
    {
        ("de", "https://www.example.com/de"),
        ("fr", "https://www.example.com/fr")
    }
});

// Option2 ) Using a callback function:
sitemap.AddNodes(SitemapNode.FromLocalized(
    new[] { "en", "de" }, 
    lang => new SitemapNode($"https://www.example.com/{lang}")));

var result = sitemap.GenerateSitemap();

Result:

<urlset xmlns:xhtml="http://www.w3.org/1999/xhtml"
		xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<url>
		<loc>https://www.example.com</loc>
		<xhtml:link rel="alternate" hreflang="de" href="https://www.example.com/de" />
		<xhtml:link rel="alternate" hreflang="fr" href="https://www.example.com/fr" />
	</url>
</urlset>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages