meta tags refactor
This commit is contained in:
parent
696d9f3f89
commit
6e1a3ed50f
|
@ -38,4 +38,23 @@ public static class Utils {
|
||||||
|
|
||||||
public override Encoding Encoding { get; }
|
public override Encoding Encoding { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string Truncate(this string input, int maxLen, string truncateMarker = "...") {
|
||||||
|
var markerLength = truncateMarker.Length;
|
||||||
|
if (maxLen < 1 + markerLength)
|
||||||
|
maxLen = 1 + markerLength;
|
||||||
|
return input.Length <= maxLen ? input : input[..(maxLen - markerLength)] + truncateMarker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetUntil(this string input, string stopAt) {
|
||||||
|
if (!string.IsNullOrWhiteSpace(input)) {
|
||||||
|
if (!input.Contains(stopAt))
|
||||||
|
return input;
|
||||||
|
|
||||||
|
var charLocation = input.IndexOf(stopAt, StringComparison.Ordinal);
|
||||||
|
return input[..++charLocation];
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
@model BlogModel
|
@model BlogModel
|
||||||
@{
|
@{
|
||||||
ViewData["title"] = "blog";
|
ViewData["title"] = "blog";
|
||||||
ViewData["desc"] = "Blog of a disabled neurodivergent queer person unhappy with the state of the world.";
|
ViewData["og-desc"] = "Blog of a disabled neurodivergent queer person unhappy with the state of the world.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@section head {
|
@section head {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
@page "/blog/{post}"
|
@page "/blog/{post}"
|
||||||
|
@using System.Text.RegularExpressions
|
||||||
@using zotanpw.Backend
|
@using zotanpw.Backend
|
||||||
@model BlogPostModel
|
@model BlogPostModel
|
||||||
|
|
||||||
|
@ -8,7 +9,19 @@
|
||||||
|
|
||||||
ViewData["title"] = "blog";
|
ViewData["title"] = "blog";
|
||||||
ViewData["subtitle"] = Model.Post.Shorthand;
|
ViewData["subtitle"] = Model.Post.Shorthand;
|
||||||
ViewData["desc"] = Model.Post.Title;
|
ViewData["og-sitename"] = $"zotan.pw >> {ViewData["title"]}";
|
||||||
|
ViewData["og-title"] = Model.Post.Title;
|
||||||
|
|
||||||
|
if (System.IO.File.Exists($"wwwroot/files/blog/{Model.Post.Shorthand}.webp"))
|
||||||
|
ViewData["og-image"] = $"/files/blog/{Model.Post.Shorthand}.webp";
|
||||||
|
|
||||||
|
var desc = Model.Post.Content;
|
||||||
|
desc = Regex.Replace(desc, @"\s+", " "); // collapse whitespace
|
||||||
|
desc = Regex.Replace(desc, @"(?i)<\/?[aibu][^>]*>", ""); // remove <a>, <i>, <b> and <u> html tags
|
||||||
|
desc = desc.Trim(); // remove leading and trailing whitespace
|
||||||
|
desc = Regex.Match(desc, @"<p>([^<].*?)<\/p>").Groups[1].ToString().GetUntil("."); // get first sentence
|
||||||
|
ViewData["og-desc"] = desc;
|
||||||
|
|
||||||
#if (DEBUG)
|
#if (DEBUG)
|
||||||
Model.Post.UpdateContentAndMetadata();
|
Model.Post.UpdateContentAndMetadata();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
@model IndexModel
|
@model IndexModel
|
||||||
@{
|
@{
|
||||||
ViewData["title"] = "home";
|
ViewData["title"] = "home";
|
||||||
ViewData["desc"] = "Website of a queer software, systems, and network engineer.";
|
ViewData["og-desc"] = "Website of a queer software, systems, and network engineer.";
|
||||||
var travelynx = new Database.DbConn().TravelynxInfo.ToList();
|
var travelynx = new Database.DbConn().TravelynxInfo.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
@{
|
@{
|
||||||
ViewData["title"] = "now playing";
|
ViewData["title"] = "now playing";
|
||||||
|
ViewData["og-desc"] = "Here you can see what kind of music I've been listening to lately.";
|
||||||
var db = new Database.DbConn();
|
var db = new Database.DbConn();
|
||||||
var albums = db.AlbumHistory.OrderByDescending(p => p.DateTime).Take(30);
|
var albums = db.AlbumHistory.OrderByDescending(p => p.DateTime).Take(30);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,27 @@
|
||||||
@using zotanpw.Backend
|
@using zotanpw.Backend
|
||||||
|
@{
|
||||||
|
var title = ViewData.ContainsKey("subtitle") ? $"zotan.pw >> {ViewData["title"]} >> {ViewData["subtitle"]}" : $"zotan.pw >> {ViewData["title"]}";
|
||||||
|
if (string.IsNullOrEmpty(ViewData["og-title"] as string))
|
||||||
|
ViewData["og-title"] = title;
|
||||||
|
}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8"/>
|
||||||
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
<meta http-equiv="X-UA-Compatible" content="chrome=1"/>
|
||||||
<meta name="twitter:card" content="summary"/>
|
<meta name="twitter:card" content="summary"/>
|
||||||
<meta name="og:title" content="zotan.pw >> @ViewData["title"]"/>
|
<meta name="og:title" content="@ViewData["og-title"]"/>
|
||||||
<meta name="og:description" content="@ViewData["desc"]"/>
|
<meta name="og:description" content="@ViewData["og-desc"]"/>
|
||||||
@if (ViewData.ContainsKey("subtitle")) {
|
<meta name="og:site_name" content="@Html.Encode(ViewData["og-sitename"])"/>
|
||||||
<title>zotan.pw >> @ViewData["title"] >> @ViewData["subtitle"]</title>
|
<meta name="og:image" content="@ViewData["og-image"]"/>
|
||||||
}
|
|
||||||
else {
|
<title>@title</title>
|
||||||
<title>zotan.pw >> @ViewData["title"]</title>
|
|
||||||
}
|
|
||||||
<link rel="stylesheet" href="~/css/site.css?v=@Utils.LinkVersion"/>
|
<link rel="stylesheet" href="~/css/site.css?v=@Utils.LinkVersion"/>
|
||||||
|
@await RenderSectionAsync("head", false)
|
||||||
<environment include="Production">
|
<environment include="Production">
|
||||||
<script async defer data-website-id="06fcb20d-431a-4251-b6cb-859d9a7384ee" src="https://evilthirdparty.click/spyinator3000.js"></script>
|
<script async defer data-website-id="06fcb20d-431a-4251-b6cb-859d9a7384ee" src="https://evilthirdparty.click/spyinator3000.js"></script>
|
||||||
</environment>
|
</environment>
|
||||||
@await RenderSectionAsync("head", false)
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
|
|
Loading…
Reference in a new issue