|
| 1 | +@page "/" |
| 2 | +@page "/blog/{fileName}" |
| 3 | +@using System.Globalization |
| 4 | +@using BlazorStatic |
| 5 | +@using BlazorStatic.Services |
| 6 | +@inject BlazorStaticContentService<BlogFrontMatter> blazorStaticContentService |
| 7 | + |
| 8 | + |
| 9 | +@* No filename -> show latest posts *@ |
| 10 | +@if (string.IsNullOrWhiteSpace(FileName)) |
| 11 | +{ |
| 12 | + <div class="divide-y divide-gray-700"> |
| 13 | + <div class="space-y-2 pb-8 pt-6 md:space-y-5"> |
| 14 | + <h1 class="font-sans md:leading-14 text-3xl font-extrabold leading-9 tracking-tight text-gray-100 sm:text-4xl sm:leading-10 md:text-6xl">Latest</h1> |
| 15 | + <p class="text-lg leading-7 text-gray-400 prose prose-invert">@WebsiteKeys.BlogLead</p> |
| 16 | + </div> |
| 17 | + |
| 18 | + <PostsList/> |
| 19 | + </div> |
| 20 | + return; |
| 21 | +} |
| 22 | + |
| 23 | +@* Show specific post by filename param *@ |
| 24 | +@if (post == null) |
| 25 | +{ |
| 26 | + <div>Post not found 🤷 </div> |
| 27 | + return; |
| 28 | +} |
| 29 | +<article> |
| 30 | + <div class="xl:divide-y xl:divide-gray-700"> |
| 31 | + <header class="pt-6 xl:pb-6"> |
| 32 | + <div class="space-y-1 text-center"> |
| 33 | + <dl class="space-y-10"> |
| 34 | + <div> |
| 35 | + <dt class="sr-only">Published on</dt> |
| 36 | + <dd class="text-base font-medium leading-6 text-gray-400"> |
| 37 | + <time datetime="@post.FrontMatter.Published.ToString("yyyy-MM-ddTHH:mm:ss.fffK", CultureInfo.InvariantCulture)"> |
| 38 | + @post.FrontMatter.Published.ToString("MMMM d, yyyy", new CultureInfo("en-US")) |
| 39 | + </time> |
| 40 | + </dd> |
| 41 | + </div> |
| 42 | + </dl> |
| 43 | + <div class="prose prose-invert mx-auto"> |
| 44 | + <h1 class="">@post.FrontMatter.Title</h1> |
| 45 | + </div> |
| 46 | + </div> |
| 47 | + </header> |
| 48 | + <div class="grid-rows-[auto_1fr] divide-y pb-8 divide-gray-700 xl:grid xl:grid-cols-4 xl:gap-x-6 xl:divide-y-0"> |
| 49 | + |
| 50 | + <dl class="pb-10 pt-6 xl:border-b xl:pt-11 xl:border-gray-700"> |
| 51 | + <dt class="sr-only">Authors</dt> |
| 52 | + <dd> |
| 53 | + <ul class="flex flex-wrap justify-center gap-4 sm:space-x-12 xl:block xl:space-x-0 xl:space-y-8"> |
| 54 | + @foreach(var author in post.FrontMatter.Authors) |
| 55 | + { |
| 56 | + <li class="flex items-center space-x-2"> |
| 57 | + @* <img alt="avatar" loading="lazy" width="38" height="38" decoding="async" data-nimg="1" class="h-10 w-10 rounded-full" srcset="/_next/image?url=%2Fstatic%2Fimages%2Favatar.png&w=48&q=75 1x, /_next/image?url=%2Fstatic%2Fimages%2Favatar.png&w=96&q=75 2x" src="/_next/image?url=%2Fstatic%2Fimages%2Favatar.png&w=96&q=75" style="color: transparent;"/> *@ |
| 58 | + <dl class="whitespace-nowrap text-sm font-medium leading-5"> |
| 59 | + @if (!string.IsNullOrWhiteSpace(author.Name)) |
| 60 | + { |
| 61 | + <dt class="sr-only">Name</dt> |
| 62 | + <dd class="text-gray-900 dark:text-gray-100 flex gap-1 items-center"> |
| 63 | + @author.Name |
| 64 | + @if (!string.IsNullOrWhiteSpace(author.XUserName)) |
| 65 | + { |
| 66 | + <a target="_blank" rel="noopener noreferrer" href="https://x.com/@author.XUserName" class="flex gap-1 text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"> |
| 67 | + <Svg SizeClasses="w-4 h-4" Icon="Svg.Icons.X"/> |
| 68 | + </a> |
| 69 | + } |
| 70 | + @if (!string.IsNullOrWhiteSpace(author.GitHubUserName)) |
| 71 | + { |
| 72 | + <a target="_blank" rel="noopener noreferrer" href="https://github.com/@author.GitHubUserName" class="flex gap-1 items-center text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"> |
| 73 | + <Svg SizeClasses="w-4 h-4" Icon="Svg.Icons.Github"/> |
| 74 | + </a> |
| 75 | + } |
| 76 | + </dd> |
| 77 | + } |
| 78 | + </dl> |
| 79 | + </li> |
| 80 | + } |
| 81 | + </ul> |
| 82 | + </dd> |
| 83 | + </dl> |
| 84 | + <div class="divide-y divide-gray-700 xl:col-span-3 xl:row-span-2 xl:pb-0"> |
| 85 | + <div class="prose prose-invert max-w-none pb-8 pt-10"> |
| 86 | + @((MarkupString)post.HtmlContent) |
| 87 | + </div> |
| 88 | + <div class="pb-6 pt-6 text-sm text-gray-300"> |
| 89 | + <a target="_blank" rel="noopener noreferrer" href="@($"{WebsiteKeys.BlogPostStorageAddress}/{FileName}")">View on GitHub</a> |
| 90 | + </div> |
| 91 | + </div> |
| 92 | + <footer> |
| 93 | + <div class=" text-sm font-medium leading-5 divide-gray-700 xl:col-start-1 xl:row-start-2 xl:divide-y"> |
| 94 | + <div class="py-4 xl:py-8"> |
| 95 | + <h2 class="text-xs uppercase tracking-wide text-gray-400">Tags</h2> |
| 96 | + <div class="flex flex-wrap"> |
| 97 | + @foreach(var tag in post.FrontMatter.Tags) |
| 98 | + { |
| 99 | + <a class="text-primary-500 hover:text-primary-400 mr-3 text-sm font-medium uppercase" href="@blazorStaticContentService.Options.Tags.TagsPageUrl/@tag">@tag</a> |
| 100 | + } |
| 101 | + </div> |
| 102 | + </div> |
| 103 | + </div> |
| 104 | + <div class="pt-4 xl:pt-8"> |
| 105 | + <a class="text-primary-500 hover:text-primary-400" aria-label="Back to the home" href="">← Back to the home</a> |
| 106 | + </div> |
| 107 | + </footer> |
| 108 | + </div> |
| 109 | + </div> |
| 110 | +</article> |
| 111 | + |
| 112 | + |
| 113 | +@code{ |
| 114 | + [Parameter] public string? FileName { get; set; } |
| 115 | + Post<BlogFrontMatter>? post; |
| 116 | + |
| 117 | + protected override void OnInitialized() |
| 118 | + { |
| 119 | + if (string.IsNullOrWhiteSpace(FileName)) return; |
| 120 | + post = blazorStaticContentService.Posts.FirstOrDefault(x => x.Url == FileName); |
| 121 | + } |
| 122 | +} |
0 commit comments