From 0e3d654a58be8ac77ab3a02928960d1015892b96 Mon Sep 17 00:00:00 2001 From: overcuriousity Date: Tue, 12 Aug 2025 16:28:05 +0200 Subject: [PATCH] progress --- src/components/Video.astro | 78 ++---- src/layouts/BaseLayout.astro | 47 ++-- src/utils/clientUtils.ts | 11 +- src/utils/remarkVideoPlugin.ts | 430 ++++++++++++++------------------ src/utils/videoUtils.ts | 431 ++++++++++++--------------------- 5 files changed, 393 insertions(+), 604 deletions(-) diff --git a/src/components/Video.astro b/src/components/Video.astro index ca5a833..0e8473e 100644 --- a/src/components/Video.astro +++ b/src/components/Video.astro @@ -1,5 +1,5 @@ --- -// src/components/Video.astro +// src/components/Video.astro - SIMPLIFIED using consolidated videoProcessor import { videoProcessor, type VideoMetadata } from '../utils/videoUtils.js'; export interface Props { @@ -36,7 +36,7 @@ const { fallback } = Astro.props; -// Process the video URL and generate optimized sources +// SIMPLIFIED: Use consolidated videoProcessor const metadata: Partial = { title, description, @@ -55,21 +55,18 @@ const options = { height }; -let processedVideo; let videoHTML = ''; -let errorMessage = ''; try { - processedVideo = await videoProcessor.processVideoUrl(src, metadata); + const processedVideo = await videoProcessor.processVideoUrl(src, metadata); videoHTML = videoProcessor.generateVideoHTML(processedVideo, options); } catch (error) { console.error('[VIDEO COMPONENT] Processing failed:', error); - errorMessage = error.message; videoHTML = `
⚠️
-
${fallback || `Video could not be loaded: ${errorMessage}`}
+
${fallback || `Video could not be loaded: ${error.message}`}
`; @@ -79,7 +76,7 @@ try { - - \ No newline at end of file + \ No newline at end of file diff --git a/src/layouts/BaseLayout.astro b/src/layouts/BaseLayout.astro index bfd51bf..4713961 100644 --- a/src/layouts/BaseLayout.astro +++ b/src/layouts/BaseLayout.astro @@ -173,32 +173,31 @@ const { title, description = 'ForensicPathways - A comprehensive directory of di getStoredTheme }; - (window as any).showToolDetails = function(toolName: string, modalType: string = 'primary') { - - let attempts = 0; - const maxAttempts = 50; - - const tryDelegate = () => { - const matrixShowToolDetails = (window as any).matrixShowToolDetails; + (window as any).showToolDetails = function(toolName: string, modalType: string = 'primary') { + let attempts = 0; + const maxAttempts = 50; - if (matrixShowToolDetails && typeof matrixShowToolDetails === 'function') { - return matrixShowToolDetails(toolName, modalType); - } + const tryDelegate = () => { + const matrixShowToolDetails = (window as any).matrixShowToolDetails; + + if (matrixShowToolDetails && typeof matrixShowToolDetails === 'function') { + return matrixShowToolDetails(toolName, modalType); + } + + const directShowToolDetails = (window as any).directShowToolDetails; + if (directShowToolDetails && typeof directShowToolDetails === 'function') { + return directShowToolDetails(toolName, modalType); + } + + attempts++; + if (attempts < maxAttempts) { + setTimeout(tryDelegate, 100); + } else { + } + }; - const directShowToolDetails = (window as any).directShowToolDetails; - if (directShowToolDetails && typeof directShowToolDetails === 'function') { - return directShowToolDetails(toolName, modalType); - } - - attempts++; - if (attempts < maxAttempts) { - setTimeout(tryDelegate, 100); - } else { - } + tryDelegate(); }; - - tryDelegate(); - }; (window as any).hideToolDetails = function(modalType: string = 'both') { const matrixHideToolDetails = (window as any).matrixHideToolDetails; @@ -229,7 +228,7 @@ const { title, description = 'ForensicPathways - A comprehensive directory of di authRequired: data.aiAuthRequired, expires: data.expires }; - case 'gatedcontent': // ADD THIS CASE + case 'gatedcontent': return { authenticated: data.gatedContentAuthenticated, authRequired: data.gatedContentAuthRequired, diff --git a/src/utils/clientUtils.ts b/src/utils/clientUtils.ts index 0d766e1..1f9bce0 100644 --- a/src/utils/clientUtils.ts +++ b/src/utils/clientUtils.ts @@ -1,5 +1,9 @@ // src/utils/clientUtils.ts -// Client-side utilities that mirror server-side toolHelpers.ts +// MINIMAL utilities that don't conflict with BaseLayout.astro or env.d.ts + +// ============================================================================ +// CORE TOOL UTILITIES (shared between client and server) +// ============================================================================ export function createToolSlug(toolName: string): string { if (!toolName || typeof toolName !== 'string') { @@ -30,7 +34,10 @@ export function isToolHosted(tool: any): boolean { tool.projectUrl.trim() !== ""; } -// Consolidated Autocomplete Functionality +// ============================================================================ +// AUTOCOMPLETE FUNCTIONALITY (keep this here since it's complex) +// ============================================================================ + interface AutocompleteOptions { minLength?: number; maxResults?: number; diff --git a/src/utils/remarkVideoPlugin.ts b/src/utils/remarkVideoPlugin.ts index d5b2670..361bfa1 100644 --- a/src/utils/remarkVideoPlugin.ts +++ b/src/utils/remarkVideoPlugin.ts @@ -1,8 +1,8 @@ -// src/utils/remarkVideoPlugin.ts +// src/utils/remarkVideoPlugin.ts - Consolidated with videoUtils import { visit } from 'unist-util-visit'; import type { Plugin } from 'unified'; -import type { Root, Text, Element } from 'hast'; -import { videoProcessor } from './videoUtils.js'; +import type { Root } from 'hast'; +import { videoProcessor, isVideoUrl } from './videoUtils.js'; interface VideoConfig { enableAsync?: boolean; @@ -16,15 +16,9 @@ interface VideoConfig { } /** - * Remark plugin to transform video syntax in markdown to HTML video elements - * - * Supports multiple syntaxes: - * 1. Custom video directive: :::video{src="url" title="Title" controls autoplay} - * 2. Image syntax for videos: ![video](url "title") - * 3. HTML video tags: - * 4. Link syntax with video: [Video Title](url.mp4) + * CONSOLIDATED Remark plugin for video processing + * Uses videoProcessor singleton to avoid code duplication */ -// REPLACE the transformer body to collect async tasks and call the processor export const remarkVideoPlugin: Plugin<[VideoConfig?], Root> = (config = {}) => { const { enableAsync = true, @@ -40,53 +34,38 @@ export const remarkVideoPlugin: Plugin<[VideoConfig?], Root> = (config = {}) => return async (tree: Root) => { const tasks: Array> = []; - // :::video{...} + // :::video{...} syntax visit(tree, 'textDirective', (node: any, index: number | undefined, parent: any) => { if (node.name === 'video' && typeof index === 'number') { - tasks.push((async () => { - const replacement = await processVideoDirectiveAsync(node, defaultOptions); - if (replacement && parent?.children) parent.children[index] = replacement; - })()); + tasks.push(processVideoDirective(node, index, parent, defaultOptions, enableAsync)); } }); - // :::video ... ::: + // :::video ... ::: syntax visit(tree, 'containerDirective', (node: any, index: number | undefined, parent: any) => { if (node.name === 'video' && typeof index === 'number') { - tasks.push((async () => { - const replacement = await processVideoDirectiveAsync(node, defaultOptions); - if (replacement && parent?.children) parent.children[index] = replacement; - })()); + tasks.push(processVideoDirective(node, index, parent, defaultOptions, enableAsync)); } }); - // ![alt](video.mp4 "title") + // ![alt](video.mp4 "title") syntax visit(tree, 'image', (node: any, index: number | undefined, parent: any) => { if (isVideoUrl(node.url) && typeof index === 'number') { - tasks.push((async () => { - const replacement = await processImageAsVideoAsync(node, defaultOptions); - if (replacement && parent?.children) parent.children[index] = replacement; - })()); + tasks.push(processImageAsVideo(node, index, parent, defaultOptions, enableAsync)); } }); - // [Title](video.mp4) + // [Title](video.mp4) syntax visit(tree, 'link', (node: any, index: number | undefined, parent: any) => { if (isVideoUrl(node.url) && typeof index === 'number') { - tasks.push((async () => { - const replacement = await processLinkAsVideoAsync(node, defaultOptions); - if (replacement && parent?.children) parent.children[index] = replacement; - })()); + tasks.push(processLinkAsVideo(node, index, parent, defaultOptions, enableAsync)); } }); - // Raw