From 3bdd8dad0006860c03f84b448dbee5c1fd4baac7 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Mon, 16 Oct 2023 11:19:10 -0300 Subject: [PATCH] fix: force unix path style --- source/Helpers/Urlizer.cs | 7 +++++++ source/Models/FrontMatter.cs | 6 ++++-- source/Models/IFile.cs | 7 ++++--- source/Models/Site.cs | 5 +++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/source/Helpers/Urlizer.cs b/source/Helpers/Urlizer.cs index 0b83bfd..5d07b96 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 a3d82f7..eddbeb6 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 ad7bed8..d3f007c 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 eb71d04..dd89c68 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 -- GitLab