Skip to content

Commit 6431561

Browse files
committed
Code updated for PWA
1 parent 70dd16b commit 6431561

17 files changed

+865
-397
lines changed

TextHub/Components/Forms/TextCaseLayout.razor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
@using Microsoft.JSInterop
44
@inject JsonLdService JsonLdService
55
@inject ToolDataService ToolDataService
6+
@inject MetaTagsService MetaTagsService
67
@inject IJSRuntime JSRuntime
78

89
<PageTitle>@PageTitle - Text Hub</PageTitle>
910

11+
<DynamicMetaTags MetaTags="@_metaTags" />
1012
<DynamicJsonLd JsonLdContent="@_jsonLdContent" Id="@(ToolName.ToLower().Replace(" ", "").Replace("-", "").Replace("_", "") + "-jsonld")" />
1113

1214
<main class="flex-1">
@@ -90,13 +92,15 @@
9092
private string _inputText = string.Empty;
9193
private string _outputText = string.Empty;
9294
private string _jsonLdContent = string.Empty;
95+
private MetaTagsData? _metaTags;
9396

9497
protected override void OnInitialized()
9598
{
9699
var tool = ToolDataService.GetTextCaseTools().FirstOrDefault(t => t.Href == Route);
97100
if (tool != null)
98101
{
99102
_jsonLdContent = JsonLdService.GenerateToolPageJsonLd(tool, "Text Case Tools");
103+
_metaTags = MetaTagsService.GetToolPageMetaTags(tool, "Text Case Tools");
100104
}
101105
}
102106

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
@inherits LayoutComponentBase
22

3-
<div class="min-h-screen flex flex-col">
4-
<UINavBar/>
5-
@Body
6-
<UIFooter/>
3+
<div class="min-h-screen flex flex-col">
4+
<SkipNavigation />
5+
<ServiceWorkerManager />
6+
7+
<header role="banner" id="navigation">
8+
<UINavBar/>
9+
</header>
10+
11+
<main role="main" id="main-content" class="flex-1">
12+
@Body
13+
</main>
14+
15+
<footer role="contentinfo">
16+
<UIFooter/>
17+
</footer>
718
</div>

TextHub/Components/Layout/UIFooter.razor

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@* --- UIFooter --- *@
2-
<footer class="bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900 text-white mt-auto">
2+
<footer class="bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900 text-white mt-auto" role="contentinfo" aria-label="Site footer">
33
<div class="container mx-auto px-4 py-12">
44
<!-- Main Footer Content -->
55
<div class="grid lg:grid-cols-4 md:grid-cols-2 gap-8 mb-8">
@@ -38,7 +38,7 @@
3838
<!-- Tools Section -->
3939
<div>
4040
<h4 class="text-lg font-semibold mb-4 text-white">Text Tools</h4>
41-
<ul class="space-y-3">
41+
<ul class="space-y-3" role="list">
4242
<li><a href="/camel-case" class="text-slate-300 hover:text-white transition-colors text-sm">Camel Case</a></li>
4343
<li><a href="/kebab-case" class="text-slate-300 hover:text-white transition-colors text-sm">Kebab Case</a></li>
4444
<li><a href="/snake-case" class="text-slate-300 hover:text-white transition-colors text-sm">Snake Case</a></li>
@@ -53,7 +53,7 @@
5353
<!-- Resources Section -->
5454
<div>
5555
<h4 class="text-lg font-semibold mb-4 text-white">Resources</h4>
56-
<ul class="space-y-3">
56+
<ul class="space-y-3" role="list">
5757
<li><a href="/documentation" class="text-slate-300 hover:text-white transition-colors text-sm">Documentation</a></li>
5858
<li><a href="https://github.com/codefrydev/TextHub/issues" target="_blank" rel="noopener noreferrer" class="text-slate-300 hover:text-white transition-colors text-sm">Report Bug</a></li>
5959
<li><a href="https://github.com/codefrydev/TextHub/discussions" target="_blank" rel="noopener noreferrer" class="text-slate-300 hover:text-white transition-colors text-sm">Community</a></li>
@@ -66,7 +66,7 @@
6666
<!-- Company Section -->
6767
<div>
6868
<h4 class="text-lg font-semibold mb-4 text-white">About</h4>
69-
<ul class="space-y-3">
69+
<ul class="space-y-3" role="list">
7070
<li><a href="https://codefrydev.in" target="_blank" rel="noopener noreferrer" class="text-slate-300 hover:text-white transition-colors text-sm">CodeFryDev</a></li>
7171
<li><a href="https://codefrydev.in/contact" target="_blank" rel="noopener noreferrer" class="text-slate-300 hover:text-white transition-colors text-sm">Contact Us</a></li>
7272
<li><a href="https://codefrydev.in/privacy" target="_blank" rel="noopener noreferrer" class="text-slate-300 hover:text-white transition-colors text-sm">Privacy Policy</a></li>

