Compare commits

...

8 Commits

Author SHA1 Message Date
9d46d6495e
fix: 0-pad Published properties 2023-08-10 22:53:15 +01:00
d6c24d80c1
fix: remove stdout diagnostic print 2023-08-10 22:52:43 +01:00
74e7187cba
chore: remove redundant NLog ref
this is implicitly ref'd by NLog.Extensions.Logging
2023-08-10 22:50:43 +01:00
8dd4468c1a
feat: gracefully shutdown logmanager on exit 2023-08-10 22:49:44 +01:00
dcbc402bfb
refactor: remove redundant ns import 2023-08-10 22:49:15 +01:00
cf615e1e81
fix: fix already-formatted <mark>
no really, I hate this.
2023-08-10 22:48:32 +01:00
086a8a665c
feat: capture ctrl+u for git repo redirect 2023-08-10 22:48:08 +01:00
cf2a5c2ffb
feat: add kb shortcut detection 2023-08-10 22:47:28 +01:00
8 changed files with 68 additions and 8 deletions

View File

@ -28,6 +28,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ts", "ts", "{BB9F76AC-292A-
src\ts\Author.ts = src\ts\Author.ts src\ts\Author.ts = src\ts\Author.ts
src\ts\TimeUtility.ts = src\ts\TimeUtility.ts src\ts\TimeUtility.ts = src\ts\TimeUtility.ts
src\ts\UI.ts = src\ts\UI.ts src\ts\UI.ts = src\ts\UI.ts
src\ts\Input.ts = src\ts\Input.ts
EndProjectSection EndProjectSection
EndProject EndProject
Global Global

View File

@ -29,7 +29,6 @@ public sealed class BlogApiController : ControllerBase
if (take == -1) take = _blogService.AllPosts.Count; if (take == -1) take = _blogService.AllPosts.Count;
var referer = Request.Headers["Referer"].ToString(); var referer = Request.Headers["Referer"].ToString();
Console.WriteLine($"Referer: {referer}");
if (!referer.StartsWith(Url.PageLink("/Blog/Index")!)) if (!referer.StartsWith(Url.PageLink("/Blog/Index")!))
{ {
return NotFound(); return NotFound();
@ -51,9 +50,9 @@ public sealed class BlogApiController : ControllerBase
url = Url.Page("/Blog/Article", url = Url.Page("/Blog/Article",
new new
{ {
year = post.Published.Year, year = post.Published.ToString("yyyy"),
month = post.Published.Month, month = post.Published.ToString("MM"),
day = post.Published.Day, day = post.Published.ToString("dd"),
slug = post.Slug slug = post.Slug
}) })
})); }));

View File

@ -18,7 +18,6 @@
<PackageReference Include="Humanizer.Core" Version="2.14.1"/> <PackageReference Include="Humanizer.Core" Version="2.14.1"/>
<PackageReference Include="Markdig" Version="0.32.0"/> <PackageReference Include="Markdig" Version="0.32.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.9"/> <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.9"/>
<PackageReference Include="NLog" Version="5.2.3"/>
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.3"/> <PackageReference Include="NLog.Extensions.Logging" Version="5.3.3"/>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0"/> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0"/>
<PackageReference Include="SmartFormat.NET" Version="3.2.2"/> <PackageReference Include="SmartFormat.NET" Version="3.2.2"/>

View File

@ -1,5 +1,5 @@
using Markdig; using Markdig;
using Markdig.Extensions.MediaLinks; using NLog;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;
using OliverBooth.Data; using OliverBooth.Data;
using OliverBooth.Markdown; using OliverBooth.Markdown;
@ -53,3 +53,5 @@ app.MapRazorPages();
app.MapRssFeed("/blog/feed"); app.MapRssFeed("/blog/feed");
app.Run(); app.Run();
LogManager.Shutdown();

33
src/ts/Input.ts Normal file
View File

@ -0,0 +1,33 @@
class Input {
public static readonly KONAMI_CODE = [
"ArrowUp",
"ArrowUp",
"ArrowDown",
"ArrowDown",
"ArrowLeft",
"ArrowRight",
"ArrowLeft",
"ArrowRight",
"b",
"a",
"Enter"
];
public static registerShortcut(shortcut: string | string[], callback: Function) {
let keys: string[];
if (typeof shortcut === 'string') keys = shortcut.split(' ');
else keys = shortcut;
let sequence: string[] = [];
document.addEventListener('keydown', e => {
sequence.push(e.key);
if (sequence.slice(-keys.length).join(' ') === keys.join(' ')) {
callback();
sequence = [];
}
});
}
}
export default Input;

View File

@ -193,6 +193,11 @@ class UI {
element = element || document.body; element = element || document.body;
element.querySelectorAll("pre code").forEach((block) => { element.querySelectorAll("pre code").forEach((block) => {
let content = block.innerHTML; let content = block.innerHTML;
// but ugly fucking hack. I hate this
content = content.replaceAll('<span class="token operator">&lt;</span>mark<span class="token operator">&gt;</span>', "<mark>");
content = content.replaceAll('<span class="token operator">&lt;</span><span class="token operator">/</span>mark<span class="token operator">&gt;</span>', "</mark>");
content = content.replaceAll("&lt;mark&gt;", "<mark>"); content = content.replaceAll("&lt;mark&gt;", "<mark>");
content = content.replaceAll("&lt;/mark&gt;", "</mark>"); content = content.replaceAll("&lt;/mark&gt;", "</mark>");
block.innerHTML = content; block.innerHTML = content;

View File

@ -1,9 +1,29 @@
import API from "./API"; import API from "./API";
import UI from "./UI"; import UI from "./UI";
import Input from "./Input";
const pkg = require("../../package.json");
declare const Handlebars: any; declare const Handlebars: any;
(() => { (() => {
let isCtrl = false;
document.addEventListener('keyup', (e) => {
if (e.ctrlKey) isCtrl = false;
});
document.addEventListener('keydown', (e) => {
if (e.ctrlKey) isCtrl = true;
if (isCtrl && e.key === "u") {
window.open(pkg.repository.url, "_blank");
return false;
}
});
Input.registerShortcut(Input.KONAMI_CODE, () => {
window.open("https://www.youtube.com/watch?v=dQw4w9WgXcQ", "_blank");
});
const blogPostContainer = UI.blogPostContainer; const blogPostContainer = UI.blogPostContainer;
if (blogPostContainer) { if (blogPostContainer) {
const template = Handlebars.compile(UI.blogPostTemplate.innerHTML); const template = Handlebars.compile(UI.blogPostTemplate.innerHTML);

View File

@ -1,6 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"lib": ["ES2022", "DOM"], "lib": ["ES2022", "DOM"],
"target": "ES2022" "target": "ES2022",
"moduleResolution": "nodenext"
} }
} }