Skip to content

Commit

Permalink
Added variables to XMD file
Browse files Browse the repository at this point in the history
New variables:
- `${cdnRoot}` --> `https://cdn.czsoft.hu/`
- `${cdnScheme}` --> `https`
- `${cdnHost}` --> `cdn.czsoft.hu`
- `${assetPath:assetType}` --> `${cdnRoot}assetType/product@version/`
- `${assetTypeRoot:assetType}` --> `${cdnRoot}assetType/`
  • Loading branch information
Czompi committed Mar 27, 2023
1 parent 2feb3e6 commit e786d3a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CWCT-MA/CWCT-MA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Copyright>Czompi Software 2023</Copyright>
<LangVersion>10.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Version>4.1.0.18</Version>
<Version>4.1.0.19</Version>
<UserSecretsId>856522d9-149d-4315-86cb-58ef7be680cd</UserSecretsId>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
</PropertyGroup>
Expand Down
16 changes: 16 additions & 0 deletions CWCT-MA/Model/AssetType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace CSCDNMA.Model;

public enum HostEnvironment
{
Development,
Staging,
Production
}
public enum AssetType
{
CSS,
JS,
IMG,
FONTS,
FONT
}
3 changes: 0 additions & 3 deletions CWCT-MA/Model/Globals.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using CwctMa.Helpers;
using CwctMa.Model.Xmd;
using Markdig;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text.Json;
Expand Down
11 changes: 11 additions & 0 deletions CWCT-MA/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page "/{*remaining}"
@using CSCDNMA.Model;
@using CwctMa.Model.Xmd
@using CwctMa.Helpers
@using Markdig
Expand All @@ -7,12 +8,22 @@
@inject ILogger<Index> _logger;
@if (File.Exists(FileName))
{
var cdnUri = new Uri(Globals.Config.CdnUrl);
var markdownFile = File.ReadAllText(FileName);
var header = $"{markdownFile[0..(markdownFile.IndexOf("</metadata>", StringComparison.OrdinalIgnoreCase)+"</metadata>".Length)]}";
//var meta = Globals.GetMetadata(Remaining ?? "");
var meta = header.ParseXml<Metadata>();
title = meta.Title;
markdownFile = markdownFile[(header.Count())..];

foreach (var t in Enum.GetNames<AssetType>())
{
@*markdownFile = markdownFile.Replace($"${{assetPath:{t}}}", $"${{assetTypeRoot:{t}}}{product}@{version}/", StringComparison.OrdinalIgnoreCase);*@
markdownFile = markdownFile.Replace($"${{assetTypeRoot:{t}}}", $"${{cdnRoot}}{t.ToLowerInvariant()}/", StringComparison.OrdinalIgnoreCase);
}
markdownFile = markdownFile.Replace($"${{cdnRoot}}", "https://${cdnHost}/", StringComparison.OrdinalIgnoreCase);
markdownFile = markdownFile.Replace($"${{cdnScheme}}", $"{cdnUri.Scheme}", StringComparison.OrdinalIgnoreCase);
markdownFile = markdownFile.Replace($"${{cdnHost}}", $"{cdnUri.DnsSafeHost}", StringComparison.OrdinalIgnoreCase);
@((MarkupString)Markdown.ToHtml(markdownFile, Globals.MarkdownPipeline))

if (meta.ShowModifiedAt)
Expand Down

0 comments on commit e786d3a

Please sign in to comment.