Skip to content

Commit

Permalink
Work in progress : Posts and Assets
Browse files Browse the repository at this point in the history
  • Loading branch information
alanta committed Nov 18, 2020
1 parent 8ec92d3 commit ce5d408
Show file tree
Hide file tree
Showing 46 changed files with 602 additions and 264 deletions.
1 change: 1 addition & 0 deletions MemoirsTheme.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<ItemGroup>
<PackageReference Include="Kontent.Statiq" Version="1.0.0-beta0007" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.9" />
<PackageReference Include="Statiq.App" Version="1.0.0-beta.24" />
<PackageReference Include="Statiq.Sass" Version="1.0.0-beta.24" />
<PackageReference Include="Statiq.Web" Version="1.0.0-beta.8" />
Expand Down
23 changes: 21 additions & 2 deletions MemoirsTheme.sln
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.30413.136
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MemoirsTheme", "MemoirsTheme.csproj", "{FD3E8728-0F91-418E-8CA4-5F37B44FF70B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -12,7 +14,24 @@ Global
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FD3E8728-0F91-418E-8CA4-5F37B44FF70B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD3E8728-0F91-418E-8CA4-5F37B44FF70B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD3E8728-0F91-418E-8CA4-5F37B44FF70B}.Debug|x64.ActiveCfg = Debug|Any CPU
{FD3E8728-0F91-418E-8CA4-5F37B44FF70B}.Debug|x64.Build.0 = Debug|Any CPU
{FD3E8728-0F91-418E-8CA4-5F37B44FF70B}.Debug|x86.ActiveCfg = Debug|Any CPU
{FD3E8728-0F91-418E-8CA4-5F37B44FF70B}.Debug|x86.Build.0 = Debug|Any CPU
{FD3E8728-0F91-418E-8CA4-5F37B44FF70B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD3E8728-0F91-418E-8CA4-5F37B44FF70B}.Release|Any CPU.Build.0 = Release|Any CPU
{FD3E8728-0F91-418E-8CA4-5F37B44FF70B}.Release|x64.ActiveCfg = Release|Any CPU
{FD3E8728-0F91-418E-8CA4-5F37B44FF70B}.Release|x64.Build.0 = Release|Any CPU
{FD3E8728-0F91-418E-8CA4-5F37B44FF70B}.Release|x86.ActiveCfg = Release|Any CPU
{FD3E8728-0F91-418E-8CA4-5F37B44FF70B}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C1636CD0-F1A4-4C64-8E3C-3ABD1A6E922D}
EndGlobalSection
EndGlobal
29 changes: 29 additions & 0 deletions Models/ContentTypes/Author.Generated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This code was generated by a kontent-generators-net tool
// (see https://github.com/Kentico/kontent-generators-net).
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// For further modifications of the class, create a separate file with the partial class.

using System;
using System.Collections.Generic;
using Kentico.Kontent.Delivery.Abstractions;

namespace Kentico.Kontent.Statiq.Memoirs.Models
{
public partial class Author
{
public const string Codename = "author";
public const string AvatarImageCodename = "avatar_image";
public const string BioCodename = "bio";
public const string ContactsCodename = "contacts";
public const string EmailCodename = "email";
public const string NameCodename = "name";

public IEnumerable<IAsset> AvatarImage { get; set; }
public string Bio { get; set; }
public IEnumerable<object> Contacts { get; set; }
public string Email { get; set; }
public string Name { get; set; }
public IContentItemSystemAttributes System { get; set; }
}
}
10 changes: 10 additions & 0 deletions Models/ContentTypes/Author.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using Kentico.Kontent.Delivery.Abstractions;

namespace Kentico.Kontent.Statiq.Memoirs.Models
{
public partial class Author
{
}
}
25 changes: 25 additions & 0 deletions Models/ContentTypes/Contact.Generated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This code was generated by a kontent-generators-net tool
// (see https://github.com/Kentico/kontent-generators-net).
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// For further modifications of the class, create a separate file with the partial class.

using System;
using System.Collections.Generic;
using Kentico.Kontent.Delivery.Abstractions;

namespace Kentico.Kontent.Statiq.Memoirs.Models
{
public partial class Contact
{
public const string Codename = "contact";
public const string IconCodename = "icon";
public const string NameCodename = "name";
public const string UrlCodename = "url";

public string Icon { get; set; }
public string Name { get; set; }
public IContentItemSystemAttributes System { get; set; }
public string Url { get; set; }
}
}
10 changes: 10 additions & 0 deletions Models/ContentTypes/Contact.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using Kentico.Kontent.Delivery.Abstractions;