TextHub/Components/Layout/UINavBar.razor

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
@inject TextHub.Services.Data.ToolDataService ToolDataService
44
@inject NavigationManager Navigation
55
@using Microsoft.AspNetCore.Components.Web
6-
<nav class="sticky top-0 z-50 bg-background/80 backdrop-blur-md border-b border-border">
6+
<nav class="sticky top-0 z-50 bg-background/80 backdrop-blur-md border-b border-border" role="navigation" aria-label="Main navigation">
77
<div class="container mx-auto px-4 py-3 md:py-4">
88
<div class="flex items-center justify-between">
9-
<a class="text-xl md:text-2xl font-bold text-gradient hover:opacity-80 transition-opacity" href="">Text Hub</a>
9+
<a class="text-xl md:text-2xl font-bold text-gradient hover:opacity-80 transition-opacity" href="/" aria-label="Text Hub - Home">Text Hub</a>
1010

1111
@* --- Desktop Menu --- *@
12-
<div class="hidden md:flex items-center gap-6">
13-
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">Home</NavLink>
12+
<div class="hidden md:flex items-center gap-6" role="menubar">
13+
<NavLink class="nav-link" href="" Match="NavLinkMatch.All" role="menuitem">Home</NavLink>
1414
<div class="relative">
15-
<button @onclick="() => _isToolsDropdownOpen = !_isToolsDropdownOpen" @onclick:stopPropagation="true" type="button" class="flex items-center gap-1 font-medium hover:text-primary transition-colors cursor-pointer">
15+
<button @onclick="() => _isToolsDropdownOpen = !_isToolsDropdownOpen" @onclick:stopPropagation="true" type="button" class="flex items-center gap-1 font-medium hover:text-primary transition-colors cursor-pointer" aria-expanded="@_isToolsDropdownOpen" aria-haspopup="true" role="menuitem">
1616
Tools
17-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-down w-4 h-4 transition-transform @(_isToolsDropdownOpen ? "rotate-180" : "")">
17+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-down w-4 h-4 transition-transform @(_isToolsDropdownOpen ? "rotate-180" : "")" aria-hidden="true">
1818
<path d="m6 9 6 6 6-6"></path>
1919
</svg>
2020
</button>
2121
@if (_isToolsDropdownOpen)
2222
{
23-
<div id="tools-dropdown" @onclick:stopPropagation="true" @onclick:preventDefault="true" class="absolute top-full mt-2 w-72 p-2 bg-popover text-popover-foreground border border-border rounded-md shadow-md z-50">
23+
<div id="tools-dropdown" @onclick:stopPropagation="true" @onclick:preventDefault="true" class="absolute top-full mt-2 w-72 p-2 bg-popover text-popover-foreground border border-border rounded-md shadow-md z-50" role="menu" aria-label="Tools menu">
2424
@* Text Case Tools Section *@
2525
<div class="mb-1">
2626
<button @onclick="() => ToggleTextCaseSection()" type="button" class="flex items-center justify-between w-full px-2 py-1.5 text-sm font-semibold text-muted-foreground hover:text-foreground transition-colors rounded hover:bg-muted/50">
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@using TextHub.Services.Data
2+
@inject MetaTagsService MetaTagsService
3+
4+
@if (MetaTags != null)
5+
{
6+
<HeadContent>
7+
<!-- Primary Meta Tags -->
8+
<meta name="title" content="@MetaTags.Title" />
9+
<meta name="description" content="@MetaTags.Description" />
10+
<meta name="keywords" content="@MetaTags.Keywords" />
11+
<meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1" />
12+
<meta name="googlebot" content="index, follow" />
13+
<meta name="bingbot" content="index, follow" />
14+
<link rel="canonical" href="@MetaTags.CanonicalUrl" />
15+
16+
<!-- Open Graph / Facebook -->
17+
<meta property="og:type" content="website" />
18+
<meta property="og:url" content="@MetaTags.CanonicalUrl" />
19+
<meta property="og:title" content="@MetaTags.OgTitle" />
20+
<meta property="og:description" content="@MetaTags.OgDescription" />
21+
<meta property="og:image" content="@MetaTags.OgImage" />
22+
<meta property="og:image:width" content="512" />
23+
<meta property="og:image:height" content="512" />
24+
<meta property="og:image:alt" content="@MetaTags.OgTitle" />
25+
<meta property="og:site_name" content="Text Hub" />
26+
<meta property="og:locale" content="en_US" />
27+
28+
<!-- Twitter -->
29+
<meta property="twitter:card" content="summary_large_image" />
30+
<meta property="twitter:url" content="@MetaTags.CanonicalUrl" />
31+
<meta property="twitter:title" content="@MetaTags.TwitterTitle" />
32+
<meta property="twitter:description" content="@MetaTags.TwitterDescription" />
33+
<meta property="twitter:image" content="@MetaTags.TwitterImage" />
34+
<meta property="twitter:image:alt" content="@MetaTags.TwitterTitle" />
35+
</HeadContent>
36+
}
37+
38+
@code {
39+
[Parameter] public MetaTagsData? MetaTags { get; set; }
40+
}

TextHub/Components/Shared/HomeHeroSection.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
</h1>
2727

2828
<!-- Subtitle -->
29-
<p class="text-xl sm:text-2xl md:text-3xl text-muted-foreground mb-6 md:mb-8 max-w-3xl mx-auto px-4 animate-fade-in" style="animation-delay: 0.2s;">
29+
<h2 class="text-xl sm:text-2xl md:text-3xl text-muted-foreground mb-6 md:mb-8 max-w-3xl mx-auto px-4 animate-fade-in" style="animation-delay: 0.2s;">
3030
Quick and simple text utilities in one place.
31-
</p>
31+
</h2>
3232

3333
<!-- Description -->
3434
<p class="text-lg sm:text-xl text-muted-foreground mb-8 md:mb-12 max-w-2xl mx-auto px-4 animate-fade-in" style="animation-delay: 0.4s;">
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@using Microsoft.AspNetCore.Components.WebAssembly.Hosting
2+
@inject IWebAssemblyHostEnvironment HostEnvironment
3+
@inject IJSRuntime JSRuntime
4+
5+
@code {
6+
protected override async Task OnAfterRenderAsync(bool firstRender)
7+
{
8+
if (firstRender)
9+
{
10+
await RegisterServiceWorkerIfProduction();
11+
}
12+
}
13+
14+
private async Task RegisterServiceWorkerIfProduction()
15+
{
16+
if (HostEnvironment.IsProduction())
17+
{
18+
try
19+
{
20+
// Check if we're on localhost via JavaScript
21+
var isLocalhost = await JSRuntime.InvokeAsync<bool>("isLocalhost");
22+
23+
if (!isLocalhost)
24+
{
25+
await JSRuntime.InvokeVoidAsync("registerServiceWorker");
26+
Console.WriteLine("Service Worker registered successfully in production");
27+
}
28+
else
29+
{
30+
Console.WriteLine("Service Worker disabled - localhost detected even in production mode");
31+
}
32+
}
33+
catch (Exception ex)
34+
{
35+
Console.WriteLine($"Service Worker registration failed: {ex.Message}");
36+
}
37+
}
38+
else
39+
{
40+
Console.WriteLine("Service Worker disabled - Development mode");
41+
}
42+
}
43+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!-- Skip Navigation for Accessibility -->
2+
<div class="sr-only focus-within:not-sr-only">
3+
<a href="#main-content" class="absolute top-4 left-4 z-50 bg-primary text-primary-foreground px-4 py-2 rounded-md font-medium focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2">
4+
Skip to main content
5+
</a>
6+
<a href="#navigation" class="absolute top-4 left-32 z-50 bg-primary text-primary-foreground px-4 py-2 rounded-md font-medium focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2">
7+
Skip to navigation
8+
</a>
9+
</div>
10+
11+
<style>
12+
.sr-only {
13+
position: absolute;
14+
width: 1px;
15+
height: 1px;
16+
padding: 0;
17+
margin: -1px;
18+
overflow: hidden;
19+
clip: rect(0, 0, 0, 0);
20+
white-space: nowrap;
21+
border: 0;
22+
}
23+
24+
.sr-only:focus {
25+
position: static;
26+
width: auto;
27+
height: auto;
28+
padding: inherit;
29+
margin: inherit;
30+
overflow: visible;
31+
clip: auto;
32+
white-space: normal;
33+
}
34+
35+
.focus-within\:not-sr-only:focus-within {
36+
position: static;
37+
width: auto;
38+
height: auto;
39+
padding: inherit;
40+
margin: inherit;
41+
overflow: visible;
42+
clip: auto;
43+
white-space: normal;
44+
}
45+
</style>

TextHub/Models/BreadcrumbItem.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace TextHub.Models;
2+
3+
public class BreadcrumbItem
4+
{
5+
public string Name { get; set; } = string.Empty;
6+
public string Url { get; set; } = string.Empty;
7+
public bool IsActive { get; set; } = false;
8+
}

TextHub/Pages/Home.razor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
@using TextHub.Components.Shared
33
@using TextHub.Services.Data
44
@inject JsonLdService JsonLdService
5+
@inject MetaTagsService MetaTagsService
56

67
<PageTitle>Text Hub - Quick & Simple Text Utilities</PageTitle>
78

9+
<DynamicMetaTags MetaTags="@_metaTags" />
810
<DynamicJsonLd JsonLdContent="@_jsonLdContent" Id="home-jsonld" />
911

1012
<div class="min-h-screen flex flex-col">
@@ -42,9 +44,11 @@
4244

4345
@code {
4446
private string _jsonLdContent = string.Empty;
47+
private MetaTagsData? _metaTags;
4548

4649
protected override void OnInitialized()
4750
{
4851
_jsonLdContent = JsonLdService.GenerateHomePageJsonLd();
52+
_metaTags = MetaTagsService.GetHomePageMetaTags();
4953
}
5054
}

0 commit comments

Comments
 (0)