Full rewrite of the portfolio site from Next.js 14 to .NET 10: - ASP.NET Core 10 Razor Pages, no Node.js dependency - EF Core 10 + SQLite (same schema as before — data survives upgrade) - Cookie authentication (same single-password model) - Resend contact form via HttpClient - Bilingual FA/EN via locale cookie + BasePageModel - All UI ported to Razor Pages with Tailwind CDN + custom CSS - Vanilla JS: particles, typewriter, cursor, animations, portfolio modal - Dockerfile: SDK 10.0-alpine → aspnet 10.0-alpine (no npm/Node needed) - CI/CD: dropped NPM_TOKEN, ADMIN_SESSION_SECRET — pure dotnet publish Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
@page "/Admin"
|
||||
@model SoroushAsadi.Pages.Admin.AdminIndexModel
|
||||
@{
|
||||
Layout = "_AdminLayout";
|
||||
ViewData["Title"] = "Dashboard";
|
||||
}
|
||||
|
||||
<h1 class="font-display text-2xl font-bold text-white mb-8">Dashboard</h1>
|
||||
|
||||
<div class="grid grid-cols-1 gap-5 sm:grid-cols-3">
|
||||
<a href="/Admin/Sections" class="glass block p-6 hover:border-electric/40 transition-colors">
|
||||
<div class="text-3xl font-bold text-electric mb-1">@Model.SectionCount</div>
|
||||
<div class="text-sm text-slate-400">Section overrides</div>
|
||||
<div class="mt-2 text-xs text-slate-500">Edit bilingual section content</div>
|
||||
</a>
|
||||
<a href="/Admin/Posts" class="glass block p-6 hover:border-violet/40 transition-colors">
|
||||
<div class="text-3xl font-bold text-violet mb-1">6</div>
|
||||
<div class="text-sm text-slate-400">Blog posts</div>
|
||||
<div class="mt-2 text-xs text-slate-500">Edit article bodies</div>
|
||||
</a>
|
||||
<div class="glass p-6">
|
||||
<div class="text-3xl font-bold text-emerald mb-1">↑</div>
|
||||
<div class="text-sm text-slate-400">Site status</div>
|
||||
<div class="mt-2 text-xs text-slate-500"><a href="/" class="text-electric hover:underline">View live site →</a></div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,11 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using SoroushAsadi.Services;
|
||||
|
||||
namespace SoroushAsadi.Pages.Admin;
|
||||
|
||||
[Authorize]
|
||||
public class AdminIndexModel(ContentService content) : Microsoft.AspNetCore.Mvc.RazorPages.PageModel
|
||||
{
|
||||
public int SectionCount { get; private set; }
|
||||
public void OnGet() => SectionCount = content.GetSectionKeys().Count;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
@page "/Admin/Login"
|
||||
@model SoroushAsadi.Pages.Admin.LoginModel
|
||||
@{
|
||||
Layout = "_AdminLayout";
|
||||
ViewData["Title"] = "Sign in";
|
||||
}
|
||||
|
||||
<div class="flex min-h-[60vh] items-center justify-center">
|
||||
<div class="w-full max-w-sm">
|
||||
<div class="mb-8 text-center">
|
||||
<img src="/logo-mark.svg" alt="" width="40" height="40" class="mx-auto mb-4" />
|
||||
<h1 class="font-display text-2xl font-bold text-white">Admin sign in</h1>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Error))
|
||||
{
|
||||
<div class="mb-4 rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-400">@Model.Error</div>
|
||||
}
|
||||
|
||||
<form method="post" class="glass p-6 space-y-4">
|
||||
<div>
|
||||
<label class="label-mono mb-2 block" for="password">Password</label>
|
||||
<input id="password" name="password" type="password" required autofocus
|
||||
class="w-full rounded-xl border border-white/10 bg-white/[.03] px-4 py-3 text-sm text-white outline-none focus:border-electric/60 transition-colors" />
|
||||
</div>
|
||||
<button type="submit" class="btn-primary w-full justify-center">Sign in</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using SoroushAsadi.Services;
|
||||
|
||||
namespace SoroushAsadi.Pages.Admin;
|
||||
|
||||
public class LoginModel(AuthService auth) : PageModel
|
||||
{
|
||||
public string Error { get; private set; } = "";
|
||||
|
||||
public void OnGet() { }
|
||||
|
||||
public async Task<IActionResult> OnPostAsync(string password, string returnUrl = "/Admin")
|
||||
{
|
||||
if (!auth.VerifyPassword(password))
|
||||
{
|
||||
Error = "Incorrect password.";
|
||||
return Page();
|
||||
}
|
||||
|
||||
var claims = new[] { new Claim(ClaimTypes.Name, "admin") };
|
||||
var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
await HttpContext.SignInAsync(
|
||||
CookieAuthenticationDefaults.AuthenticationScheme,
|
||||
new ClaimsPrincipal(identity));
|
||||
|
||||
if (!Url.IsLocalUrl(returnUrl)) returnUrl = "/Admin";
|
||||
return LocalRedirect(returnUrl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
@page "/Admin/Logout"
|
||||
@model SoroushAsadi.Pages.Admin.LogoutModel
|
||||
@@ -0,0 +1,16 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace SoroushAsadi.Pages.Admin;
|
||||
|
||||
[IgnoreAntiforgeryToken]
|
||||
public class LogoutModel : PageModel
|
||||
{
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
return RedirectToPage("/Admin/Login");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
@page "/Admin/Posts/{slug}"
|
||||
@model SoroushAsadi.Pages.Admin.Posts.PostEditModel
|
||||
@{
|
||||
Layout = "_AdminLayout";
|
||||
ViewData["Title"] = "Edit post: " + Model.Slug;
|
||||
}
|
||||
|
||||
<div class="mb-6 flex items-center gap-4">
|
||||
<a href="/Admin/Posts" class="text-slate-400 hover:text-white transition-colors text-sm">← Posts</a>
|
||||
<h1 class="font-display text-xl font-bold text-white">@Model.Slug</h1>
|
||||
<a href="/blog/@Model.Slug" target="_blank" class="text-xs text-slate-400 hover:text-white transition-colors">View ↗</a>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Message))
|
||||
{
|
||||
<div class="mb-4 rounded-lg border border-emerald/30 bg-emerald/10 px-4 py-3 text-sm text-emerald">@Model.Message</div>
|
||||
}
|
||||
|
||||
<form method="post" class="space-y-4">
|
||||
<div>
|
||||
<label class="label-mono mb-2 block">Body (Markdown)</label>
|
||||
<p class="text-xs text-slate-500 mb-2">Supports: ## headings, **bold**, `code`, - list items, paragraphs</p>
|
||||
<textarea name="body" rows="30"
|
||||
class="w-full rounded-xl border border-white/10 bg-white/[.03] px-4 py-3 font-mono text-xs text-slate-200 outline-none focus:border-electric/60 transition-colors resize-y"
|
||||
spellcheck="false">@Model.CurrentBody</textarea>
|
||||
</div>
|
||||
<div class="flex gap-3">
|
||||
<button type="submit" class="btn-primary">Save</button>
|
||||
@if (Model.HasOverride)
|
||||
{
|
||||
<button type="submit" name="reset" value="1" class="rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-2 text-sm text-red-400 hover:bg-red-500/20 transition-colors">Reset to default</button>
|
||||
}
|
||||
<a href="/Admin/Posts" class="btn-ghost">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
@@ -0,0 +1,71 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using SoroushAsadi.Services;
|
||||
|
||||
namespace SoroushAsadi.Pages.Admin.Posts;
|
||||
|
||||
[Authorize]
|
||||
public class PostEditModel(ContentService content) : PageModel
|
||||
{
|
||||
[BindProperty(SupportsGet = true)]
|
||||
public string Slug { get; set; } = "";
|
||||
|
||||
public string CurrentBody { get; private set; } = "";
|
||||
public string Message { get; private set; } = "";
|
||||
public bool HasOverride { get; private set; }
|
||||
|
||||
// Known default bodies live in Blog/Post.cshtml.cs (DefaultBodies)
|
||||
private static readonly Dictionary<string, string> _defaults = new()
|
||||
{
|
||||
["rag-eval-framework"] = SoroushAsadi.Pages.Blog.DefaultBodies.RagEval,
|
||||
["agentic-n8n-patterns"] = SoroushAsadi.Pages.Blog.DefaultBodies.N8nPatterns,
|
||||
["vertex-cost-control"] = SoroushAsadi.Pages.Blog.DefaultBodies.VertexCost,
|
||||
["k8s-llm-inference"] = SoroushAsadi.Pages.Blog.DefaultBodies.K8sInference,
|
||||
["flutter-on-device-ai"] = SoroushAsadi.Pages.Blog.DefaultBodies.FlutterAI,
|
||||
["enterprise-ai-roadmap"] = SoroushAsadi.Pages.Blog.DefaultBodies.EnterpriseRoadmap,
|
||||
};
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
var overrides = content.GetPostOverrides();
|
||||
if (overrides.TryGetValue(Slug, out var node) && node["body"]?.GetValue<string>() is { } body)
|
||||
{
|
||||
CurrentBody = body;
|
||||
HasOverride = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentBody = _defaults.GetValueOrDefault(Slug, "");
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult OnPost(string body, string? reset)
|
||||
{
|
||||
if (reset == "1")
|
||||
{
|
||||
// Remove override — default body shows through
|
||||
var existing = content.GetPostOverrides();
|
||||
existing.Remove(Slug);
|
||||
// Rebuild the posts JSON without this slug
|
||||
var obj = new JsonObject();
|
||||
foreach (var kv in existing) obj[kv.Key] = kv.Value.DeepClone();
|
||||
content.SaveSection(ContentService.PostsKey, obj.ToJsonString());
|
||||
|
||||
Message = "Reset to default.";
|
||||
HasOverride = false;
|
||||
CurrentBody = _defaults.GetValueOrDefault(Slug, "");
|
||||
return Page();
|
||||
}
|
||||
|
||||
content.SavePost(Slug, new JsonObject { ["body"] = body });
|
||||
HasOverride = true;
|
||||
CurrentBody = body;
|
||||
Message = "Saved.";
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
|
||||
// Re-export DefaultBodies from the Blog page so this page can use them
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
@page "/Admin/Posts"
|
||||
@model SoroushAsadi.Pages.Admin.Posts.PostsIndexModel
|
||||
@{
|
||||
Layout = "_AdminLayout";
|
||||
ViewData["Title"] = "Blog posts";
|
||||
var slugs = new[]{ "rag-eval-framework","agentic-n8n-patterns","vertex-cost-control","k8s-llm-inference","flutter-on-device-ai","enterprise-ai-roadmap" };
|
||||
}
|
||||
|
||||
<h1 class="font-display text-2xl font-bold text-white mb-8">Blog posts</h1>
|
||||
|
||||
<div class="space-y-2">
|
||||
@foreach (var slug in slugs)
|
||||
{
|
||||
var hasOverride = Model.OverrideSlugs.Contains(slug);
|
||||
<div class="glass flex items-center justify-between p-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="font-mono text-sm text-white">@slug</span>
|
||||
@if (hasOverride)
|
||||
{
|
||||
<span class="rounded-full bg-violet/10 px-2 py-0.5 font-mono text-[.65rem] text-violet">customized</span>
|
||||
}
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<a href="/Admin/Posts/@slug" class="btn-ghost text-xs py-1.5 px-3">Edit</a>
|
||||
<a href="/blog/@slug" target="_blank" class="text-xs text-slate-400 hover:text-white transition-colors self-center">View ↗</a>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,13 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using SoroushAsadi.Services;
|
||||
|
||||
namespace SoroushAsadi.Pages.Admin.Posts;
|
||||
|
||||
[Authorize]
|
||||
public class PostsIndexModel(ContentService content) : PageModel
|
||||
{
|
||||
public IReadOnlySet<string> OverrideSlugs { get; private set; } = new HashSet<string>();
|
||||
|
||||
public void OnGet() => OverrideSlugs = content.GetPostOverrides().Keys.ToHashSet();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
@page "/Admin/Sections/{key}"
|
||||
@model SoroushAsadi.Pages.Admin.Sections.SectionEditModel
|
||||
@{
|
||||
Layout = "_AdminLayout";
|
||||
ViewData["Title"] = "Edit: " + Model.SectionKey;
|
||||
}
|
||||
|
||||
<div class="mb-6 flex items-center gap-4">
|
||||
<a href="/Admin/Sections" class="text-slate-400 hover:text-white transition-colors text-sm">← Sections</a>
|
||||
<h1 class="font-display text-xl font-bold text-white">@Model.SectionKey</h1>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Message))
|
||||
{
|
||||
<div class="mb-4 rounded-lg border border-emerald/30 bg-emerald/10 px-4 py-3 text-sm text-emerald">@Model.Message</div>
|
||||
}
|
||||
|
||||
<form method="post" class="space-y-4">
|
||||
<div>
|
||||
<label class="label-mono mb-2 block">JSON ({"fa": {...}, "en": {...}})</label>
|
||||
<textarea name="json" rows="24"
|
||||
class="w-full rounded-xl border border-white/10 bg-white/[.03] px-4 py-3 font-mono text-xs text-slate-200 outline-none focus:border-electric/60 transition-colors resize-y"
|
||||
spellcheck="false">@Model.CurrentJson</textarea>
|
||||
</div>
|
||||
<div class="flex gap-3">
|
||||
<button type="submit" class="btn-primary">Save</button>
|
||||
<a href="/Admin/Sections" class="btn-ghost">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using SoroushAsadi.Services;
|
||||
|
||||
namespace SoroushAsadi.Pages.Admin.Sections;
|
||||
|
||||
[Authorize]
|
||||
public class SectionEditModel(ContentService content) : PageModel
|
||||
{
|
||||
[BindProperty(SupportsGet = true)]
|
||||
public string SectionKey { get; set; } = "";
|
||||
|
||||
public string CurrentJson { get; private set; } = "{\n \"fa\": {},\n \"en\": {}\n}";
|
||||
public string Message { get; private set; } = "";
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
var node = content.GetSection(SectionKey);
|
||||
if (node is not null)
|
||||
CurrentJson = node.ToJsonString(new JsonSerializerOptions { WriteIndented = true });
|
||||
}
|
||||
|
||||
public IActionResult OnPost(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Validate JSON
|
||||
JsonDocument.Parse(json);
|
||||
content.SaveSection(SectionKey, json);
|
||||
Message = "Saved.";
|
||||
CurrentJson = json;
|
||||
return Page();
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
Message = $"Invalid JSON: {ex.Message}";
|
||||
CurrentJson = json;
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
@page "/Admin/Sections"
|
||||
@model SoroushAsadi.Pages.Admin.Sections.SectionsIndexModel
|
||||
@{
|
||||
Layout = "_AdminLayout";
|
||||
ViewData["Title"] = "Sections";
|
||||
var all = new[]{ "hero","services","dataflow","stack","expertise","portfolio","blog","contact","footer" };
|
||||
}
|
||||
|
||||
<div class="mb-6 flex items-center justify-between">
|
||||
<h1 class="font-display text-2xl font-bold text-white">Sections</h1>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
@foreach (var key in all)
|
||||
{
|
||||
var hasOverride = Model.OverrideKeys.Contains(key);
|
||||
<div class="glass flex items-center justify-between p-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="font-mono text-sm text-white">@key</span>
|
||||
@if (hasOverride)
|
||||
{
|
||||
<span class="rounded-full bg-electric/10 px-2 py-0.5 font-mono text-[.65rem] text-electric">customized</span>
|
||||
}
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<a href="/Admin/Sections/@key" class="btn-ghost text-xs py-1.5 px-3">Edit</a>
|
||||
@if (hasOverride)
|
||||
{
|
||||
<form method="post" asp-page-handler="Reset" class="inline">
|
||||
<input type="hidden" name="key" value="@key" />
|
||||
<button type="submit" class="rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-1.5 text-xs text-red-400 hover:bg-red-500/20 transition-colors">Reset</button>
|
||||
</form>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,19 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using SoroushAsadi.Services;
|
||||
|
||||
namespace SoroushAsadi.Pages.Admin.Sections;
|
||||
|
||||
[Authorize]
|
||||
public class SectionsIndexModel(ContentService content) : PageModel
|
||||
{
|
||||
public IReadOnlySet<string> OverrideKeys { get; private set; } = new HashSet<string>();
|
||||
public void OnGet() => OverrideKeys = content.GetSectionKeys().ToHashSet();
|
||||
|
||||
public IActionResult OnPostReset(string key)
|
||||
{
|
||||
content.DeleteSection(key);
|
||||
return RedirectToPage();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user