diff --git a/source/Helpers/Urlizer.cs b/source/Helpers/Urlizer.cs index 0b83bfdcfe8e1e8826c6b568f9268cb0b1ac1a69..5d07b9698b118f368c3385451590a29ded05fe0c 100644 --- a/source/Helpers/Urlizer.cs +++ b/source/Helpers/Urlizer.cs @@ -62,6 +62,13 @@ public static partial class Urlizer } return (path.StartsWith('/') ? '/' : string.Empty) + string.Join('/', result); } + + /// + /// Convert all paths to a unix path style + /// + /// + /// + public static string Path(string? path) => (path ?? string.Empty).Replace('\\', '/'); } /// diff --git a/source/Models/FrontMatter.cs b/source/Models/FrontMatter.cs index a3d82f718dbbad9c1a607aefb35083aa645fdc08..eddbeb67e7a610209e18e46b5c7d4ffbad3a68e7 100644 --- a/source/Models/FrontMatter.cs +++ b/source/Models/FrontMatter.cs @@ -70,11 +70,13 @@ public class FrontMatter : IFrontMatter /// [YamlIgnore] - public string? SourceRelativePathDirectory => Path.GetDirectoryName(SourceRelativePath); + public string? SourceRelativePathDirectory => (Path.GetDirectoryName(SourceRelativePath) ?? string.Empty) + .Replace('\\', '/'); /// [YamlIgnore] - public string? SourceFileNameWithoutExtension => Path.GetFileNameWithoutExtension(SourceRelativePath); + public string? SourceFileNameWithoutExtension => (Path.GetFileNameWithoutExtension(SourceRelativePath) ?? string.Empty) + .Replace('\\', '/'); /// [YamlIgnore] diff --git a/source/Models/IFile.cs b/source/Models/IFile.cs index ad7bed8e3a090aeb14c9fff7549de80598ae4d7b..d3f007c6ca9ef53ae2cbd08c7aeff5349b30b4e0 100644 --- a/source/Models/IFile.cs +++ b/source/Models/IFile.cs @@ -1,5 +1,6 @@ using System.IO; using Microsoft.AspNetCore.StaticFiles; +using SuCoS.Helpers; namespace SuCoS.Models; @@ -21,17 +22,17 @@ public interface IFile /// /// The source directory of the file, without the file name. /// - string? SourceRelativePathDirectory => Path.GetDirectoryName(SourceRelativePath); + string? SourceRelativePathDirectory => Urlizer.Path(Path.GetDirectoryName(SourceFullPath)); /// /// The full source directory of the file, without the file name. /// - string? SourceFullPathDirectory => Path.GetDirectoryName(SourceFullPath); + string? SourceFullPathDirectory => Urlizer.Path(Path.GetDirectoryName(SourceFullPath)); /// /// The source filename, without the extension. ;) /// - string? SourceFileNameWithoutExtension => Path.GetFileNameWithoutExtension(SourceRelativePath); + string? SourceFileNameWithoutExtension => Path.GetFileNameWithoutExtension(SourceFullPath); /// /// File extension. diff --git a/source/Models/Site.cs b/source/Models/Site.cs index eb71d04b48853a64a4b6d44ee696dc9f48307601..dd89c68c2801e7242bd7396c2a4014428d18ee20 100644 --- a/source/Models/Site.cs +++ b/source/Models/Site.cs @@ -246,12 +246,13 @@ public class Site : ISite { sectionName ??= "section"; var isIndex = string.IsNullOrEmpty(relativePath); + relativePath = Urlizer.Path(relativePath); FrontMatter frontMatter = new() { Kind = isIndex ? Kind.index : Kind.list, Section = isIndex ? "index" : sectionName, - SourceRelativePath = Path.Combine(relativePath, indexLeafFileConst), - SourceFullPath = Path.Combine(SourceContentPath, relativePath, indexLeafFileConst), + SourceRelativePath = Urlizer.Path(Path.Combine(relativePath, indexLeafFileConst)), + SourceFullPath = Urlizer.Path(Path.Combine(SourceContentPath, relativePath, indexLeafFileConst)), Title = title, Type = isIndex ? "index" : sectionName, URL = relativePath