namespace Kentico.Kontent.Statiq.Memoirs.Models
{
public partial class Contact
{
}
}
2 changes: 2 additions & 0 deletions Models/ContentTypes/CustomTypeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public class CustomTypeProvider : ITypeProvider
{
private static readonly Dictionary<Type, string> _codenames = new Dictionary<Type, string>
{
{typeof(Author), "author"},
{typeof(CodeSnippet), "code_snippet"},
{typeof(Contact), "contact"},
{typeof(Container), "container"},
{typeof(CustomerCase), "customer_case"},
{typeof(GithubGist), "github_gist"},
Expand Down
3 changes: 2 additions & 1 deletion Models/ContentTypes/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace Kentico.Kontent.Statiq.Memoirs.Models
{
public partial class Post
public partial class Post: IPageMetadata
{
public string Url => $"{PostDate.Value.Year}/{PostDate.Value.Month:00}/{UrlPattern}.html";
}
}
23 changes: 23 additions & 0 deletions Models/IPageMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Kentico.Kontent.Delivery.Abstractions;
using System.Collections.Generic;

namespace Kentico.Kontent.Statiq.Memoirs.Models
{
public interface IPageMetadata
{
public string MetadataTwitterCreator { get; }
public string UrlPattern { get; }
public string MetadataMetaKeywords { get; }
public IEnumerable<IAsset> MetadataTwitterImage { get; }
public string MetadataOgTitle { get; }
public IEnumerable<IAsset> MetadataOgImage { get; }
public string MetadataTwitterSite { get; }
public string MetadataMetaDescription { get; }
public string MetadataMetaTitle { get; }
public string MetadataOgDescription { get; }

public string Title { get; }
public IEnumerable<IAsset> TeaserImage { get; }
public IEnumerable<IMultipleChoiceOption> MetadataTwitterCard { get; set; }
}
}
16 changes: 16 additions & 0 deletions Models/PostViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

namespace Kentico.Kontent.Statiq.Memoirs.Models
{
public class PostViewModel
{
public PostViewModel(Post post, Author author, SiteSettings metadata)
{
Post = post;
Author = author;
Metadata = metadata;
}
public Post Post { get; }
public Author Author { get; }
public SiteSettings Metadata { get; }
}
}
12 changes: 12 additions & 0 deletions Models/SiteSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Kentico.Kontent.Statiq.Memoirs.Models{
public class SiteSettings{
public string Name {get; set;}
public string Title {get; set;}
public string Description {get; set;}
public string Logo {get; set;}
public string Favicon {get; set;}
public bool LazyImages { get; set; }
public bool ImageShadow { get; set; }
public string Copyright { get; set; }
}
}
17 changes: 17 additions & 0 deletions Pipelines/Assets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Statiq.Common;
using Statiq.Core;

namespace Kentico.Kontent.Statiq.Lumen.Pipelines
{
public class Assets : Pipeline
{
public Assets()
{
InputModules = new ModuleList
{
new ReadFiles(pattern: "assets/**/*.{*,!scss}"),
new WriteFiles()
};
}
}
}
18 changes: 18 additions & 0 deletions Pipelines/Authors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Kentico.Kontent.Delivery.Abstractions;
using Kentico.Kontent.Statiq.Memoirs.Models;
using Kontent.Statiq;
using Statiq.Common;
using Statiq.Core;

namespace Kentico.Kontent.Statiq.Lumen.Pipelines
{
public class Authors : Pipeline
{
public Authors(IDeliveryClient deliveryClient)
{
InputModules = new ModuleList{
new Kontent<Author>(deliveryClient)
};
}
}
}
25 changes: 25 additions & 0 deletions Pipelines/DownloadImages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Kentico.Kontent.Statiq.Lumen.Pipelines;
using Kontent.Statiq;
using Statiq.Common;
using Statiq.Core;
using System.Linq;

namespace MemoirsTheme.Pipelines
{
public class DownloadImages : Pipeline
{
public DownloadImages()
{
Dependencies.AddRange(nameof(Posts));
PostProcessModules = new ModuleList(
// pull documents from other pipelines
new ReplaceDocuments(Dependencies.ToArray()),
new KontentDownloadImages()
);
OutputModules = new ModuleList(

new WriteFiles()
);
}
}
}
60 changes: 60 additions & 0 deletions Pipelines/Posts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Kentico.Kontent.Delivery.Abstractions;
using Kentico.Kontent.Delivery.Urls.QueryParameters;
using Kentico.Kontent.Statiq.Memoirs.Models;
using Kontent.Statiq;
using Statiq.Common;
using Statiq.Core;
using Statiq.Razor;
using System.Linq;

namespace Kentico.Kontent.Statiq.Lumen.Pipelines
{
public class Posts : Pipeline
{
public Posts(IDeliveryClient deliveryClient, SiteSettings site)
{
Dependencies.AddRange(nameof(Authors));
InputModules = new ModuleList{
new Kontent<Post>(deliveryClient)
.OrderBy(Post.PostDateCodename, SortOrder.Descending)
.WithQuery(new DepthParameter(1), new IncludeTotalCountParameter()),
/*new SetMetadata(nameof(Category), Config.FromDocument((doc, ctx) =>
{
// Add category (useful for grouping)
return doc.AsKontent<Article>().SelectedCategory.System.Codename;
})),
new SetMetadata(nameof(Article.SelectedCategory), Config.FromDocument((doc, ctx) =>
{
// Add some extra metadata to be used later for creating filenames
return doc.AsKontent<Article>().SelectedCategory;
})),
new SetMetadata(nameof(Tag), Config.FromDocument((doc, ctx) =>
{
// Add tag (useful for grouping)
return doc.AsKontent<Article>().TagObjects.Select(t=>t.System.Codename);
})),
new SetMetadata(nameof(Article.TagObjects), Config.FromDocument((doc, ctx) =>
{
// Add some extra metadata to be used later for creating filenames
return doc.AsKontent<Article>().TagObjects;
})),*/
new SetDestination(Config.FromDocument((doc, ctx) => new NormalizedPath($"posts/{doc.AsKontent<Post>().Url}" ))),
};

ProcessModules = new ModuleList {
new MergeContent(new ReadFiles(patterns: "Post.cshtml") ),
new RenderRazor()
.WithModel(Config.FromDocument((document, context) =>
new PostViewModel(document.AsKontent<Post>(),
context.Outputs.FromPipeline(nameof(Authors)).Select(x => x.AsKontent<Author>()).FirstOrDefault(),
site
))),
new KontentImageProcessor()
};

OutputModules = new ModuleList {
new WriteFiles(),
};
}
}
}
8 changes: 5 additions & 3 deletions Pipelines/StyleSheets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ public class StyleSheets : Pipeline
{
public StyleSheets()
{
InputModules = new ModuleList {
new ReadFiles(pattern: "_sass/**/{!_,}*.scss"),
InputModules = new ModuleList
{
new ReadFiles("_sass/**/{!_,}*.scss"),
new CompileSass()
.WithCompactOutputStyle(),
new SetDestination(".css"),
new SetDestination(Config.FromDocument((doc, ctx) =>
new NormalizedPath($"assets/css/{doc.Source.FileNameWithoutExtension}.css"))),
new WriteFiles()
};
}
Expand Down
7 changes: 7 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Extensions.Configuration;
using Statiq.Web;
using Kentico.Kontent.Statiq.Memoirs.Models;
using MemoirsTheme.Resolvers;

namespace MemoirsTheme
{
Expand All @@ -18,7 +19,13 @@ await Bootstrapper
.CreateDefault(args)
.ConfigureServices((services, settings) =>
{
// pull in site settings from configuration
var siteSettings = (settings as IConfiguration).GetSection("Site").Get<SiteSettings>();
services.AddSingleton(siteSettings);

services.AddSingleton<ITypeProvider, CustomTypeProvider>();
services.AddDeliveryInlineContentItemsResolver(new CodeSnippetResolver());
services.AddDeliveryInlineContentItemsResolver(new GitHubGistResolver());
services.AddDeliveryClient((IConfiguration)settings);
})
.AddHostingCommands()
Expand Down
14 changes: 14 additions & 0 deletions Resolvers/CodeSnippetResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Kentico.Kontent.Delivery.Abstractions;
using Kentico.Kontent.Statiq.Memoirs.Models;
using System.Linq;

namespace MemoirsTheme.Resolvers
{
public class CodeSnippetResolver : IInlineContentItemsResolver<CodeSnippet>
{
public string Resolve(CodeSnippet data)
{
return $"<pre><code class=\"language-{data.Language.First().Codename}\">{data.Code}</code></pre>";
}
}
}
Loading

0 comments on commit ce5d408

Please sign in to comment.