An open API service indexing awesome lists of open source software.

https://github.com/xshaheen/xdot-sitemap

A package for .NET to help you build a sitemap according to the google recommendations.
https://github.com/xshaheen/xdot-sitemap

csharp dotnet seo sitemap xml

Last synced: 7 months ago
JSON representation

A package for .NET to help you build a sitemap according to the google recommendations.

Awesome Lists containing this project

README

          

# Xdot.Sitemap

A package for .NET to help you build a sitemap according to the google recommendations. see [this link to learn about sitemaps][sitemap-google-docs].

**if you like this work, please consider give the project star 🌟**

## Installation

Using the [.NET CLI tools][dotnet-core-cli-tools]:

```sh
dotnet add package Xdot.Sitemap
```

Using the [NuGet CLI][nuget-cli]:

```sh
nuget install Xdot.Sitemap
```

Using the [Package Manager Console][package-manager-console]:

```powershell
Install-Package Xdot.Sitemap
```

## Usage

### Write a sitemap to stream

```c#
var urls = new List
{
new("https://www.example.com"),
new("https://www.example.com/contact-us"),
}

await using var stream = new MemoryStream();
await urls.WriteToAsync(stream);
```

This code will write the following to the memory stream:

```xml


https://www.example.com


https://www.example.com/contact-us

```

### Write localized versions for a URL

```c#
var urls = new List
{
new(new SitemapAlternateUrl[]
{
new()
{
Location = "https://www.example.com/english/page.html",
LanguageCode = "en",
},
new()
{
Location = "https://www.example.com/deutsch/page.html",
LanguageCode = "de",
},
new()
{
Location = "https://www.example.com/schweiz-deutsch/page.html",
LanguageCode = "de-ch",
},
}),

// ...
};

await using var stream = new MemoryStream();
await urls.WriteToAsync(stream);
```

This code will write the following to the memory stream:

```xml


https://www.example.com/english/page.html





https://www.example.com/deutsch/page.html





https://www.example.com/schweiz-deutsch/page.html



```

### Write Sitemap Index

```c#
var sitemapReferences = new List
{
new() { Location = "https://www.Example.com/ümlaT-sitemap.xml" },
new() { Location = "https://www.example.com/اداره-اعلانات" },
}

await using var stream = new MemoryStream()
await references.WriteToAsync(stream);
```
This code will write the following to the memory stream:

```xml


https://www.example.com/%C3%BCmlat-sitemap.xml


https://www.example.com/%D8%A7%D8%AF%D8%A7%D8%B1%D9%87-%D8%A7%D8%B9%D9%84%D8%A7%D9%86%D8%A7%D8%AA

```

## License

This project is licensed under the Apache 2.0 license.

## Contact

If you have any suggestions, comments or questions, please feel free to contact me on:

Email: mxshaheen@gmail.com

[sitemap-google-docs]: https://developers.google.com/search/docs/advanced/sitemaps/overview
[dotnet-core-cli-tools]: https://docs.microsoft.com/en-us/dotnet/core/tools/
[nuget-cli]: https://docs.microsoft.com/en-us/nuget/tools/nuget-exe-cli-reference
[package-manager-console]: https://docs.microsoft.com/en-us/nuget/tools/package-manager-console