Category-based homepage layout

This commit is contained in:
Alicia Sykes committed 2025-10-11 14:29:09 +01:00
1 parent c4a9eab0ae
commit df993fc99c
14 files changed
+1020 -155

No files matched your search

@@ -7,6 +7,7 @@
import { browser } from '$app/environment';
import { theme, themes, type ThemeOption, type Theme } from '$lib/stores/theme';
import { navbarDisplay, navbarDisplayOptions, type NavbarDisplayMode } from '$lib/stores/navbarDisplay';
import { homepageLayout, homepageLayoutOptions, type HomepageLayoutMode } from '$lib/stores/homepageLayout';
import { site } from '$lib/constants/site';
import { resolve } from '$app/paths';
@@ -24,6 +25,7 @@
let accessibilitySettings = $state(accessibility);
let currentTheme = $state(theme);
let currentNavbarDisplay = $state(navbarDisplay);
let currentHomepageLayout = $state(homepageLayout);
// Shortcut key detection
const isMac = browser && navigator.platform.toUpperCase().indexOf('MAC') >= 0;
@@ -54,6 +56,12 @@
navbarDisplay.setMode(target.value as NavbarDisplayMode);
}
// Handle homepage layout mode change
function handleHomepageLayoutChange(event: Event) {
const target = event.currentTarget as HTMLSelectElement;
homepageLayout.setMode(target.value as HomepageLayoutMode);
}
// Primary accessibility options (always visible)
const primaryA11yOptions = ['reduce-motion'];
// const primaryA11yOptions: string[] = [];
@@ -108,6 +116,7 @@
accessibility.init();
theme.init();
navbarDisplay.init();
homepageLayout.init();
return () => {
document.removeEventListener('click', handleClickOutside);
@@ -236,6 +245,24 @@
</small>
</div>
<!-- Homepage Layout -->
<div class="settings-section">
<h3>Homepage Layout</h3>
<div class="navbar-select-wrapper">
<select class="navbar-select" value={$currentHomepageLayout} onchange={handleHomepageLayoutChange}>
{#each homepageLayoutOptions as option (option.id)}
<option value={option.id}>{option.name}</option>
{/each}
</select>
<div class="dropdown-icon">
<Icon name="chevron-down" size="xs" />
</div>
</div>
<small class="navbar-description">
{homepageLayoutOptions.find((opt) => opt.id === $currentHomepageLayout)?.description}
</small>
</div>
<!-- Accessibility Options -->
<div class="settings-section">
<h3>Accessibility</h3>
@@ -0,0 +1,138 @@
<script lang="ts">
import { onMount } from 'svelte';
import Icon from './Icon.svelte';
export let x: number = 0;
export let y: number = 0;
export let items: Array<{
label: string;
icon: string;
action: () => void;
condition?: boolean;
}> = [];
export let onClose: () => void;
let menuElement: HTMLDivElement;
onMount(() => {
// Position the menu, ensuring it stays within viewport
if (menuElement) {
const rect = menuElement.getBoundingClientRect();
const viewportWidth = window.innerWidth;
const viewportHeight = window.innerHeight;
// Adjust horizontal position if menu would overflow
if (x + rect.width > viewportWidth) {
x = viewportWidth - rect.width - 10;
}
// Adjust vertical position if menu would overflow
if (y + rect.height > viewportHeight) {
y = viewportHeight - rect.height - 10;
}
}
// Close on click outside
const handleClickOutside = (e: MouseEvent) => {
if (menuElement && !menuElement.contains(e.target as Node)) {
onClose();
}
};
// Close on Escape key
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
onClose();
}
};
document.addEventListener('click', handleClickOutside);
document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('click', handleClickOutside);
document.removeEventListener('keydown', handleKeyDown);
};
});
function handleItemClick(action: () => void) {
action();
onClose();
}
// Filter items based on condition
$: visibleItems = items.filter((item) => item.condition !== false);
</script>
<div class="context-menu" bind:this={menuElement} style="left: {x}px; top: {y}px;">
{#each visibleItems as item (item.label)}
<button class="menu-item" onclick={() => handleItemClick(item.action)}>
<Icon name={item.icon} size="sm" />
<span>{item.label}</span>
</button>
{/each}
</div>
<style lang="scss">
.context-menu {
position: fixed;
z-index: 1000;
background: var(--bg-secondary);
border: 1px solid var(--border-primary);
border-radius: var(--radius-md);
box-shadow: var(--shadow-lg);
padding: var(--spacing-xs);
min-width: 12rem;
animation: menuFadeIn 0.15s ease-out;
}
.menu-item {
width: 100%;
display: flex;
align-items: center;
gap: var(--spacing-sm);
padding: var(--spacing-sm) var(--spacing-md);
background: none;
border: none;
border-radius: var(--radius-sm);
color: var(--text-primary);
font-size: var(--font-size-sm);
text-align: left;
cursor: pointer;
transition: all var(--transition-fast);
&:hover {
background: var(--surface-hover);
color: var(--color-primary);
}
&:active {
transform: scale(0.98);
}
:global(svg) {
flex-shrink: 0;
color: var(--text-secondary);
transition: color var(--transition-fast);
}
&:hover :global(svg) {
color: var(--color-primary);
}
span {
flex: 1;
}
}
@keyframes menuFadeIn {
from {
opacity: 0;
transform: translateY(-4px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
</style>
+164 -7
View File
@@ -2,24 +2,36 @@
import { tooltip } from '$lib/actions/tooltip';
import { onMount } from 'svelte';
import Icon from '$lib/components/global/Icon.svelte';
import ContextMenu from '$lib/components/global/ContextMenu.svelte';
import type { NavItem } from '$lib/constants/nav';
import { bookmarks, type BookmarkedTool } from '$lib/stores/bookmarks';
import { toolUsage, recentlyUsedTools } from '$lib/stores/toolUsage';
import { activeContextMenu } from '$lib/stores/contextMenu';
import { site } from '$lib/constants/site';
export let tool: NavItem;
export let small: boolean = false;
export let size: 'default' | 'small' | 'compact' = 'default';
let isHovered = false;
let isBookmarked = false;
// Generate unique ID for this tool card
const menuId = `context-menu-${tool.href}`;
onMount(() => {
bookmarks.init();
toolUsage.init();
});
$: isBookmarked = bookmarks.isBookmarked(tool.href, $bookmarks);
$: isInRecents = $recentlyUsedTools.some((t) => t.href === tool.href);
$: showContextMenu = $activeContextMenu.id === menuId;
function toggleBookmark(e: Event) {
e.preventDefault();
e.stopPropagation();
function toggleBookmark(e?: Event) {
if (e) {
e.preventDefault();
e.stopPropagation();
}
const bookmarkedTool: BookmarkedTool = {
href: tool.href,
@@ -30,10 +42,60 @@
bookmarks.toggle(bookmarkedTool);
}
function handleContextMenu(e: MouseEvent) {
e.preventDefault();
e.stopPropagation();
activeContextMenu.open(menuId, e.clientX, e.clientY);
}
function copyUrl() {
const origin = typeof window !== 'undefined' ? window.location.origin : site.url;
const url = `${origin}${tool.href}`;
navigator.clipboard.writeText(url);
}
function openTool() {
window.location.href = tool.href;
}
function removeFromRecents() {
toolUsage.remove(tool.href);
}
$: contextMenuItems = [
{
label: isBookmarked ? 'Remove Bookmark' : 'Bookmark',
icon: isBookmarked ? 'bookmark-remove' : 'bookmark-add',
action: () => toggleBookmark(),
},
{
label: 'Open',
icon: 'external-link',
action: openTool,
},
{
label: 'Copy URL',
icon: 'link',
action: copyUrl,
},
{
label: 'Remove from Recents',
icon: 'trash',
action: removeFromRecents,
condition: isInRecents,
},
];
</script>
{#if small}
<a href={tool.href} class="tool-card small" aria-label={tool.label} use:tooltip={{ text: tool.description || '' }}>
{#if size === 'small'}
<a
href={tool.href}
class="tool-card small"
aria-label={tool.label}
use:tooltip={{ text: tool.description || '' }}
on:contextmenu={handleContextMenu}
>
<div class="left">
<h3>{tool.label}</h3>
<div class="tool-icon">
@@ -50,6 +112,21 @@
</svg>
</div>
</a>
{:else if size === 'compact'}
<a
href={tool.href}
class="tool-card compact"
aria-label={tool.label}
use:tooltip={{ text: tool.description || '' }}
on:contextmenu={handleContextMenu}
>
<div class="compact-content">
<div class="tool-icon">
<Icon name={tool.icon || 'default'} />
</div>
<h3>{tool.label}</h3>
</div>
</a>
{:else}
<a
href={tool.href}
@@ -57,6 +134,7 @@
aria-label={tool.label}
on:mouseenter={() => (isHovered = true)}
on:mouseleave={() => (isHovered = false)}
on:contextmenu={handleContextMenu}
>
<div class="card-header">
<h3>{tool.label}</h3>
@@ -102,6 +180,15 @@
</a>
{/if}
{#if showContextMenu}
<ContextMenu
x={$activeContextMenu.x}
y={$activeContextMenu.y}
items={contextMenuItems}
onClose={() => activeContextMenu.close()}
/>
{/if}
<style lang="scss">
.tool-card {
display: flex;
@@ -329,13 +416,19 @@
justify-content: space-between;
padding: var(--spacing-sm);
gap: var(--spacing-sm);
background: var(--bg-tertiary);
background: linear-gradient(
135deg,
var(--bg-secondary),
color-mix(in srgb, var(--bg-secondary), var(--bg-tertiary) 50%)
);
.left {
display: flex;
flex-direction: row-reverse;
align-items: center;
gap: var(--spacing-md);
min-width: 0;
position: relative;
z-index: 1;
}
h3 {
@@ -360,6 +453,8 @@
.tool-arrow {
width: 1.25rem;
height: 1.25rem;
position: relative;
z-index: 1;
@media (max-width: 768px) {
display: none;
@@ -381,6 +476,68 @@
}
}
.tool-card.compact {
flex-direction: column;
align-items: center;
justify-content: center;
padding: var(--spacing-sm);
gap: var(--spacing-xs);
text-align: center;
min-height: 5rem;
// max-width: 10rem;
background: linear-gradient(
135deg,
var(--bg-secondary),
color-mix(in srgb, var(--bg-secondary), var(--bg-tertiary) 50%)
);
.compact-content {
display: flex;
flex-direction: column;
align-items: center;
gap: var(--spacing-xs);
width: 100%;
position: relative;
z-index: 1;
}
h3 {
font-size: var(--font-size-sm);
font-weight: 500;
margin: 0;
line-height: 1.2;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
width: 100%;
}
.tool-icon {
width: 1.75rem;
height: 1.75rem;
transition: all 0.25s;
filter: saturate(0.9);
}
&:hover {
.tool-icon {
transform: scale(1.15);
filter: saturate(1);
}
}
&:focus {
outline: 2px solid var(--color-primary);
outline-offset: 2px;
box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-primary), transparent 85%);
border-color: var(--color-primary);
background-color: var(--surface-hover);
}
}
@keyframes fadeIn {
to {
opacity: 1;
@@ -55,7 +55,7 @@
<div class="track" style="animation-duration: {durationFor(row.items.length)}s;">
{#each dupe(row.items).map((t, idx) => ({ t, idx })) as it (it.t.href + '-' + it.idx)}
<div class="card-wrap">
<ToolCard tool={it.t} small={true} />
<ToolCard tool={it.t} size="small" />
</div>
{/each}
</div>
+7 -12
View File
@@ -7,20 +7,24 @@
export let tools: NavItem[] = ALL_PAGES;
export let searchQuery: string = '';
export let idPrefix: string = 'main-';
export let size: 'default' | 'small' | 'compact' = 'default';
// Remove duplicates based on href, keeping the first occurrence
// Also filter out items without a label
$: uniqueTools = tools
.filter((tool) => tool.label)
.filter((tool, index, array) => array.findIndex((t) => t.href === tool.href) === index);
// Dynamic minimum column width based on size
$: minColWidth = size === 'compact' ? '140px' : size === 'small' ? '200px' : '280px';
</script>
{#if uniqueTools.length === 0 && searchQuery}
<NoResults {searchQuery} />
{:else}
<section class="tools-grid">
<section class="tools-grid" class:compact={size === 'compact'} style="--min-col-width: {minColWidth};">
{#each uniqueTools as tool (`${idPrefix}-${tool.href.replaceAll('/', '-')}`)}
<ToolCard {tool} />
<ToolCard {tool} {size} />
{/each}
</section>
{/if}
@@ -28,17 +32,8 @@
<style lang="scss">
.tools-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--min-col-width, 280px)), 1fr));
gap: var(--spacing-md);
margin-bottom: var(--spacing-xl);
@media (max-width: 768px) {
grid-template-columns: 1fr;
gap: var(--spacing-md);
}
@media (min-width: 1200px) {
grid-template-columns: repeat(3, 1fr);
}
}
</style>
@@ -0,0 +1,343 @@
<script lang="ts">
import { site } from '$lib/constants/site';
import { TOP_NAV, SUB_NAV, type NavItem, type NavGroup } from '$lib/constants/nav';
import ToolsGrid from '$lib/components/global/ToolsGrid.svelte';
import SearchFilter from '$lib/components/furniture/SearchFilter.svelte';
import { bookmarks } from '$lib/stores/bookmarks';
import { frequentlyUsedTools, recentlyUsedTools } from '$lib/stores/toolUsage';
import Icon from '$lib/components/global/Icon.svelte';
interface Props {
toolPages: NavItem[];
referencePages: NavItem[];
}
let { toolPages, referencePages }: Props = $props();
// Helper to extract nav items from mixed structure
function extractNavItems(items: (NavItem | NavGroup)[]): NavItem[] {
const navItems: NavItem[] = [];
for (const item of items) {
if ('href' in item) {
navItems.push(item);
} else if ('title' in item && 'items' in item) {
navItems.push(...item.items);
}
}
return navItems;
}
// Category configuration - easily extensible for future customization
interface CategorySection {
id: string;
title: string;
icon: string;
basePath: string;
items: NavItem[];
}
const categories: CategorySection[] = $derived(
TOP_NAV.filter((nav) => nav.href !== '/reference')
.map((nav) => {
const subItems = SUB_NAV[nav.href] || [];
return {
id: nav.href.slice(1), // Remove leading slash
title: nav.label,
icon: getIconForCategory(nav.href),
basePath: nav.href,
items: extractNavItems(subItems),
};
})
.sort((a, b) => {
// Diagnostics first, then others
if (a.id === 'diagnostics') return -1;
if (b.id === 'diagnostics') return 1;
return 0;
}),
);
// Get appropriate icon for each category
function getIconForCategory(path: string): string {
const iconMap: Record<string, string> = {
'/subnetting': 'network',
'/cidr': 'layers',
'/ip-address-convertor': 'hash',
'/dns': 'server',
'/diagnostics': 'activity',
};
return iconMap[path] || 'folder';
}
// Convert tool usage to NavItem format
const mostUsedItems = $derived(
$frequentlyUsedTools.slice(0, 8).map((tool) => ({
href: tool.href,
label: tool.label || 'Tool',
icon: tool.icon,
description: tool.description,
})),
);
const recentItems = $derived(
$recentlyUsedTools.slice(0, 4).map((tool) => ({
href: tool.href,
label: tool.label || 'Tool',
icon: tool.icon,
description: tool.description,
})),
);
let filteredTools: NavItem[] = $state([...toolPages, ...referencePages]);
let searchQuery: string = $state('');
// Update filtered items when search changes
$effect(() => {
const allPages = [...toolPages, ...referencePages];
if (searchQuery.trim() === '') {
filteredTools = allPages;
} else {
const query = searchQuery.toLowerCase().trim();
filteredTools = allPages.filter(
(tool) =>
tool.label.toLowerCase().includes(query) ||
tool.description?.toLowerCase().includes(query) ||
tool.keywords?.some((keyword) => keyword.toLowerCase().includes(query)),
);
}
});
</script>
<!-- Minimal Hero -->
<section class="hero-categories">
<h1>{site.title}</h1>
</section>
<!-- Search Filter -->
<SearchFilter bind:filteredTools bind:searchQuery />
{#if searchQuery.trim() === ''}
<div class="categories-layout">
<!-- Bookmarks Section -->
{#if $bookmarks.length > 0}
<section class="category-section bookmarks-section">
<div class="section-header">
<Icon name="bookmarks" size="md" />
<h2>Bookmarked</h2>
<span class="count">{$bookmarks.length}</span>
</div>
<ToolsGrid
idPrefix="bookmarked"
tools={$bookmarks.map((b) => ({
href: b.href,
label: b.label,
icon: b.icon,
description: b.description,
}))}
searchQuery=""
/>
</section>
{/if}
<!-- Usage Row: Most Used (2/3) and Recently Used (1/3) -->
{#if mostUsedItems.length > 0 || recentItems.length > 0}
{@const hasBoth = mostUsedItems.length > 0 && recentItems.length > 0}
<div class="usage-row" class:both={hasBoth}>
{#if mostUsedItems.length > 0}
<section class="category-section most-used">
<div class="section-header">
<Icon name="frequently-used" size="md" />
<h2>Most Used</h2>
<span class="count">{mostUsedItems.length}</span>
</div>
<ToolsGrid size="compact" idPrefix="most-used" tools={mostUsedItems} searchQuery="" />
</section>
{/if}
{#if recentItems.length > 0}
<section class="category-section recently-used">
<div class="section-header">
<Icon name="clock" size="md" />
<h2>Recent</h2>
<span class="count">{recentItems.length}</span>
</div>
<ToolsGrid size="compact" idPrefix="recent" tools={recentItems} searchQuery="" />
</section>
{/if}
</div>
{/if}
<!-- Category Sections -->
<div class="categories-grid">
{#each categories as category (category.id)}
{#if category.items.length > 0}
<section class="category-section" class:full-width={category.id === 'diagnostics'}>
<div class="section-header">
<Icon name={category.icon} size="md" />
<h2>{category.title}</h2>
<span class="count">{category.items.length}</span>
</div>
<ToolsGrid size="compact" idPrefix={category.id} tools={category.items} searchQuery="" />
</section>
{/if}
{/each}
<!-- Reference Section -->
{#if referencePages.length > 0}
<section class="category-section full-width">
<div class="section-header">
<Icon name="book-open" size="md" />
<h2>Reference</h2>
<span class="count">{referencePages.length}</span>
</div>
<ToolsGrid size="small" idPrefix="reference" tools={referencePages} searchQuery="" />
</section>
{/if}
</div>
</div>
{:else}
<!-- Search Results -->
<ToolsGrid idPrefix="search" tools={filteredTools} {searchQuery} />
{/if}
<style lang="scss">
.hero-categories {
text-align: center;
padding: var(--spacing-lg) 0 var(--spacing-md);
h1 {
font-size: var(--font-size-2xl);
font-weight: 600;
color: var(--text-primary);
margin: 0;
line-height: 1.3;
@media (max-width: 768px) {
font-size: var(--font-size-xl);
}
}
}
.categories-layout {
display: flex;
flex-direction: column;
gap: var(--spacing-xl);
}
.category-section {
display: flex;
flex-direction: column;
gap: var(--spacing-md);
background: var(--bg-tertiary);
padding: var(--spacing-md);
border-radius: var(--radius-md);
border: 1px solid var(--border-primary);
box-shadow: var(--shadow-md);
break-inside: avoid;
page-break-inside: avoid;
max-height: 36rem;
overflow-y: auto;
animation: slideInFade 0.3s ease-out;
// Custom scrollbar styling
scrollbar-width: thin;
scrollbar-color: var(--border-primary) transparent;
&::-webkit-scrollbar {
width: 0.5rem;
}
&::-webkit-scrollbar-track {
background: transparent;
border-radius: var(--radius-md);
}
&::-webkit-scrollbar-thumb {
background: var(--border-primary);
border-radius: var(--radius-full);
transition: background var(--transition-fast);
&:hover {
background: var(--border-secondary);
}
}
@media (max-width: 768px) {
max-height: none;
overflow-y: visible;
}
}
.section-header {
display: flex;
align-items: center;
gap: var(--spacing-sm);
padding-bottom: var(--spacing-sm);
border-bottom: 1px solid var(--border-secondary);
h2 {
font-size: var(--font-size-lg);
font-weight: 600;
color: var(--text-primary);
margin: 0;
flex: 1;
}
.count {
font-size: var(--font-size-sm);
color: var(--text-tertiary);
background: var(--bg-tertiary);
padding: var(--spacing-xs) var(--spacing-sm);
border-radius: var(--radius-full);
font-weight: 500;
}
:global(svg) {
color: var(--color-primary);
flex-shrink: 0;
}
}
// Full width sections
.bookmarks-section,
.full-width {
grid-column: 1 / -1;
}
// Usage row: 2/3 and 1/3 split
.usage-row {
display: grid;
grid-template-columns: 1fr;
gap: var(--spacing-lg);
&.both {
grid-template-columns: 2fr 1fr;
}
@media (max-width: 1024px) {
grid-template-columns: 1fr;
}
}
// Categories grid - flexible masonry-like layout
.categories-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr));
gap: var(--spacing-xl);
align-items: start;
@media (max-width: 768px) {
grid-template-columns: 1fr;
}
}
@keyframes slideInFade {
from {
opacity: 0;
transform: translateY(-8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
</style>
@@ -0,0 +1,151 @@
<script lang="ts">
import { site, about } from '$lib/constants/site';
import type { NavItem } from '$lib/constants/nav';
import ToolsGrid from '$lib/components/global/ToolsGrid.svelte';
import SearchFilter from '$lib/components/furniture/SearchFilter.svelte';
import BookmarksGrid from '$lib/components/global/BookmarksGrid.svelte';
import FrequentlyUsedGrid from '$lib/components/global/FrequentlyUsedGrid.svelte';
import { bookmarks } from '$lib/stores/bookmarks';
import { frequentlyUsedTools } from '$lib/stores/toolUsage';
import Icon from '$lib/components/global/Icon.svelte';
interface Props {
toolPages: NavItem[];
referencePages: NavItem[];
}
let { toolPages, referencePages }: Props = $props();
let filteredTools: NavItem[] = $state(toolPages);
let filteredReference: NavItem[] = $state(referencePages);
let searchQuery: string = $state('');
// Update filtered items when search changes
$effect(() => {
if (searchQuery.trim() === '') {
filteredTools = toolPages;
filteredReference = referencePages;
} else {
const query = searchQuery.toLowerCase().trim();
filteredTools = toolPages.filter(
(tool) =>
tool.label.toLowerCase().includes(query) ||
tool.description?.toLowerCase().includes(query) ||
tool.keywords?.some((keyword) => keyword.toLowerCase().includes(query)),
);
filteredReference = referencePages.filter(
(page) =>
page.label.toLowerCase().includes(query) ||
page.description?.toLowerCase().includes(query) ||
page.keywords?.some((keyword) => keyword.toLowerCase().includes(query)),
);
}
});
</script>
<!-- Hero Section -->
<section class="hero">
<div class="hero-content">
<h2>{site.title}</h2>
<p class="hero-description">{about.line1}</p>
<a href="/sitemap" class="sitemap-link">Sitemap</a>
</div>
</section>
<!-- Search Filter -->
<SearchFilter bind:filteredTools bind:searchQuery />
{#if searchQuery.trim() === ''}
<!-- Bookmarks Section -->
<BookmarksGrid hideOther={true} />
<!-- Frequently Used Tools Section -->
<FrequentlyUsedGrid hideOther={true} />
<!-- Show "All Tools" heading if there are bookmarks or frequently used tools -->
{#if $bookmarks.length > 0 || $frequentlyUsedTools.length > 0}
<section class="tools-grid-sub-header">
<Icon name="network-port" size="md" />
<h2>All Tools</h2>
<span class="count">{toolPages.length + referencePages.length}</span>
</section>
{/if}
<!-- Tools Grid -->
<ToolsGrid idPrefix="tools" tools={filteredTools} {searchQuery} />
<!-- Reference Pages Section -->
{#if filteredReference.length > 0}
<section class="reference-section">
<div class="section-header">
<h2>Reference & Documentation</h2>
<p class="section-description">
Comprehensive reference materials and documentation for network professionals.
</p>
</div>
<ToolsGrid idPrefix="reference" tools={filteredReference} {searchQuery} />
</section>
{/if}
{:else}
<!-- Combined Search Results -->
<ToolsGrid idPrefix="search" tools={[...filteredTools, ...filteredReference]} {searchQuery} />
{/if}
<style lang="scss">
.sitemap-link {
display: none;
}
/* Homepage specific styles */
.hero {
text-align: center;
padding: var(--spacing-xl) 0 var(--spacing-sm);
.hero-content {
max-width: 900px;
margin: 0 auto;
h2 {
font-size: var(--font-size-3xl);
font-weight: 700;
color: var(--text-primary);
margin-bottom: var(--spacing-md);
line-height: 1.2;
@media (max-width: 768px) {
font-size: var(--font-size-xl);
}
}
.hero-description {
font-size: var(--font-size-lg);
color: var(--text-secondary);
line-height: 1.6;
margin: 0;
@media (max-width: 768px) {
font-size: var(--font-size-md);
}
}
}
}
.reference-section {
margin-top: var(--spacing-xl);
.section-header {
text-align: center;
margin-bottom: var(--spacing-lg);
h2 {
font-size: var(--font-size-xl);
font-weight: 600;
color: var(--text-primary);
margin-bottom: var(--spacing-sm);
}
.section-description {
font-size: var(--font-size-md);
color: var(--text-secondary);
max-width: 600px;
margin: 0 auto;
line-height: 1.6;
}
}
}
</style>
@@ -0,0 +1,62 @@
<script lang="ts">
import { site } from '$lib/constants/site';
import type { NavItem } from '$lib/constants/nav';
import ToolsGrid from '$lib/components/global/ToolsGrid.svelte';
import SearchFilter from '$lib/components/furniture/SearchFilter.svelte';
interface Props {
toolPages: NavItem[];
referencePages: NavItem[];
}
let { toolPages, referencePages }: Props = $props();
let filteredTools: NavItem[] = $state([...toolPages, ...referencePages]);
let searchQuery: string = $state('');
// Update filtered items when search changes
$effect(() => {
const allPages = [...toolPages, ...referencePages];
if (searchQuery.trim() === '') {
filteredTools = allPages;
} else {
const query = searchQuery.toLowerCase().trim();
filteredTools = allPages.filter(
(tool) =>
tool.label.toLowerCase().includes(query) ||
tool.description?.toLowerCase().includes(query) ||
tool.keywords?.some((keyword) => keyword.toLowerCase().includes(query)),
);
}
});
</script>
<!-- Minimal Hero Section -->
<section class="hero-minimal">
<h1>{site.title}</h1>
</section>
<!-- Search Filter -->
<SearchFilter bind:filteredTools bind:searchQuery />
<!-- Compact Tools Grid -->
<ToolsGrid idPrefix="minimal" tools={filteredTools} {searchQuery} />
<style lang="scss">
.hero-minimal {
text-align: center;
padding: var(--spacing-lg) 0 var(--spacing-md);
h1 {
font-size: var(--font-size-2xl);
font-weight: 600;
color: var(--text-primary);
margin: 0;
line-height: 1.3;
@media (max-width: 768px) {
font-size: var(--font-size-xl);
}
}
}
</style>
+1
View File
@@ -284,6 +284,7 @@ export const iconMap: Record<string, string> = {
shuffle: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d=""/><path d="M489 95L569 175C578.4 184.4 578.4 199.6 569 208.9L489 288.9C479.6 298.3 464.4 298.3 455.1 288.9C445.8 279.5 445.7 264.3 455.1 255L494.1 216L420 216C404.9 216 390.7 223.1 381.6 235.2L348 280L318 240L343.2 206.4C361.3 182.2 389.8 168 420 168L494.1 168L455.1 129C445.7 119.6 445.7 104.4 455.1 95.1C464.5 85.8 479.7 85.7 489 95.1zM258 400L232.8 433.6C214.7 457.8 186.2 472 156 472L88 472C74.7 472 64 461.3 64 448C64 434.7 74.7 424 88 424L156 424C171.1 424 185.3 416.9 194.4 404.8L228 360L258 400zM455 351C464.4 341.6 479.6 341.6 488.9 351L568.9 431C578.3 440.4 578.3 455.6 568.9 464.9L488.9 544.9C479.5 554.3 464.3 554.3 455 544.9C445.7 535.5 445.6 520.3 455 511L494 472L419.9 472C389.7 472 361.2 457.8 343.1 433.6L194.4 235.2C185.3 223.1 171.1 216 156 216L88 216C74.7 216 64 205.3 64 192C64 178.7 74.7 168 88 168L156 168C186.2 168 214.7 182.2 232.8 206.4L381.6 404.8C390.7 416.9 404.9 424 420 424L494.1 424L455.1 385C445.7 375.6 445.7 360.4 455.1 351.1z"/></svg>`,
mailbox: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M283.3 176L448 176C509.9 176 560 226.1 560 288L560 480C560 488.8 552.8 496 544 496L318 496C319.3 490.9 320 485.5 320 480L320 272C320 235.1 306.1 201.5 283.3 176zM368 296C368 309.3 378.7 320 392 320L416 320L416 360C416 373.3 426.7 384 440 384L488 384C501.3 384 512 373.3 512 360L512 296C512 282.7 501.3 272 488 272L392 272C378.7 272 368 282.7 368 296z"/><path d="M283.3 176C306.1 201.5 320 235.1 320 272L320 480C320 485.5 319.3 490.9 318 496L544 496C552.8 496 560 488.8 560 480L560 288C560 226.1 509.9 176 448 176L283.3 176zM176 176C123 176 80 219 80 272L80 480C80 488.8 87.2 496 96 496L256 496C264.8 496 272 488.8 272 480L272 272C272 219 229 176 176 176zM176 128L448 128C536.4 128 608 199.6 608 288L608 480C608 515.3 579.3 544 544 544L96 544C60.7 544 32 515.3 32 480L32 272C32 192.5 96.5 128 176 128zM136 272L216 272C229.3 272 240 282.7 240 296C240 309.3 229.3 320 216 320L136 320C122.7 320 112 309.3 112 296C112 282.7 122.7 272 136 272zM368 296C368 282.7 378.7 272 392 272L488 272C501.3 272 512 282.7 512 296L512 360C512 373.3 501.3 384 488 384L440 384C426.7 384 416 373.3 416 360L416 320L392 320C378.7 320 368 309.3 368 296z"/></svg>`,
mustache: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M48.2 274.7C52.7 353.5 118 416 198 416C230.5 416 262 405.5 288 386L305.6 372.8C314.1 366.4 325.9 366.4 334.4 372.8L352 386C378 405.5 409.5 416 442 416C521.9 416 587.3 353.5 591.8 274.7C547.5 291.4 495.8 281.7 460.4 246.3C446.1 232 426.8 224 406.6 224L405.4 224C386.9 224 369 230.5 354.8 242.3L335.5 258.4C326.6 265.8 313.7 265.8 304.8 258.4L285.5 242.3C271.3 230.5 253.4 224 234.9 224L233.7 224C213.5 224 194.2 232 179.9 246.3C144.5 281.7 92.8 291.4 48.5 274.7z"/><path d="M233.4 176C200.5 176 169 189.1 145.7 212.3C117.2 240.8 71.5 242.1 41.4 215.4L39.9 214.1C37.2 211.7 34.1 210 30.9 209.1C28.1 208.3 25.5 208 23.5 208.1C19.9 208.2 16.5 209 13.4 210.5C11.2 211.5 9.2 212.9 7.4 214.7C2.8 219.1-.1 225.3-.1 232.1L-.1 266.1C-.1 375.5 88.5 464.1 197.9 464.1C240.7 464.1 282.4 450.2 316.7 424.5L319.9 422.1L323.1 424.5C357.4 450.2 399.1 464.1 441.9 464.1C551.3 464.1 639.9 375.5 639.9 266.1L639.9 232.1C639.9 225.2 637 219 632.4 214.7C628.2 210.7 622.6 208.2 616.3 208.1C615.9 208.1 615.4 208.1 615 208.1C612.6 208.2 610.2 208.6 607.9 209.4C605 210.4 602.3 212 599.9 214.1L598.4 215.4C568.3 242.1 522.6 240.8 494.1 212.3C470.8 189 439.3 176 406.4 176L405.2 176C375.5 176 346.7 186.4 323.9 205.5L319.9 208.8L315.9 205.5C293.1 186.5 264.3 176 234.6 176L233.4 176zM591.7 274.7C587.2 353.5 521.9 416 441.9 416C409.4 416 377.9 405.5 351.9 386L334.3 372.8C325.8 366.4 314 366.4 305.5 372.8L288 386C262 405.5 230.5 416 198 416C118.1 416 52.7 353.5 48.2 274.7C92.5 291.4 144.2 281.7 179.6 246.3C193.9 232 213.2 224 233.4 224L234.6 224C253.1 224 271 230.5 285.2 242.3L304.5 258.4C313.4 265.8 326.3 265.8 335.2 258.4L354.5 242.3C368.7 230.5 386.6 224 405.1 224L406.3 224C426.5 224 445.8 232 460.1 246.3C495.5 281.7 547.2 291.4 591.5 274.7z"/></svg>`,
'frequently-used': `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d=""/><path d="M152.5 96C139.2 96 128.5 106.7 128.5 120C128.5 133.3 139.2 144 152.5 144L206.6 144L71.6 279C62.2 288.4 62.2 303.6 71.6 312.9C81 322.2 96.2 322.3 105.5 312.9L240.5 177.9L240.5 232C240.5 245.3 251.2 256 264.5 256C277.8 256 288.5 245.3 288.5 232L288.5 120C288.5 106.7 277.8 96 264.5 96L152.5 96zM468.3 134.1C468.3 155.1 485.4 172.2 506.4 172.2C527.4 172.2 544.5 155.1 544.5 134.1C544.5 113.1 527.4 96 506.4 96C485.4 96 468.3 113.1 468.3 134.1zM344.2 258.2C344.2 279.2 361.3 296.3 382.3 296.3C403.3 296.3 420.4 279.2 420.4 258.2C420.4 237.2 403.3 220.1 382.3 220.1C361.3 220.1 344.2 237.2 344.2 258.2zM506.4 220.1C485.4 220.1 468.3 237.2 468.3 258.2C468.3 279.2 485.4 296.3 506.4 296.3C527.4 296.3 544.5 279.2 544.5 258.2C544.5 237.2 527.4 220.1 506.4 220.1zM220.7 381.8C220.7 402.8 237.8 419.9 258.8 419.9C279.8 419.9 296.9 402.8 296.9 381.8C296.9 360.8 279.8 343.7 258.8 343.7C237.8 343.7 220.7 360.8 220.7 381.8zM382.3 343.7C361.3 343.7 344.2 360.8 344.2 381.8C344.2 402.8 361.3 419.9 382.3 419.9C403.3 419.9 420.4 402.8 420.4 381.8C420.4 360.8 403.3 343.7 382.3 343.7zM468.4 381.8C468.4 402.8 485.5 419.9 506.5 419.9C527.5 419.9 544.6 402.8 544.6 381.8C544.6 360.8 527.5 343.7 506.5 343.7C485.5 343.7 468.4 360.8 468.4 381.8zM134.6 467.8C113.6 467.8 96.5 484.9 96.5 505.9C96.5 526.9 113.6 544 134.6 544C155.6 544 172.7 526.9 172.7 505.9C172.7 484.9 155.6 467.8 134.6 467.8zM220.7 505.9C220.7 526.9 237.8 544 258.8 544C279.8 544 296.9 526.9 296.9 505.9C296.9 484.9 279.8 467.8 258.8 467.8C237.8 467.8 220.7 484.9 220.7 505.9zM382.3 467.8C361.3 467.8 344.2 484.9 344.2 505.9C344.2 526.9 361.3 544 382.3 544C403.3 544 420.4 526.9 420.4 505.9C420.4 484.9 403.3 467.8 382.3 467.8zM468.4 505.9C468.4 526.9 485.5 544 506.5 544C527.5 544 544.6 526.9 544.6 505.9C544.6 484.9 527.5 467.8 506.5 467.8C485.5 467.8 468.4 484.9 468.4 505.9z"/></svg>`,
// 'template': ``,
// 'list-check': ``,
share: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M112 320C112 346.5 133.5 368 160 368C186.5 368 208 346.5 208 320C208 293.5 186.5 272 160 272C133.5 272 112 293.5 112 320zM400 160C400 186.5 421.5 208 448 208C474.5 208 496 186.5 496 160C496 133.5 474.5 112 448 112C421.5 112 400 133.5 400 160zM400 480C400 506.5 421.5 528 448 528C474.5 528 496 506.5 496 480C496 453.5 474.5 432 448 432C421.5 432 400 453.5 400 480z"/><path d="M496 160C496 133.5 474.5 112 448 112C421.5 112 400 133.5 400 160C400 186.5 421.5 208 448 208C474.5 208 496 186.5 496 160zM544 160C544 213 501 256 448 256C420.6 256 395.9 244.5 378.4 226.1L252.9 295.8C254.9 303.5 256 311.6 256 320C256 328.4 254.9 336.5 252.9 344.2L378.4 413.9C395.9 395.5 420.6 384 448 384C501 384 544 427 544 480C544 533 501 576 448 576C395 576 352 533 352 480C352 471.7 353.1 463.5 355.1 455.8L229.6 386.1C212.1 404.5 187.4 416 160 416C107 416 64 373 64 320C64 267 107 224 160 224C187.4 224 212.1 235.5 229.6 253.9L355.1 184.2C353.1 176.5 352 168.4 352 160C352 107 395 64 448 64C501 64 544 107 544 160zM208 320C208 293.5 186.5 272 160 272C133.5 272 112 293.5 112 320C112 346.5 133.5 368 160 368C186.5 368 208 346.5 208 320zM448 528C474.5 528 496 506.5 496 480C496 453.5 474.5 432 448 432C421.5 432 400 453.5 400 480C400 506.5 421.5 528 448 528z"/></svg>`,
+19
View File
@@ -0,0 +1,19 @@
import { writable } from 'svelte/store';
interface ContextMenuState {
id: string | null;
x: number;
y: number;
}
function createContextMenuStore() {
const { subscribe, set } = writable<ContextMenuState>({ id: null, x: 0, y: 0 });
return {
subscribe,
open: (id: string, x: number, y: number) => set({ id, x, y }),
close: () => set({ id: null, x: 0, y: 0 }),
};
}
export const activeContextMenu = createContextMenuStore();
+79
View File
@@ -0,0 +1,79 @@
import { writable } from 'svelte/store';
import { browser } from '$app/environment';
export type HomepageLayoutMode = 'default' | 'minimal' | 'categories';
export interface HomepageLayoutOption {
id: HomepageLayoutMode;
name: string;
description: string;
}
const STORAGE_KEY = 'homepage-layout';
// Available homepage layout options
export const homepageLayoutOptions: HomepageLayoutOption[] = [
{
id: 'default',
name: 'Default',
description: 'Full homepage with all sections and features',
},
{
id: 'minimal',
name: 'Minimal',
description: 'Clean, simplified homepage layout',
},
{
id: 'categories',
name: 'Categories',
description: 'Organized by tool categories with flexible grid layout',
},
];
function createHomepageLayoutStore() {
const { subscribe, set } = writable<HomepageLayoutMode>('categories');
return {
subscribe,
// Initialize from localStorage or default
init: () => {
if (browser) {
const stored = localStorage.getItem(STORAGE_KEY);
const isValidMode = homepageLayoutOptions.some((option) => option.id === stored);
const initialMode = isValidMode ? (stored as HomepageLayoutMode) : 'categories';
set(initialMode);
return initialMode;
}
return 'categories';
},
// Set homepage layout mode and persist to localStorage
setMode: (mode: HomepageLayoutMode) => {
const option = homepageLayoutOptions.find((opt) => opt.id === mode);
if (!option) {
console.warn(`Homepage layout mode "${mode}" is not valid`);
return;
}
set(mode);
if (browser) {
localStorage.setItem(STORAGE_KEY, mode);
}
},
// Get option configuration
getOption: (mode: HomepageLayoutMode): HomepageLayoutOption | undefined => {
return homepageLayoutOptions.find((opt) => opt.id === mode);
},
// Get all available options
getAllOptions: (): HomepageLayoutOption[] => {
return homepageLayoutOptions;
},
};
}
export const homepageLayout = createHomepageLayoutStore();
+14
View File
@@ -130,3 +130,17 @@ export const frequentlyUsedTools = derived(toolUsage, ($toolUsage) => {
...data,
}));
});
/**
* Derived store for recently used tools
*/
export const recentlyUsedTools = derived(toolUsage, ($toolUsage) => {
const sorted = Object.entries($toolUsage)
.sort((a, b) => b[1].lastVisited - a[1].lastVisited)
.slice(0, maxItems);
return sorted.map(([href, data]) => ({
href,
...data,
}));
});
+13 -135
View File
@@ -1,14 +1,11 @@
<script lang="ts">
import '../styles/pages.scss';
import { site, about } from '$lib/constants/site';
import { onMount } from 'svelte';
import { ALL_PAGES, SUB_NAV, type NavItem, type NavGroup } from '$lib/constants/nav';
import ToolsGrid from '$lib/components/global/ToolsGrid.svelte';
import SearchFilter from '$lib/components/furniture/SearchFilter.svelte';
import BookmarksGrid from '$lib/components/global/BookmarksGrid.svelte';
import FrequentlyUsedGrid from '$lib/components/global/FrequentlyUsedGrid.svelte';
import { bookmarks } from '$lib/stores/bookmarks';
import { frequentlyUsedTools } from '$lib/stores/toolUsage';
import Icon from '$lib/components/global/Icon.svelte';
import { homepageLayout } from '$lib/stores/homepageLayout';
import HomepageDefault from '$lib/components/home/HomepageDefault.svelte';
import HomepageMinimal from '$lib/components/home/HomepageMinimal.svelte';
import HomepageCategories from '$lib/components/home/HomepageCategories.svelte';
// Helper function to extract nav items from mixed structure
function extractNavItems(items: (NavItem | NavGroup)[]): NavItem[] {
@@ -30,136 +27,17 @@
!page.href.startsWith('/reference') && !page.href.startsWith('/bookmarks') && !page.href.startsWith('/offline'),
);
let filteredTools: NavItem[] = $state(toolPages);
let filteredReference: NavItem[] = $state(referencePages);
let searchQuery: string = $state('');
let currentLayout = $state(homepageLayout);
// Update filtered items when search changes
$effect(() => {
if (searchQuery.trim() === '') {
filteredTools = toolPages;
filteredReference = referencePages;
} else {
const query = searchQuery.toLowerCase().trim();
filteredTools = toolPages.filter(
(tool) =>
tool.label.toLowerCase().includes(query) ||
tool.description?.toLowerCase().includes(query) ||
tool.keywords?.some((keyword) => keyword.toLowerCase().includes(query)),
);
filteredReference = referencePages.filter(
(page) =>
page.label.toLowerCase().includes(query) ||
page.description?.toLowerCase().includes(query) ||
page.keywords?.some((keyword) => keyword.toLowerCase().includes(query)),
);
}
onMount(() => {
homepageLayout.init();
});
</script>
<!-- Hero Section -->
<section class="hero">
<div class="hero-content">
<h2>{site.title}</h2>
<p class="hero-description">{about.line1}</p>
<a href="/sitemap" class="sitemap-link">Sitemap</a>
</div>
</section>
<!-- Search Filter -->
<SearchFilter bind:filteredTools bind:searchQuery />
{#if searchQuery.trim() === ''}
<!-- Bookmarks Section -->
<BookmarksGrid hideOther={true} />
<!-- Frequently Used Tools Section -->
<FrequentlyUsedGrid hideOther={true} />
<!-- Show "All Tools" heading if there are bookmarks or frequently used tools -->
{#if $bookmarks.length > 0 || $frequentlyUsedTools.length > 0}
<section class="tools-grid-sub-header">
<Icon name="network-port" size="md" />
<h2>All Tools</h2>
<span class="count">{toolPages.length + referencePages.length}</span>
</section>
{/if}
<!-- Tools Grid -->
<ToolsGrid idPrefix="tools" tools={filteredTools} {searchQuery} />
<!-- Reference Pages Section -->
{#if filteredReference.length > 0}
<section class="reference-section">
<div class="section-header">
<h2>Reference & Documentation</h2>
<p class="section-description">
Comprehensive reference materials and documentation for network professionals.
</p>
</div>
<ToolsGrid idPrefix="reference" tools={filteredReference} {searchQuery} />
</section>
{/if}
{#if $currentLayout === 'minimal'}
<HomepageMinimal {toolPages} {referencePages} />
{:else if $currentLayout === 'categories'}
<HomepageCategories {toolPages} {referencePages} />
{:else}
<!-- Combined Search Results -->
<ToolsGrid idPrefix="search" tools={[...filteredTools, ...filteredReference]} {searchQuery} />
<HomepageDefault {toolPages} {referencePages} />
{/if}
<style lang="scss">
.sitemap-link {
display: none;
}
/* Homepage specific styles */
.hero {
text-align: center;
padding: var(--spacing-xl) 0 var(--spacing-sm);
.hero-content {
max-width: 900px;
margin: 0 auto;
h2 {
font-size: var(--font-size-3xl);
font-weight: 700;
color: var(--text-primary);
margin-bottom: var(--spacing-md);
line-height: 1.2;
@media (max-width: 768px) {
font-size: var(--font-size-xl);
}
}
.hero-description {
font-size: var(--font-size-lg);
color: var(--text-secondary);
line-height: 1.6;
margin: 0;
@media (max-width: 768px) {
font-size: var(--font-size-md);
}
}
}
}
.reference-section {
margin-top: var(--spacing-xl);
.section-header {
text-align: center;
margin-bottom: var(--spacing-lg);
h2 {
font-size: var(--font-size-xl);
font-weight: 600;
color: var(--text-primary);
margin-bottom: var(--spacing-sm);
}
.section-description {
font-size: var(--font-size-md);
color: var(--text-secondary);
max-width: 600px;
margin: 0 auto;
line-height: 1.6;
}
}
}
</style>
+1
View File
@@ -524,6 +524,7 @@ html[data-theme='light'] {
--color-error: #f44336;
--color-info: #00bcd4;
--border-secondary: #d3ddeb;
--border-primary: #e0e0e0;
--surface-hover: #f5f5f5;
--surface-active: #eeeeee;