consolidation

This commit is contained in:
overcuriousity
2025-07-25 12:23:56 +02:00
parent 1e7c1a2468
commit b7fea4f31f
6 changed files with 138 additions and 51 deletions

View File

@@ -1,4 +1,6 @@
---
import { createToolSlug } from '../utils/toolHelpers.js';
export interface Props {
toolName: string;
context: 'card' | 'modal-primary' | 'modal-secondary';
@@ -7,12 +9,8 @@ export interface Props {
const { toolName, context, size = 'small' } = Astro.props;
// Create URL-safe slug from tool name
const toolSlug = 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
// AFTER: Single line with centralized function
const toolSlug = createToolSlug(toolName);
const iconSize = size === 'small' ? '14' : '16';
---

View File

@@ -286,26 +286,12 @@ domains.forEach((domain: any) => {
// ===== SHARING FUNCTIONALITY =====
// Create tool slug from name (same logic as ShareButton.astro)
function createToolSlug(toolName) {
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
}
// Find tool by name or slug
function findTool(identifier) {
return toolsData.find(tool =>
tool.name === identifier ||
createToolSlug(tool.name) === identifier.toLowerCase()
);
}
// REMOVED: createToolSlug function - now using window.createToolSlug
// REMOVED: findTool function - now using window.findToolByIdentifier
// Generate share URLs
function generateShareURL(toolName, view, modal = null) {
const toolSlug = createToolSlug(toolName);
const toolSlug = window.createToolSlug(toolName);
const baseUrl = window.location.origin + window.location.pathname;
const params = new URLSearchParams();
params.set('tool', toolSlug);
@@ -517,10 +503,7 @@ domains.forEach((domain: any) => {
elements.description.textContent = tool.description;
// Badges
const hasValidProjectUrl = tool.projectUrl !== undefined &&
tool.projectUrl !== null &&
tool.projectUrl !== "" &&
tool.projectUrl.trim() !== "";
const hasValidProjectUrl = window.isToolHosted(tool);
elements.badges.innerHTML = '';
if (isConcept) {
@@ -645,7 +628,7 @@ domains.forEach((domain: any) => {
}
if (tool.knowledgebase === true) {
const kbId = tool.name.toLowerCase().replace(/\s+/g, '-');
const kbId = window.createToolSlug(tool.name);
linksHTML += `
<a href="/knowledgebase#kb-${kbId}" class="btn btn-secondary" style="width: 100%; margin-top: 0.5rem;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="margin-right: 0.5rem;">
@@ -665,7 +648,7 @@ domains.forEach((domain: any) => {
// ===== POPULATE SHARE BUTTON =====
const shareButtonContainer = document.getElementById(`share-button-${modalType}`);
if (shareButtonContainer) {
const toolSlug = createToolSlug(tool.name);
const toolSlug = window.createToolSlug(tool.name);
shareButtonContainer.innerHTML = `
<button class="share-btn share-btn--medium"
data-tool-name="${tool.name}"
@@ -822,10 +805,7 @@ domains.forEach((domain: any) => {
}
const isMethod = tool.type === 'method';
const hasValidProjectUrl = tool.projectUrl !== undefined &&
tool.projectUrl !== null &&
tool.projectUrl !== "" &&
tool.projectUrl.trim() !== "";
const hasValidProjectUrl = window.isToolHosted(tool);
const domains = tool.domains || [];
const phases = tool.phases || [];