summaryrefslogtreecommitdiffstats
path: root/themes/danix-xyz-hacker/assets/js
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-04-20 13:59:05 +0200
committerDanilo M. <danix@danix.xyz>2026-04-20 13:59:05 +0200
commit60f1a9352ed91135b531e14e7d061c0a1987cd0b (patch)
tree2c21fa2ac64481523392e00d6b8f12981396c9c8 /themes/danix-xyz-hacker/assets/js
parent7ac53237b95c798beb57b37f2f7bf38be1f4056b (diff)
downloaddanixxyz-60f1a9352ed91135b531e14e7d061c0a1987cd0b.tar.gz
danixxyz-60f1a9352ed91135b531e14e7d061c0a1987cd0b.zip
refactor: unify 404 page with shared search functionality
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 <noreply@anthropic.com>
Diffstat (limited to 'themes/danix-xyz-hacker/assets/js')
-rw-r--r--themes/danix-xyz-hacker/assets/js/not-found-page.js40
1 files changed, 7 insertions, 33 deletions
diff --git a/themes/danix-xyz-hacker/assets/js/not-found-page.js b/themes/danix-xyz-hacker/assets/js/not-found-page.js
index 6ec8895..2b4f676 100644
--- a/themes/danix-xyz-hacker/assets/js/not-found-page.js
+++ b/themes/danix-xyz-hacker/assets/js/not-found-page.js
@@ -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');
});