]> danix's work - danix.xyz-2.git/commitdiff
refactor: unify 404 page with shared search functionality
authorDanilo M. <redacted>
Mon, 20 Apr 2026 11:59:05 +0000 (13:59 +0200)
committerDanilo M. <redacted>
Mon, 20 Apr 2026 11:59:05 +0000 (13:59 +0200)
Removes inline window.articlesData from both 404 pages. not-found-page.js now uses shared notFoundPage Alpine component from search.js (lazy-loaded index). Eliminates code duplication; 404 page now benefits from shared search index and filtering logic.

Co-Authored-By: Claude Haiku 4.5 <redacted>
themes/danix-xyz-hacker/assets/js/not-found-page.js
themes/danix-xyz-hacker/layouts/404.en.html
themes/danix-xyz-hacker/layouts/404.it.html

index 6ec8895ed0ea3f023e9fb48814d578bb23d2185a..2b4f67611b03f90cc0656117eb56917bbc260a1b 100644 (file)
@@ -1,35 +1,9 @@
+// 404 page: initialize shared notFoundPage Alpine component
 document.addEventListener('alpine:init', () => {
-  Alpine.data('notFoundPage', () => ({
-    showEasterEgg: false,
-    searchQuery: '',
-    filteredArticles: [],
-    allArticles: window.articlesData || [],
-
-    filterArticles(query) {
-      this.searchQuery = query.toLowerCase();
-      if (!this.searchQuery) {
-        this.filteredArticles = [];
-        return;
-      }
-      this.filteredArticles = this.allArticles.filter(article =>
-        article.title.toLowerCase().includes(this.searchQuery) ||
-        article.content.toLowerCase().includes(this.searchQuery)
-      ).slice(0, 5);
-    },
-
-    toggleEasterEgg() {
-      console.log('toggleEasterEgg called, current state:', this.showEasterEgg);
-      this.showEasterEgg = !this.showEasterEgg;
-      console.log('new state:', this.showEasterEgg);
-    },
-
-    goToRandomArticle() {
-      if (this.allArticles.length > 0) {
-        const randomArticle = this.allArticles[Math.floor(Math.random() * this.allArticles.length)];
-        window.location.href = randomArticle.url;
-      }
-    }
-  }));
-
-  console.log('notFoundPage Alpine component registered');
+  // Ensure search index is preloaded on 404 page
+  const notFoundElement = document.querySelector('[x-data*="notFoundPage"]');
+  if (notFoundElement && notFoundElement.__x) {
+    notFoundElement.__x.$data.init();
+  }
+  console.log('404 page initialized with shared search functionality');
 });
index 6ed4892387f9ccf9716be409beb81f20ef12685e..8d8641db994248bc38474d35a095618da5e25f1b 100644 (file)
@@ -1,19 +1,5 @@
 {{ define "main" }}
 
-<!-- Pass articles data to JavaScript for Alpine.js -->
-<script>
-window.articlesData = [
-  {{ range (where .Site.RegularPages "Section" "articles") }}
-  {
-    title: '{{ .Title | safeJS }}',
-    url: '{{ .Permalink }}',
-    date: '{{ .Date.Format "Jan 02, 2006" }}',
-    content: '{{ (.Summary | plainify | safeJS) }}'
-  },
-  {{ end }}
-];
-</script>
-
 <main class="min-h-screen px-4 py-12">
   <div class="mx-auto px-4 py-12 max-w-4xl border border-border glow-accent rounded-lg bg-bg p-8" x-data="notFoundPage()">
     <div class="text-center">
index 805b19a79d06e7f050fdf681ac5dd3b130507743..1a8fbbe3bb54c1f457551ce63e363cb3c1e70237 100644 (file)
@@ -1,19 +1,5 @@
 {{ define "main" }}
 
-<!-- Pass articles data to JavaScript for Alpine.js -->
-<script>
-window.articlesData = [
-  {{ range (where .Site.RegularPages "Section" "articles") }}
-  {
-    title: '{{ .Title | safeJS }}',
-    url: '{{ .Permalink }}',
-    date: '{{ .Date.Format "Jan 02, 2006" }}',
-    content: '{{ (.Summary | plainify | safeJS) }}'
-  },
-  {{ end }}
-];
-</script>
-
 <main class="min-h-screen px-4 py-12">
   <div class="mx-auto px-4 py-12 max-w-4xl border border-border glow-accent rounded-lg bg-bg p-8" x-data="notFoundPage()">
     <div class="text-center">