xsitemap 2.9.2
.NET 6.0
.NET Standard 2.0
dotnet add package xsitemap --version 2.9.2
NuGet\Install-Package xsitemap -Version 2.9.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="xsitemap" Version="2.9.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add xsitemap --version 2.9.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: xsitemap, 2.9.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install xsitemap as a Cake Addin
#addin nuget:?package=xsitemap&version=2.9.2
// Install xsitemap as a Cake Tool
#tool nuget:?package=xsitemap&version=2.9.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
X.Web.Sitemap
Simple sitemap generator for .NET
⚠️ See breaking changes for release 2.9.2
Usage example
Below is an example of basic usage in a non-testable manner
class Program
{
static void Main(string[] args)
{
var sitemap = new Sitemap();
sitemap.Add(new Url
{
ChangeFrequency = ChangeFrequency.Daily,
Location = "http://www.example.com",
Priority = 0.5,
TimeStamp = DateTime.Now
});
sitemap.Add(CreateUrl("http://www.example.com/link1"));
sitemap.Add(CreateUrl("http://www.example.com/link2"));
sitemap.Add(CreateUrl("http://www.example.com/link3"));
sitemap.Add(CreateUrl("http://www.example.com/link4"));
sitemap.Add(CreateUrl("http://www.example.com/link5"));
//Save sitemap structure to file
sitemap.Save(@"d:\www\example.com\sitemap.xml");
//Split a large list into pieces and store in a directory
sitemap.SaveToDirectory(@"d:\www\example.com\sitemaps");
//Get xml-content of file
Console.Write(sitemap.ToXml());
Console.ReadKey();
}
private static Url CreateUrl(string url)
{
return new Url
{
ChangeFrequency = ChangeFrequency.Daily,
Location = url,
Priority = 0.5,
TimeStamp = DateTime.Now
};
}
}
Below is a more comprehensive example that demonstrates how to create many sitemaps and how to add them to a sitemap index file in a unit-testable fashion.
public class SitemapGenerationWithSitemapIndexExample
{
private readonly ISitemapGenerator _sitemapGenerator;
private readonly ISitemapIndexGenerator _sitemapIndexGenerator;
//--this is a bogus interface defined in this example to simulate something you might use to get a list of URls from your CMS or something like that
private readonly IWebsiteUrlRetriever _websiteUrlRetriever;
//--and IoC/Dependency injection framework should inject this in
public SitemapGenerationWithSitemapIndexExample(
ISitemapGenerator sitemapGenerator,
ISitemapIndexGenerator sitemapIndexGenerator,
IWebsiteUrlRetriever websiteUrlRetriever)
{
_sitemapGenerator = sitemapGenerator;
_sitemapIndexGenerator = sitemapIndexGenerator;
_websiteUrlRetriever = websiteUrlRetriever;
}
//--this is an example showing how you might take a large list of URLs of different kinds of resources and build both a bunch of sitemaps (depending on
// how many URls you have) as well as a sitemap index file to go with it
public void GenerateSitemapsForMyEntireWebsite()
{
//--imagine you have an interface that can return a list of URLs for a resource that you consider to be high priority -- for example, the product detail pages (PDPs)
// of your website
var productPageUrlStrings = _websiteUrlRetriever.GetHighPriorityProductPageUrls();
//--build a list of X.Web.Sitemap.Url objects and determine what is the appropriate ChangeFrequency, TimeStamp (aka "LastMod" or date that the resource last had changes),
// and the a priority for the page. If you can build in some logic to prioritize your pages then you are more sophisticated than most! :)
var allUrls = productPageUrlStrings.Select(url => new Url
{
//--assign the location of the HTTP request -- e.g.: https://www.somesite.com/some-resource
Location = url,
//--let's instruct crawlers to crawl these pages monthly since the content doesn't change that much
ChangeFrequency = ChangeFrequency.Monthly,
//--in this case we don't know when the page was last modified so we wouldn't really set this. Only assigning here to demonstrate that the property exists.
// if your system is smart enough to know when a page was last modified then that is the best case scenario
TimeStamp = DateTime.UtcNow,
//--set this to between 0 and 1. This should only be used as a relative ranking of other pages in your site so that search engines know which result to prioritize
// in SERPS if multiple pages look pertinent from your site. Since product pages are really important to us, we'll make them a .9
Priority = .9
}).ToList();
var miscellaneousLowPriorityUrlStrings = _websiteUrlRetriever.GetMiscellaneousLowPriorityUrls();
var miscellaneousLowPriorityUrls = miscellaneousLowPriorityUrlStrings.Select(url => new Url
{
Location = url,
//--let's instruct crawlers to crawl these pages yearly since the content almost never changes
ChangeFrequency = ChangeFrequency.Yearly,
//--let's pretend this content was changed a year ago
TimeStamp = DateTime.UtcNow.AddYears(-1),
//--these pages are super low priority
Priority = .1
}).ToList();
//--combine the urls into one big list. These could of course bet kept seperate and two different sitemap index files could be generated if we wanted
allUrls.AddRange(miscellaneousLowPriorityUrls);
//--pick a place where you would like to write the sitemap files in that folder will get overwritten by new ones
var targetSitemapDirectory = new DirectoryInfo("\\SomeServer\\some_awesome_file_Share\\sitemaps\\");
//--generate one or more sitemaps (depending on the number of URLs) in the designated location.
var fileInfoForGeneratedSitemaps = _sitemapGenerator.GenerateSitemaps(allUrls, targetSitemapDirectory);
var sitemapInfos = new List<SitemapInfo>();
var dateSitemapWasUpdated = DateTime.UtcNow.Date;
foreach (var fileInfo in fileInfoForGeneratedSitemaps)
{
//--it's up to you to figure out what the URI is to the sitemap you wrote to the file sytsem. In this case we are assuming that the directory above
// has files exposed via the /sitemaps/ subfolder of www.mywebsite.com
var uriToSitemap = new Uri($"https://www.mywebsite.com/sitemaps/{fileInfo.Name}");
sitemapInfos.Add(new SitemapInfo(uriToSitemap, dateSitemapWasUpdated));
}
//--now generate the sitemap index file which has a reference to all of the sitemaps that were generated.
_sitemapIndexGenerator.GenerateSitemapIndex(sitemapInfos, targetSitemapDirectory, "sitemap-index.xml");
//-- After this runs you'll want to make sure your robots.txt has a reference to the sitemap index (at the bottom of robots.txt) like this:
// "Sitemap: https://www.mywebsite.com/sitemaps/sitemap-index.xml"
// You could do this manually (since this may never change) or if you are ultra-fancy, you could dynamically update your robots.txt with the names of the sitemap index
// file(s) you generated
}
//--some bogus interface that is meant to simulate pulling urls from your CMS/website
public interface IWebsiteUrlRetriever
{
List<string> GetHighPriorityProductPageUrls();
List<string> GetMiscellaneousLowPriorityUrls();
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
NuGet packages (6)
Showing the top 5 NuGet packages that depend on xsitemap:
Package | Downloads |
---|---|
Piranha.AspNetCore
Piranha CMS middleware components for AspNetCore |
|
N3O.Umbraco.Search
TODO |
|
N3O.Umbraco.Web
Web N3O Umbraco extensions. |
|
Molecule
个人项目公共组件集合 |
|
IM.HttpUtils
Package Description |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on xsitemap:
Repository | Stars |
---|---|
PiranhaCMS/piranha.core
Piranha CMS is the friendly editor-focused CMS for .NET6 that can be used both as an integrated CMS or as a headless API.
|
Version | Downloads | Last updated |
---|---|---|
2.9.2 | 74 | 9/23/2023 |
2.8.0 | 47,423 | 3/7/2023 |
2.7.2-beta | 180 | 3/2/2023 |
2.7.0 | 62,759 | 9/3/2022 |
2.1.0 | 148,879 | 11/3/2021 |
2.0.7 | 234,358 | 7/28/2019 |
2.0.6 | 31,667 | 9/26/2018 |
2.0.5 | 53,685 | 3/12/2018 |
2.0.0 | 9,617 | 4/29/2017 |
1.5.0.100 | 7,489 | 1/4/2017 |
1.1.5.2 | 4,623 | 7/7/2013 |
1.1.5.1 | 1,438 | 7/7/2013 |
1.1.5 | 1,339 | 4/5/2013 |
1.1.3 | 1,346 | 3/12/2013 |
1.1.2 | 1,669 | 10/12/2012 |
1.0.0 | 1,363 | 10/12/2012 |