Skip to content

Commit

Permalink
Merge branch 'ernado-x:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado-x authored Sep 10, 2024
2 parents 6416f64 + e19ca53 commit 4db1f69
Show file tree
Hide file tree
Showing 21 changed files with 211 additions and 240 deletions.
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
[![NuGet version](https://badge.fury.io/nu/xsitemap.svg)](https://badge.fury.io/nu/xsitemap)
[![Part of awesome .NET Core](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/thangchung/awesome-dotnet-core#tools)
[![Twitter URL](https://img.shields.io/twitter/url/https/twitter.com/andrew_gubskiy.svg?style=social&label=Follow%20me!)](https://twitter.com/intent/user?screen_name=andrew_gubskiy)

# X.Web.Sitemap
# X.Web.Sitemap

Simple sitemap generator for .NET
[![NuGet Version](http://img.shields.io/nuget/v/X.Web.Sitemap.svg?style=flat)](https://www.nuget.org/packages/X.Web.Sitemap/)
[![Twitter URL](https://img.shields.io/twitter/url/https/twitter.com/andrew_gubskiy.svg?style=social&label=Follow%20me!)](https://twitter.com/intent/user?screen_name=andrew_gubskiy)

⚠️ **See breaking changes for [release 2.9.2](https://github.com/ernado-x/X.Web.Sitemap/releases/tag/v2.9.2)**

You can download it from nuget.org at http://nuget.org/packages/xsitemap/
X.Web.Sitemap is a library for generating and managing sitemaps in .NET applications.

## Usage example

Expand All @@ -23,9 +19,9 @@ Below is an example of basic usage in a non-testable manner

sitemap.Add(new Url
{
ChangeFrequency = ChangeFrequency.Daily,
ChangeFrequency = ChangeFrequency.Hourly,
Location = "http://www.example.com",
Priority = 0.5,
Priority = 0.8,
TimeStamp = DateTime.Now
});

Expand Down
24 changes: 18 additions & 6 deletions X.Web.Sitemap.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 15.0.26403.7
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DD3DEEE0-ABF3-4DFB-A5A9-14AA3FB1DBA2}"
ProjectSection(SolutionItems) = preProject
src\Directory.Build.props = src\Directory.Build.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{5662CFB2-6193-4FB8-BBA3-B5822FDB583F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "X.Web.Sitemap.Tests", "tests\X.Web.Sitemap.Tests\X.Web.Sitemap.Tests.csproj", "{5AA327E0-C63F-4567-9C09-23707EB5E4C4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "X.Web.Sitemap", "src\X.Web.Sitemap\X.Web.Sitemap.csproj", "{704FA5E2-2694-44C9-826E-85C2CEC96D5D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "X.Web.Sitemap.Example", "src\X.Web.Sitemap.Example\X.Web.Sitemap.Example.csproj", "{97B9B296-63C0-4816-AD53-E069E6BDEF66}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{9428EFB0-FF29-406C-91E5-89B9C85E093A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "X.Web.Sitemap.Example", "examples\X.Web.Sitemap.Example\X.Web.Sitemap.Example.csproj", "{1E7AAF8C-08EB-4918-B987-618F8D06F43C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xsitemap", "src\xsitemap\xsitemap.csproj", "{03ABE12B-69FB-4E5F-A9A1-8B3257D90480}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,17 +34,22 @@ Global
{704FA5E2-2694-44C9-826E-85C2CEC96D5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{704FA5E2-2694-44C9-826E-85C2CEC96D5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{704FA5E2-2694-44C9-826E-85C2CEC96D5D}.Release|Any CPU.Build.0 = Release|Any CPU
{97B9B296-63C0-4816-AD53-E069E6BDEF66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{97B9B296-63C0-4816-AD53-E069E6BDEF66}.Debug|Any CPU.Build.0 = Debug|Any CPU
{97B9B296-63C0-4816-AD53-E069E6BDEF66}.Release|Any CPU.ActiveCfg = Release|Any CPU
{97B9B296-63C0-4816-AD53-E069E6BDEF66}.Release|Any CPU.Build.0 = Release|Any CPU
{1E7AAF8C-08EB-4918-B987-618F8D06F43C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E7AAF8C-08EB-4918-B987-618F8D06F43C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E7AAF8C-08EB-4918-B987-618F8D06F43C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E7AAF8C-08EB-4918-B987-618F8D06F43C}.Release|Any CPU.Build.0 = Release|Any CPU
{03ABE12B-69FB-4E5F-A9A1-8B3257D90480}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03ABE12B-69FB-4E5F-A9A1-8B3257D90480}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03ABE12B-69FB-4E5F-A9A1-8B3257D90480}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03ABE12B-69FB-4E5F-A9A1-8B3257D90480}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5AA327E0-C63F-4567-9C09-23707EB5E4C4} = {5662CFB2-6193-4FB8-BBA3-B5822FDB583F}
{704FA5E2-2694-44C9-826E-85C2CEC96D5D} = {DD3DEEE0-ABF3-4DFB-A5A9-14AA3FB1DBA2}
{97B9B296-63C0-4816-AD53-E069E6BDEF66} = {DD3DEEE0-ABF3-4DFB-A5A9-14AA3FB1DBA2}
{1E7AAF8C-08EB-4918-B987-618F8D06F43C} = {9428EFB0-FF29-406C-91E5-89B9C85E093A}
{03ABE12B-69FB-4E5F-A9A1-8B3257D90480} = {DD3DEEE0-ABF3-4DFB-A5A9-14AA3FB1DBA2}
EndGlobalSection
EndGlobal
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public List<Url> GetUrls(string domain)
var productPageUrlStrings = GetHighPriorityProductPageUrls(domain);

//--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! :)
// and the 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>default</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\X.Web.Sitemap\X.Web.Sitemap.csproj" />
<ProjectReference Include="..\..\src\X.Web.Sitemap\X.Web.Sitemap.csproj"/>
</ItemGroup>

</Project>
24 changes: 24 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project>

<PropertyGroup>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>

<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<PackageIcon>x-web.png</PackageIcon>

<Authors>Andrew Gubskiy</Authors>
<Copyright>Andrew Gubskiy © 2024</Copyright>
<Company>Ukrainian .NET Developer Community</Company>

<Version>2.10.3</Version>
<AssemblyVersion>2.10.3</AssemblyVersion>
<FileVersion>2.10.3</FileVersion>
<PackageVersion>2.10.3</PackageVersion>

<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/ernado-x/X.Web.Sitemap.git</RepositoryUrl>
<PackageProjectUrl>https://andrew.gubskiy.com/open-source</PackageProjectUrl>
</PropertyGroup>

</Project>
14 changes: 14 additions & 0 deletions src/X.Web.Sitemap/FileSystemWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
using System;
using System.IO;
using System.Threading.Tasks;
using JetBrains.Annotations;

namespace X.Web.Sitemap;

[PublicAPI]
internal interface IFileSystemWrapper
{
/// <summary>
/// Writes the specified XML to the specified path.
/// </summary>
/// <param name="xml"></param>
/// <param name="path"></param>
/// <returns></returns>
FileInfo WriteFile(string xml, string path);

/// <summary>
/// Writes the specified XML to the specified path asynchronously.
/// </summary>
/// <param name="xml"></param>
/// <param name="path"></param>
/// <returns></returns>
Task<FileInfo> WriteFileAsync(string xml, string path);
}

Expand Down
4 changes: 2 additions & 2 deletions src/X.Web.Sitemap/Generators/SitemapGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public List<FileInfo> GenerateSitemaps(IEnumerable<Url> urls, DirectoryInfo targ
{
var sitemaps = BuildSitemaps(urls.ToList(), MaxNumberOfUrlsPerSitemap);

var sitemapFileInfos = SaveSitemaps(targetDirectory, sitemapBaseFileNameWithoutExtension, sitemaps);
var result = SaveSitemaps(targetDirectory, sitemapBaseFileNameWithoutExtension, sitemaps);

return sitemapFileInfos;
return result;
}

private static List<Sitemap> BuildSitemaps(IReadOnlyList<Url> urls, int maxNumberOfUrlsPerSitemap)
Expand Down
48 changes: 48 additions & 0 deletions src/X.Web.Sitemap/Image.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.ComponentModel;
using System.Xml.Serialization;
using JetBrains.Annotations;

namespace X.Web.Sitemap;

[PublicAPI]
[Serializable]
[Description("Encloses all information about a single image. Each URL (<loc> tag) can include up to 1,000 <image:image> tags.")]
[XmlRoot(ElementName = "image", Namespace = "http://www.google.com/schemas/sitemap-image/1.1")]
public class Image
{
/// <summary>
/// Location of the image.
/// </summary>
[Description("The URL of the image.")]
[XmlElement(ElementName = "loc", Namespace = "http://www.google.com/schemas/sitemap-image/1.1")]
public string Location { get; set; } = "";

/// <summary>
/// Caption of the image.
/// </summary>
[Description("The caption of the image.")]
[XmlElement(ElementName = "caption", Namespace = "http://www.google.com/schemas/sitemap-image/1.1")]
public string? Caption { get; set; }

/// <summary>
/// Geographic location of the image.
/// </summary>
[Description("The geographic location of the image. For example, \"Limerick, Ireland\".")]
[XmlElement(ElementName = "geo_location", Namespace = "http://www.google.com/schemas/sitemap-image/1.1")]
public string? GeographicLocation { get; set; }

/// <summary>
/// Title of the image.
/// </summary>
[Description("The title of the image.")]
[XmlElement(ElementName = "title", Namespace = "http://www.google.com/schemas/sitemap-image/1.1")]
public string? Title { get; set; }

/// <summary>
/// License of the image.
/// </summary>
[Description("A URL to the license of the image.")]
[XmlElement(ElementName = "license", Namespace = "http://www.google.com/schemas/sitemap-image/1.1")]
public string? License { get; set; }
}
157 changes: 0 additions & 157 deletions src/X.Web.Sitemap/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/X.Web.Sitemap/Serializers/SitemapIndexSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface ISitemapIndexSerializer

public class SitemapIndexSerializer : ISitemapIndexSerializer
{
private readonly XmlSerializer _serializer = new XmlSerializer(typeof(SitemapIndex));
private readonly XmlSerializer _serializer = new(typeof(SitemapIndex));

public string Serialize(SitemapIndex sitemapIndex)
{
Expand Down
Loading

0 comments on commit 4db1f69

Please sign in to comment.