// src/utils/remarkVideoPlugin.ts import { visit } from 'unist-util-visit'; import type { Plugin } from 'unified'; import type { Root } from 'hast'; export const remarkVideoPlugin: Plugin<[], Root> = () => { return (tree: Root) => { visit(tree, 'html', (node: any, index: number | undefined, parent: any) => { if (node.value && node.value.includes(' ${title !== 'Video' ? `
${escapeHtml(title)}
` : ''} `.trim(); parent.children[index] = { type: 'html', value: enhancedHTML }; console.log(`[VIDEO] Processed: ${title}`); console.log(`[VIDEO] Final URL: ${finalSrc}`); } } }); }; }; function processNextcloudUrl(originalUrl: string): string { if (isNextcloudShareUrl(originalUrl) && !originalUrl.includes('/download')) { const downloadUrl = `${originalUrl}/download`; console.log(`[VIDEO] Auto-added /download: ${originalUrl} → ${downloadUrl}`); return downloadUrl; } return originalUrl; } function isNextcloudShareUrl(url: string): boolean { const pattern = /\/s\/[a-zA-Z0-9]+/; return pattern.test(url) && (url.includes('nextcloud') || url.includes('cloud.')); } function escapeHtml(unsafe: string): string { if (typeof unsafe !== 'string') return ''; return unsafe .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); }