Skip to content

Commit

Permalink
Added HTML titles support
Browse files Browse the repository at this point in the history
  • Loading branch information
Pxtl committed Nov 28, 2023
1 parent 26bc579 commit a980665
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion SnowSite/Snow/snow.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},{
"file": "categories.cshtml => category"
},{
"file": "archive.cshtml"
"file": "archive.cshtml",
"title": "Archive"
},{
"file": "about.cshtml"
},{
Expand Down
3 changes: 2 additions & 1 deletion SnowSite/Snow/themes/default/_layouts/default.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@using System.Collections.Generic
@{
var keywords = String.Join(",", Model.Keywords);
var title = String.Join("", Model.HeaderTitleChain);
}
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
Expand All @@ -10,7 +11,7 @@
<meta name="viewport" content="width=device-width" />
<meta http-equiv="last-modified" content="@Model.GeneratedDate" />
<meta name="keywords" content="@keywords" />
<title>philliphaydon.com</title>
<title>@title</title>
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css" />
@Html.CanonicalUrl()
</head>
Expand Down
4 changes: 4 additions & 0 deletions src/Snow/StaticFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ public class StaticFile
{
public string File { get; set; }
public string Loop { get; set; }
/// <summary>
/// File title to use in header title if it's HTML. May be overridden by loop.
/// </summary>
public string Title { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Snow/StaticFileProcessors/BaseProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using Enums;

public abstract class BaseProcessor
Expand All @@ -20,6 +21,9 @@ public void Process(SnowyData snowyData, SnowSettings settings)
ParseDirectories(snowyData);
TestModule.StaticFile = SourceFile;
TestModule.Published = Published.True;
TestModule.HeaderTitleChain = new string[] { snowyData.File.Title, TestModule.Settings.BlogTitle }
.Where(t => !string.IsNullOrWhiteSpace(t))
.ToList();

Impl(snowyData, settings);
}
Expand Down
1 change: 1 addition & 0 deletions src/Snow/StaticFileProcessors/CategoriesProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ protected override void Impl(SnowyData snowyData, SnowSettings settings)
var posts = GetPosts(snowyData.Files, category);

TestModule.Category = category;
TestModule.HeaderTitleChain = new[] { category.Name, "Categories", TestModule.Settings.BlogTitle };
TestModule.GeneratedUrl = settings.SiteUrl + "/category/" + category.Url + "/";
TestModule.PostsInCategory = posts.ToList();

Expand Down
3 changes: 2 additions & 1 deletion src/Snow/StaticFileProcessors/DraftsProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Snow.StaticFileProcessors
{
using Enums;
using Snow.Models;

public class DraftsProcessor : StaticFileProcessor
{
Expand All @@ -12,7 +13,7 @@ public override string ProcessorName
protected override void Impl(SnowyData snowyData, SnowSettings settings)
{
TestModule.Published = Published.Draft;

TestModule.HeaderTitleChain = new[] { "Drafts", TestModule.Settings.BlogTitle };
base.Impl(snowyData, settings);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Snow/TestModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public static string GeneratedDate
get { return Date; }
}

//Title to pass to viewmodel, changes on iterations.
public static IEnumerable<string> HeaderTitleChain { get; set; }

//Data changes on iterations
public static Post Data { get; set; }
public static string StaticFile { get; set; }
Expand Down Expand Up @@ -66,6 +69,7 @@ public TestModule()
NextPage = PageNumber + 1,
PreviousPage = PageNumber - 1,
MonthYearList = MonthYear,
HeaderTitleChain = HeaderTitleChain,
GeneratedDate = GeneratedDate,
Category = Category,
Drafts = Drafts,
Expand All @@ -89,6 +93,7 @@ public TestModule()
PostDate = Data.Date,
Layout = Data.Layout,
Title = Data.Title,
HeaderTitleChain = new string[] { Data.Title, Settings.BlogTitle },
GeneratedDate = GeneratedDate,
Url = Data.Url,
AllCategories = Categories,
Expand Down
5 changes: 5 additions & 0 deletions src/Snow/ViewModels/BaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace Snow.ViewModels

public abstract class BaseViewModel : DynamicDictionary
{
/// <summary>
/// Title of current view. Will generally be in order from most to least
/// specific, with final value always being site name.
/// </summary>
public IEnumerable<string> HeaderTitleChain { get; set; }
/// <summary>
/// All posts
/// </summary>
Expand Down

0 comments on commit a980665

Please sign in to comment.