start to move things to config

This commit is contained in:
tparnell
2019-02-02 13:49:46 -05:00
parent 6ed0ef4205
commit f3080faae0
7 changed files with 40 additions and 13 deletions

View File

@@ -15,6 +15,12 @@ namespace TerribleDev.Blog.Web.Controllers
{
public class SeoController : Controller
{
private readonly BlogConfiguration configuration;
public SeoController(BlogConfiguration configuration)
{
this.configuration = configuration;
}
public static DateTimeOffset publishDate = DateTimeOffset.UtcNow; // keep publish date in memory so we just return when the server was kicked
public static IEnumerable<SyndicationItem> postsToSyndication = HomeController.postsAsList.Select(a => a.ToSyndicationItem()).ToList();
[Route("/rss")]
@@ -28,8 +34,8 @@ namespace TerribleDev.Blog.Web.Controllers
using (XmlWriter xmlWriter = XmlWriter.Create(this.Response.Body, new XmlWriterSettings() { Async = true, Indent = false, Encoding = Encoding.UTF8 }))
{
var writer = new RssFeedWriter(xmlWriter);
await writer.WriteTitle("The Ramblings of TerribleDev");
await writer.WriteValue("link", "https://blog.terribledev.io");
await writer.WriteTitle(configuration.Title);
await writer.WriteValue("link", configuration.Link);
await writer.WriteDescription("My name is Tommy Parnell. I usually go by TerribleDev on the internets. These are just some of my writings and rants about the software space.");
foreach (var item in postsToSyndication)
@@ -48,7 +54,7 @@ namespace TerribleDev.Blog.Web.Controllers
{
Response.StatusCode = 200;
Response.ContentType = "text/xml";
var sitewideLinks = new List<SiteMapItem>(HomeController.tagToPost.Keys.Select(a=> new SiteMapItem() { LastModified = DateTime.UtcNow, Location = $"https://blog.terribledev.io/tag/{a}/"}))
var sitewideLinks = new List<SiteMapItem>(HomeController.tagToPost.Keys.Select(a => new SiteMapItem() { LastModified = DateTime.UtcNow, Location = $"https://blog.terribledev.io/tag/{a}/" }))
{
new SiteMapItem() { LastModified = DateTime.UtcNow, Location="https://blog.terribledev.io/all-tags/" }
};

View File

@@ -0,0 +1,8 @@
namespace TerribleDev.Blog.Web.Models
{
public class BlogConfiguration
{
public string Title { get; set; }
public string Link { get; set; }
}
}

View File

@@ -15,6 +15,8 @@ using Microsoft.Extensions.FileProviders;
using Microsoft.Net.Http.Headers;
using HardHat.Middlewares;
using HardHat;
using TerribleDev.Blog.Web.Models;
namespace TerribleDev.Blog.Web
{
public class Startup
@@ -29,6 +31,9 @@ namespace TerribleDev.Blog.Web
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
var blogConfig = new BlogConfiguration();
Configuration.GetSection("Blog").Bind(blogConfig);
services.AddSingleton(blogConfig);
services.AddResponseCompression(a =>
{
a.EnableForHttps = true;

View File

@@ -1,4 +1,5 @@
@model IPost
@inject BlogConfiguration config
@model IPost
@{
ViewData["Title"] = "Post";
ViewData["HideNav"] = true;
@@ -13,7 +14,7 @@
<meta property="og:type" content="blog">
<meta property="og:title" content="@Model.Title">
<meta property="og:url" content="https://blog.terribledev.io/@Model.Url/">
<meta property="og:site_name" content="The Ramblings of TerribleDev">
<meta property="og:site_name" content="@config.Title">
<meta property="og:description" content="@Model.SummaryPlainShort">
<meta property="og:updated_time" content="@Model.PublishDate.ToString("O")">
<meta name="twitter:card" content="summary">

View File

@@ -1,11 +1,12 @@
<meta name="description" content="My name is Tommy Parnell. I usually go by TerribleDev on the internets. These are just some of my writings and rants about the software space." />
@inject BlogConfiguration config
<meta name="description" content="My name is Tommy Parnell. I usually go by TerribleDev on the internets. These are just some of my writings and rants about the software space." />
<meta property="og:type" content="blog">
<meta property="og:title" content="The Ramblings of TerribleDev">
<meta property="og:title" content="@config.Title">
<meta property="og:url" content="https://blog.terribledev.io/">
<meta property="og:site_name" content="The Ramblings of TerribleDev">
<meta property="og:site_name" content="@config.Title">
<meta property="og:description" content="My name is Tommy Parnell. I usually go by TerribleDev on the internets. These are just some of my writings and rants about the software space.">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="The Ramblings of TerribleDev">
<meta name="twitter:title" content="@config.Title">
<meta name="twitter:description" content="My name is Tommy Parnell. I usually go by TerribleDev on the internets. These are just some of my writings and rants about the software space.">
<meta name="twitter:creator" content="@@TerribleDev">
<meta property="og:image" content="https://www.gravatar.com/avatar/333e3cea32cd17ff2007d131df336061?s=640" />

View File

@@ -1,4 +1,6 @@
<!DOCTYPE html>
@inject BlogConfiguration config
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
@@ -11,7 +13,7 @@
<link rel="alternate" type="application/atom+xml" async title="RSS" href="/rss.xml">
<link rel="manifest" href="~/manifest.json" async asp-append-version="true">
<link asp-append-version="true" rel="icon" async href="~/favicon.ico" />
<title>@ViewData["Title"] - The Ramblings of TerribleDev</title>
<title>@ViewData["Title"] - @config.Title</title>
<environment names="Development">
<link asp-append-version="true" rel="stylesheet" href="~/css/site.css" />
</environment>
@@ -24,7 +26,7 @@
<partial name="Nav" />
<header class="header">
<svg aria-label="Open Menu" id="menuBtn" role="button" xmlns="http://www.w3.org/2000/svg" width="32" height="32"><path d="M4 10h24c1.104 0 2-.896 2-2s-.896-2-2-2H4c-1.104 0-2 .896-2 2s.896 2 2 2zm24 4H4c-1.104 0-2 .896-2 2s.896 2 2 2h24c1.104 0 2-.896 2-2s-.896-2-2-2zm0 8H4c-1.104 0-2 .896-2 2s.896 2 2 2h24c1.104 0 2-.896 2-2s-.896-2-2-2z" /></svg>
<div class="headerCallout"><a href="/" class="link-unstyled ">The Ramblings of TerribleDev</a></div>
<div class="headerCallout"><a href="/" class="link-unstyled ">@config.Title</a></div>
</header>
@{
var bodyBump = ViewData["HideNav"] == null ? "bodyWithNav": "";

View File

@@ -9,5 +9,9 @@
}
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Blog": {
"title": "The Ramblings of TerribleDev",
"link": "https://blog.terribledev.io"
}
}