/** * blog-search.js - Logic for real-time article filtering and dropdown results * Updated to support unified site-wide searching (Blogs + Services/Abilities + Pages) */ // 1. Static site-wide Pages & Services (Abilities) Dataset const ADDITIONAL_SEARCH_DATA = [ // --- Services / Abilities --- { title: "Amazon Account Launch & Registration", excerpt: "Launch and register your Amazon seller account with professional setup and configuration.", type: "service", url: "../services/amazon-account-launch.php", tags: ["Amazon", "Launch", "Registration", "Onboarding"] }, { title: "Amazon Product Listing Services", excerpt: "Professional Amazon product listing and SEO optimization to improve visibility and sales.", type: "service", url: "../services/amazon-product-listing.php", tags: ["Amazon", "Listing", "SEO", "Optimization"] }, { title: "Amazon Brand & Product-Specific Videos", excerpt: "High-quality product and brand videos for Amazon listings to boost conversion rates.", type: "service", url: "../services/amazon-brand-product-videos.php", tags: ["Amazon", "Videos", "Brand", "Product Video"] }, { title: "A+ Content (Enhanced Brand Content)", excerpt: "Create beautiful Amazon A+ Content and premium product descriptions.", type: "service", url: "../services/aplus-content-services.php", tags: ["Amazon", "A+", "EBC", "Enhanced Brand Content"] }, { title: "Amazon Advertising (PPC) Services", excerpt: "Optimize and manage your Amazon Pay-Per-Click campaigns to maximize ROI.", type: "service", url: "../services/amazon-advertising-services.php", tags: ["Amazon", "PPC", "Advertising", "Ads"] }, { title: "Amazon Account Management", excerpt: "Full-service management for your Amazon store, including inventory, health, and growth.", type: "service", url: "../services/amazon-account-management.php", tags: ["Amazon", "Management", "Account Manager"] }, { title: "Amazon Account Reinstatement", excerpt: "Get your suspended Amazon seller account or listing reinstated quickly.", type: "service", url: "../services/amazon-account-reinstatement.php", tags: ["Amazon", "Reinstatement", "Suspended", "Appeals"] }, { title: "Flipkart Seller Services & Registration", excerpt: "Register and launch your store on Flipkart with professional setup.", type: "service", url: "../services/flipkart-seller-services.php", tags: ["Flipkart", "Launch", "Registration", "Onboarding"] }, { title: "Flipkart Account Management", excerpt: "End-to-end account management, performance monitoring, and growth strategies on Flipkart.", type: "service", url: "../services/flipkart-account-management.php", tags: ["Flipkart", "Management", "Account Manager"] }, { title: "Flipkart RPD (Return Pickup Dispute)", excerpt: "Manage and resolve return pickup disputes on Flipkart to save costs.", type: "service", url: "../services/flipkart-rpd-services.php", tags: ["Flipkart", "RPD", "Disputes", "Returns"] }, { title: "Flipkart Advertising Services", excerpt: "Professional Flipkart product advertising and campaigns to boost visibility.", type: "service", url: "../services/flipkart-advertising-services.php", tags: ["Flipkart", "Advertising", "PPC", "Ads"] }, { title: "JioMart Seller Services", excerpt: "Onboarding, product cataloging, and store optimization for JioMart sellers.", type: "service", url: "../services/jiomart-services.php", tags: ["JioMart", "Seller", "Onboarding"] }, { title: "Meesho Seller Services", excerpt: "Meesho seller registration, product uploads, listing optimization, and order management.", type: "service", url: "../services/meesho-services.php", tags: ["Meesho", "Seller", "Listing"] }, { title: "Myntra Seller Services", excerpt: "Grow your fashion brand on Myntra with cataloging and store management.", type: "service", url: "../services/Myntra-Seller-Services.php", tags: ["Myntra", "Seller", "Fashion", "Listing"] }, { title: "Ajio Seller Services", excerpt: "Get your brand registered and listed on Ajio with our specialized cataloging.", type: "service", url: "../services/Ajio-Seller-Services.php", tags: ["Ajio", "Seller", "Cataloging"] }, { title: "Nykaa Seller Services", excerpt: "Professional seller solutions, registration, and product listing on Nykaa.", type: "service", url: "../services/Nayaka-Seller-Services.php", tags: ["Nykaa", "Beauty", "Seller", "Listing"] }, { title: "Blinkit Seller Services", excerpt: "List and scale your fast-moving products on Blinkit quick commerce.", type: "service", url: "../services/Blinkit.php", tags: ["Blinkit", "Quick Commerce", "Q-Commerce", "Instant Delivery"] }, { title: "Zepto Seller Services", excerpt: "Get your products onboarding and managed on Zepto quick-delivery platform.", type: "service", url: "../services/Zepto.php", tags: ["Zepto", "Quick Commerce", "Q-Commerce", "Instant Delivery"] }, { title: "Swiggy Instamart Services", excerpt: "Onboard and optimize your catalog on Swiggy Instamart for instant sales.", type: "service", url: "../services/Instamart.php", tags: ["Instamart", "Swiggy", "Quick Commerce", "Q-Commerce"] }, { title: "BigBasket Seller Services", excerpt: "Professional cataloging and store management services for BigBasket.", type: "service", url: "../services/BigBasket.php", tags: ["BigBasket", "Grocery", "Seller"] }, { title: "Amazon Fresh Services", excerpt: "Expand your grocery business with Amazon Fresh listing and management.", type: "service", url: "../services/Amazon-now.php", tags: ["Amazon Fresh", "Grocery", "Seller", "Now"] }, { title: "Flipkart Minute Services", excerpt: "List and optimize your items on Flipkart Minute instant delivery service.", type: "service", url: "../services/Flipkart-Minute.php", tags: ["Flipkart Minute", "Quick Commerce", "Q-Commerce"] }, { title: "Cataloging Services", excerpt: "Professional cataloging, photoshoot, and listing services for top e-commerce websites.", type: "service", url: "../services/cataloging-services.php", tags: ["Cataloging", "Photoshoot", "Listing"] }, { title: "GST Registration & Compliance", excerpt: "Get new GST registration, legal filings, and complete e-commerce tax compliance.", type: "service", url: "../services/gst-registration-services.php", tags: ["GST", "Tax", "Legal", "Compliance", "Filing"] }, { title: "Company Registration & Incorporation", excerpt: "Incorporate Private Limited, LLP, One Person Company, or Partnership easily.", type: "service", url: "../services/company-registration-services.php", tags: ["Company", "Incorporation", "Legal", "Partnership", "LLP"] }, { title: "Trademark Registration & IP", excerpt: "Secure your brand name, logo, and intellectual property with trademark filing.", type: "service", url: "../services/trademark-registration-services.php", tags: ["Trademark", "Legal", "IP", "Brand", "Copyright"] }, { title: "FSSAI Registration & Food License", excerpt: "Obtain FSSAI food license for food-related e-commerce or retail operations.", type: "service", url: "../services/fssai-registration-services.php", tags: ["FSSAI", "Legal", "Food License", "Safety"] }, { title: "MSME Udyam Registration", excerpt: "Register your business as an MSME to access government benefits and subsidies.", type: "service", url: "../services/udyam-registration-services.php", tags: ["MSME", "Udyam", "Legal", "Registration", "Micro"] }, // --- Pages --- { title: "Home - Digitalsbooster", excerpt: "We provide e-commerce account management, cataloging, marketplace advertising, and legal registration services.", type: "page", url: "../index.php", tags: ["Home", "Digitalsbooster", "E-commerce", "Growth"] }, { title: "About Us - Who We Are", excerpt: "Learn about Digitalsbooster's mission, vision, and how we help brands scale across online marketplaces.", type: "page", url: "../company/about-us.php", tags: ["About Us", "Company", "Mission", "Vision"] }, { title: "Our Team", excerpt: "Meet our passionate team of e-commerce specialists, digital marketers, and legal compliance experts.", type: "page", url: "../company/our-team.php", tags: ["Team", "Company", "Experts", "Staff"] }, { title: "Frequently Asked Questions (FAQs)", excerpt: "Find quick answers regarding e-commerce onboarding, account management, legal compliance, and pricing.", type: "page", url: "../company/faqs.php", tags: ["FAQs", "Company", "Help", "Support", "Questions"] }, { title: "Clients & Partners", excerpt: "Discover the brands that have scaled their digital sales and reached millions of customers with Digitalsbooster.", type: "page", url: "../company/clients.php", tags: ["Clients", "Company", "Success Stories", "Partners", "Brands"] }, { title: "Careers at Digitalsbooster", excerpt: "Join a fast-growing, innovative team of e-commerce specialists and tech enthusiasts.", type: "page", url: "../company/career.php", tags: ["Career", "Company", "Jobs", "Hiring", "Work"] }, { title: "Contact Us", excerpt: "Get in touch with Digitalsbooster for a free consultation or custom quotes.", type: "page", url: "../contact-us.php", tags: ["Contact Us", "Help", "Talk", "Support", "Enquiry", "Email"] } ]; // Helper to determine depth and calculate prefix to Digitalsbooster root const getRelativePrefix = () => { const loc = window.location.pathname; if (loc.match(/\/blogs\/post/i)) { return '../../'; } if (loc.match(/\/(blogs|company|services)/i)) { return '../'; } return ''; }; // Compile dynamic blog posts + static services & pages const getCombinedDataset = (blogData) => { const blogs = (blogData || []).map(b => ({ ...b, type: 'blog' })); const prefix = getRelativePrefix(); const pagesAndServices = ADDITIONAL_SEARCH_DATA.map(item => ({ ...item, resolvedUrl: prefix + item.url.replace(/^\.\.\//, '') })); return [...blogs, ...pagesAndServices]; }; // 2. Core Data Helpers (Exposed for Dashboard reuse) window.BlogSearchHelpers = { getImgUrl: (path) => { if (!path) return '../assets/images/placeholder.png'; if (path.startsWith('http://') || path.startsWith('https:///')) return path; // If it's already resolved (starts with relative dots or matches correct folder structure), return as is if (path.startsWith('.') || path.includes('dashboard/index.html')) return path; // Otherwise, clean and resolve relative path prefix let cleanPath = path.replace(/^(\.\.\/)+/, '').replace(/^\//, ''); if (cleanPath.startsWith('dashboard/')) { cleanPath = 'blogs/' + cleanPath; } const prefix = getRelativePrefix(); return prefix + cleanPath; }, parseTags: (tagData) => { if (!tagData) return []; try { if (typeof tagData === 'string' && tagData.startsWith('[')) return JSON.parse(tagData); if (typeof tagData === 'string') return tagData.split(',').map(t => t.trim()).filter(t => t !== ''); if (Array.isArray(tagData)) return tagData; } catch (e) { console.error("Error parsing tags:", e); } return []; }, // Unified filter logic covering title, excerpt, full body/content, tags, and authors filterData: (data, searchTerm) => { if (!searchTerm) return []; const term = searchTerm.toLowerCase().trim(); const unifiedDataset = getCombinedDataset(data); return unifiedDataset.filter(item => { if (!item) return false; const titleMatch = (item.title || '').toString().toLowerCase().includes(term); const excerptMatch = (item.excerpt || '').toString().toLowerCase().includes(term); const contentMatch = (item.content || item.body || '').toString().toLowerCase().includes(term); const authorMatch = (item.author_name || item.author || '').toString().toLowerCase().includes(term); const tags = window.BlogSearchHelpers.parseTags(item.tags || item.category); const tagMatch = tags.some(tag => tag && tag.toString().toLowerCase().includes(term)); return titleMatch || excerptMatch || contentMatch || authorMatch || tagMatch; }); } }; document.addEventListener('DOMContentLoaded', () => { // Initialize Search Instances const setupSearch = (inputId, dropdownId, blogsOnly = false) => { const input = document.getElementById(inputId); const dropdown = document.getElementById(dropdownId); if (!input || !dropdown) return; input.addEventListener('input', (e) => { const searchTerm = e.target.value; const data = window.BLOG_DATA || (typeof BLOG_DATA !== 'undefined' ? BLOG_DATA : []); console.log("Search term:", searchTerm); console.log("Data source (window.BLOG_DATA):", data); if (searchTerm.trim().length < 1) { dropdown.innerHTML = ''; dropdown.style.display = 'none'; return; } let filteredResults = window.BlogSearchHelpers.filterData(data, searchTerm); if (blogsOnly) { filteredResults = filteredResults.filter(item => item.type === 'blog'); } console.log("Filtered results matching query:", filteredResults); renderDropdown(filteredResults, dropdown); }); input.addEventListener('click', () => { if (input.value.length >= 1 && dropdown.innerHTML !== '') { dropdown.style.display = 'block'; } }); // Close dropdown when clicking outside specific instance document.addEventListener('click', (e) => { if (!input.contains(e.target) && !dropdown.contains(e.target)) { dropdown.style.display = 'none'; } }); }; const renderDropdown = (results, dropdown) => { if (results.length === 0) { dropdown.innerHTML = '