commit to fs in core only

This commit is contained in:
Tommy Parnell
2019-01-30 21:58:53 -05:00
parent b7486dcc85
commit d8a0004bc5
9 changed files with 36 additions and 43 deletions

View File

@@ -10,6 +10,8 @@ module BlogFactory =
open Microsoft.AspNetCore.Html
open System.Linq
open System.Collections.Generic
open fs
open System
let fixTagName (tag:string) = tag.Replace(' ', '-').WithoutSpecialCharacters().ToLower()
let mapImgUrlResolver (resolveUrl:string) =
@@ -17,16 +19,15 @@ module BlogFactory =
let getPosts (path) = Directory.EnumerateFiles(path, "*.md", SearchOption.TopDirectoryOnly)
let parseYml (postText:string):PostSettings =
postText.Split("---").[0]
|> DeserializerBuilder().Build().Deserialize
let parseYml (postText:string) =
let split = postText.Split("---")
match split with
| [| _ |] -> raise(Exception("No yml found"))
| [| yml; _|] -> DeserializerBuilder().Build().Deserialize(yml)
| split when split.Length > 2 -> DeserializerBuilder().Build().Deserialize(split.[0])
let getFileInfo (filePath:string) =
let fileInfo = FileInfo(filePath)
async {
let! text = File.ReadAllTextAsync(fileInfo.FullName) |> Async.AwaitTask
return (text, fileInfo)
}
let getMarkdownBuilder (imgRef) =
MarkdownPipelineBuilder()
.Use<TargetLinkExtension>()
@@ -55,7 +56,7 @@ module BlogFactory =
let images = images |> Seq.distinct |> Seq.map mapImgUrlFromResolved |> Seq.toList
{
PublishDate = postSettings.date.ToUniversalTime();
tags = tags |> System.Collections.Generic.List
tags = tags |> Seq.toList
Title = postSettings.title;
Url = resolvedUrl;
Content = HtmlString(postContent);
@@ -63,7 +64,7 @@ module BlogFactory =
SummaryPlain = postSummaryPlain;
SummaryPlainShort = summaryPlainShort;
ContentPlain = postContentPlain;
Images = images |> System.Collections.Generic.List
Images = images |> Seq.toList
}
let getAllPosts path =
getPosts path

View File

@@ -12,6 +12,6 @@ type Post =
ContentPlain: string;
SummaryPlain: string;
SummaryPlainShort: string;
tags : System.Collections.Generic.List<string>
Images: System.Collections.Generic.List<string>
tags : List<string>
Images: List<string>
}

View File

@@ -3,6 +3,8 @@
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Util\fs.fs" />
<Compile Include="Util\Constants.fs" />
<Compile Include="Util\Async.fs" />
<Compile Include="Models\PostSettings.fs" />
<Compile Include="Models\Post.fs" />

View File

@@ -0,0 +1,8 @@
module Constants
module Constants=
let MORE = "<!-- more -->"
let YMLDIVIDER = "---"
type Tokens =
| MORE
| YMLDIVIDER

View File

@@ -0,0 +1,10 @@
module fs
open System.IO
let getFileInfo (filePath:string) =
let fileInfo = FileInfo(filePath)
async {
let! text = File.ReadAllTextAsync(fileInfo.FullName) |> Async.AwaitTask
return (text, fileInfo)
}

View File

@@ -1,9 +0,0 @@
using Microsoft.AspNetCore.Html;
namespace TerribleDev.Blog.Web.Models
{
public class PostModel
{
public HtmlString Content { get; set; }
}
}

View File

@@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
namespace TerribleDev.Blog.Web.Models
{
public class PostSettings
{
public List<string> tags { get; set; }
public string title { get; set; }
public string permalink { get; set; }
public DateTime date { get; set; }
public DateTime updated { get; set; }
public string id { get; set; }
public string thumbnail_image { get; set; }
public string thumbnailImage { get; set; }
public string thumbnail_image_position { get; set; }
public string layout { get; set; }
}
}

View File

@@ -25,7 +25,7 @@
{
<meta property="og:image" content="https://blog.terribledev.io@(image)">
}
@if(Model.Images.Count > 0)
@if(Model.Images.Length > 0)
{
<meta name="twitter:image" content="https://blog.terribledev.io@(Model.Images[0])">
}

View File

@@ -4,7 +4,7 @@
<h1 itemprop="headline" class="headline">@Model.Title</h1>
<time class="headlineSubtext" itemprop="datePublished" content="@Model.PublishDate.ToString()">@Model.PublishDate.ToString("D")</time>
@Model.Content
@if (Model.tags.Count > 0)
@if (Model.tags.Length > 0)
{
<div>
<span>Tagged In:</span><br />