Refactor
This commit is contained in:
parent
43355f4377
commit
e010feaaba
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -186,4 +186,4 @@ Temporary Items
|
||||||
database.db
|
database.db
|
||||||
.bearer_token
|
.bearer_token
|
||||||
|
|
||||||
Pages/blog/posts/drafts
|
Posts/drafts
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System.ServiceModel.Syndication;
|
using System.ServiceModel.Syndication;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using zotanpw.Backend;
|
using zotanpw.Backend;
|
||||||
using zotanpw.Pages.blog;
|
using zotanpw.Pages;
|
||||||
|
|
||||||
namespace zotanpw.Controllers;
|
namespace zotanpw.Controllers;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using zotanpw.Pages.blog;
|
using zotanpw.Pages;
|
||||||
using J = System.Text.Json.Serialization.JsonPropertyNameAttribute;
|
using J = System.Text.Json.Serialization.JsonPropertyNameAttribute;
|
||||||
|
|
||||||
namespace zotanpw.Controllers;
|
namespace zotanpw.Controllers;
|
||||||
|
|
|
@ -8,13 +8,13 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
using YamlDotNet.Serialization;
|
using YamlDotNet.Serialization;
|
||||||
using YamlDotNet.Serialization.NamingConventions;
|
using YamlDotNet.Serialization.NamingConventions;
|
||||||
|
|
||||||
namespace zotanpw.Pages.blog;
|
namespace zotanpw.Pages;
|
||||||
|
|
||||||
public class BlogModel : PageModel {
|
public class BlogModel : PageModel {
|
||||||
public static readonly List<BlogPost> Posts = new();
|
public static readonly List<BlogPost> Posts = new();
|
||||||
|
|
||||||
static BlogModel() {
|
static BlogModel() {
|
||||||
foreach (var file in Directory.EnumerateFiles("Pages/blog/posts"))
|
foreach (var file in Directory.EnumerateFiles("Posts"))
|
||||||
if (file.EndsWith(".md"))
|
if (file.EndsWith(".md"))
|
||||||
Posts.Add(new BlogPost(Path.GetFileNameWithoutExtension(file)));
|
Posts.Add(new BlogPost(Path.GetFileNameWithoutExtension(file)));
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public class BlogModel : PageModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateContentAndMetadata() {
|
public void UpdateContentAndMetadata() {
|
||||||
var markdownText = System.IO.File.ReadAllText($"Pages/blog/posts/{Shorthand}.md");
|
var markdownText = System.IO.File.ReadAllText($"Posts/{Shorthand}.md");
|
||||||
|
|
||||||
var parsed = ParseBlogPost(markdownText);
|
var parsed = ParseBlogPost(markdownText);
|
||||||
Title = parsed.metadata.Title!;
|
Title = parsed.metadata.Title!;
|
|
@ -1,6 +1,6 @@
|
||||||
@page "/blog/{post}"
|
@page "/blog/{post}"
|
||||||
@model BlogPostModel
|
|
||||||
@using zotanpw.Backend
|
@using zotanpw.Backend
|
||||||
|
@model BlogPostModel
|
||||||
|
|
||||||
@{
|
@{
|
||||||
if (Model.Post == null)
|
if (Model.Post == null)
|
|
@ -1,20 +1,18 @@
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
namespace zotanpw.Pages.blog;
|
namespace zotanpw.Pages;
|
||||||
|
|
||||||
public class BlogPostModel : PageModel {
|
public class BlogPostModel : PageModel {
|
||||||
public BlogModel.BlogPost? Post;
|
public BlogModel.BlogPost? Post;
|
||||||
|
|
||||||
public IActionResult OnGet() {
|
public IActionResult OnGet() {
|
||||||
if (string.IsNullOrWhiteSpace((string)RouteData.Values["post"]!)) {
|
if (string.IsNullOrWhiteSpace((string)RouteData.Values["post"]!))
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
|
||||||
|
|
||||||
Post = BlogModel.Posts.FirstOrDefault(p => p.Shorthand == (string)RouteData.Values["post"]!);
|
Post = BlogModel.Posts.FirstOrDefault(p => p.Shorthand == (string)RouteData.Values["post"]!);
|
||||||
if (Post == null) {
|
if (Post == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
|
||||||
|
|
||||||
return Page();
|
return Page();
|
||||||
}
|
}
|
Loading…
Reference in a new issue