consolidation

This commit is contained in:
overcuriousity 2025-07-25 12:48:06 +02:00
parent b7fea4f31f
commit bd7f93167c
5 changed files with 32 additions and 56 deletions

View File

@ -616,7 +616,7 @@ document.addEventListener('DOMContentLoaded', () => {
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="margin-right: 0.5rem; vertical-align: middle;"> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="margin-right: 0.5rem; vertical-align: middle;">
<path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/> <path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/>
</svg> </svg>
Passende Tool-Empfehlungen Passende Empfehlungen
</h3> </h3>
<p style="margin: 0; opacity: 0.9; line-height: 1.5;"> <p style="margin: 0; opacity: 0.9; line-height: 1.5;">
Basierend auf Ihrer Anfrage: "<em>${originalQuery.slice(0, 100)}${originalQuery.length > 100 ? '...' : ''}</em>" Basierend auf Ihrer Anfrage: "<em>${originalQuery.slice(0, 100)}${originalQuery.length > 100 ? '...' : ''}</em>"

5
src/env.d.ts vendored
View File

@ -18,6 +18,11 @@ declare global {
switchToAIView?: () => void; switchToAIView?: () => void;
clearTagFilters?: () => void; clearTagFilters?: () => void;
clearAllFilters?: () => void; clearAllFilters?: () => void;
// CONSOLIDATED: Tool utility functions
createToolSlug: (toolName: string) => string;
findToolByIdentifier: (tools: any[], identifier: string) => any | undefined;
isToolHosted: (tool: any) => boolean;
} }
} }

View File

@ -23,8 +23,8 @@ const { title, description = 'CC24-Guide - A comprehensive directory of digital
<!-- CONSOLIDATED: Load theme script --> <!-- CONSOLIDATED: Load theme script -->
<script src="/src/scripts/theme.js"></script> <script src="/src/scripts/theme.js"></script>
<!-- CONSOLIDATED: Load tool utilities --> <!-- CONSOLIDATED: Load tool utilities (now from enhanced TypeScript file) -->
<script src="/src/scripts/tool-utils.js"></script> <script src="/src/utils/toolHelpers.ts"></script>
<!-- CONSOLIDATED: Load client-side auth utilities --> <!-- CONSOLIDATED: Load client-side auth utilities -->
<script src="/src/scripts/client-auth.js"></script> <script src="/src/scripts/client-auth.js"></script>

View File

@ -1,52 +0,0 @@
// Client-side tool utilities
// Mirrors server-side function logic for consistency
/**
* Creates a URL-safe slug from a tool name (client-side version)
*/
function createToolSlug(toolName) {
if (!toolName || typeof toolName !== 'string') {
console.warn('[toolUtils] Invalid toolName provided:', toolName);
return '';
}
return toolName.toLowerCase()
.replace(/[^a-z0-9\s-]/g, '') // Remove special characters
.replace(/\s+/g, '-') // Replace spaces with hyphens
.replace(/-+/g, '-') // Remove duplicate hyphens
.replace(/^-|-$/g, ''); // Remove leading/trailing hyphens
}
/**
* Finds a tool by name or slug from tools array (client-side version)
*/
function findToolByIdentifier(tools, identifier) {
if (!identifier || !Array.isArray(tools)) return undefined;
return tools.find(tool =>
tool.name === identifier ||
createToolSlug(tool.name) === identifier.toLowerCase()
);
}
/**
* Checks if tool has a valid project URL (hosted on CC24 server)
*/
function isToolHosted(tool) {
return tool.projectUrl !== undefined &&
tool.projectUrl !== null &&
tool.projectUrl !== "" &&
tool.projectUrl.trim() !== "";
}
// Make functions available globally for existing code compatibility
window.createToolSlug = createToolSlug;
window.findToolByIdentifier = findToolByIdentifier;
window.isToolHosted = isToolHosted;
// Export for module usage
if (typeof module !== 'undefined' && module.exports) {
module.exports = { createToolSlug, findToolByIdentifier, isToolHosted };
}
console.log('Tool utilities loaded');

View File

@ -1,5 +1,6 @@
/** /**
* Tool utility functions for consistent tool operations across the app * CONSOLIDATED Tool utility functions for consistent tool operations across the app
* Works in both server (Node.js) and client (browser) environments
*/ */
export interface Tool { export interface Tool {
@ -66,3 +67,25 @@ export function getToolCategory(tool: Tool): 'concept' | 'method' | 'hosted' | '
if (tool.license && tool.license !== 'Proprietary') return 'oss'; if (tool.license && tool.license !== 'Proprietary') return 'oss';
return 'proprietary'; return 'proprietary';
} }
// BROWSER COMPATIBILITY LAYER
// Only assign to window if we're in a browser environment
if (typeof window !== 'undefined') {
// Make functions available globally for existing code compatibility
window.createToolSlug = createToolSlug;
window.findToolByIdentifier = findToolByIdentifier;
window.isToolHosted = isToolHosted;
console.log('[toolHelpers] Consolidated tool utilities loaded and assigned to window');
}
// LEGACY NODE.JS COMPATIBILITY
// Support for older require() patterns if needed
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
createToolSlug,
findToolByIdentifier,
isToolHosted,
getToolCategory
};
}