Skip to content

Commit

Permalink
Added Id to the structure service.
Browse files Browse the repository at this point in the history
  • Loading branch information
tidyui committed Jan 3, 2021
1 parent 1589fe2 commit a931f8b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/Statica/Models/StaticStructure.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Håkan Edling
* Copyright (c) 2019-2021 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand All @@ -8,8 +8,6 @@
*
*/

using System.Collections.Generic;

namespace Statica.Models
{
public class StaticStructure
Expand Down
10 changes: 9 additions & 1 deletion src/Statica/Services/IStaticaService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Håkan Edling
* Copyright (c) 2019-2021 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand All @@ -8,6 +8,8 @@
*
*/

using System.Collections.Generic;

namespace Statica.Services
{
public interface IStaticaService
Expand All @@ -18,5 +20,11 @@ public interface IStaticaService
/// <param name="slug">The base slug</param>
/// <returns>The structure</returns>
IStructureService GetStructure(string slug);

/// <summary>
/// Gets all of the available structures.
/// </summary>
/// <returns>A collection of structures</returns>
IEnumerable<IStructureService> GetStructures();
}
}
7 changes: 6 additions & 1 deletion src/Statica/Services/IStructureService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Håkan Edling
* Copyright (c) 2019-2021 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand All @@ -15,6 +15,11 @@ namespace Statica.Services
{
public interface IStructureService
{
/// <summary>
/// Gets the unique structure id.
/// </summary>
string Id { get; }

/// <summary>
/// Gets the current sitemap.
/// </summary>
Expand Down
13 changes: 11 additions & 2 deletions src/Statica/Services/StaticaService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Håkan Edling
* Copyright (c) 2019-2021 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand Down Expand Up @@ -28,7 +28,7 @@ public StaticaService(params StaticStructure[] structures)
foreach (var structure in structures)
{
_structures[structure.Id] =
new StructureService(structure.BaseSlug, structure.DataPath);
new StructureService(structure.Id, structure.BaseSlug, structure.DataPath);
}
}

Expand All @@ -45,5 +45,14 @@ public IStructureService GetStructure(string id)
}
return null;
}

/// <summary>
/// Gets all of the available structures.
/// </summary>
/// <returns>A collection of structures</returns>
public IEnumerable<IStructureService> GetStructures()
{
return _structures.Values;
}
}
}
21 changes: 18 additions & 3 deletions src/Statica/Services/StructureService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Håkan Edling
* Copyright (c) 2019-2021 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand All @@ -19,7 +19,10 @@ namespace Statica.Services
{
public class StructureService : IStructureService
{
// The bas slug for the structure
// The unique id
private readonly string _id;

// The base slug for the structure
private readonly string _baseSlug;

/// The base path for the structure.
Expand All @@ -31,15 +34,27 @@ public class StructureService : IStructureService
/// Mutex for initialization.
private object mutex = new object();

public StructureService(string baseSlug, string dataPath)
/// <summary>
/// Default constructor.
/// </summary>
/// <param name="id">The unique id</param>
/// <param name="baseSlug">The base slug</param>
/// <param name="dataPath">The data path</param>
public StructureService(string id, string baseSlug, string dataPath)
{
_id = id;
_baseSlug = baseSlug;
_dataPath = dataPath;

if (!string.IsNullOrWhiteSpace(_baseSlug) && !_baseSlug.EndsWith("/"))
_baseSlug += "/";
}

/// <summary>
/// Gets the unique structure id.
/// </summary>
public string Id => _id;

/// <summary>
/// Gets the current page structure.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/Statica/Statica.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>0.3.1</Version>
<Version>0.3.2</Version>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

<PackageId>Statica</PackageId>
<PackageVersion>0.3.1</PackageVersion>
<PackageVersion>0.3.2</PackageVersion>
<Authors>Håkan Edling</Authors>
<Description>Piranha Module for generating a partial page structure from local markdown files.</Description>
<Copyright>Copyright 2019-2020 (c) Håkan Edling</Copyright>
<Copyright>Copyright 2019-2021 (c) Håkan Edling</Copyright>
<PackageTags>aspnetcore netstandard</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>statica.png</PackageIcon>
Expand Down

0 comments on commit a931f8b

Please sign in to comment.