robots.txt Generator (with more advanced options)

Robots.txt Generator

Robots.txt Generator (Advanced)

Your generated `robots.txt` file is displayed below. Copy the contents and place them in the root directory of your website.


                     
                

Generated on: ${date}

${rtg_escapeHTML(code)}
`; } /** * Generates and downloads a PDF of the output */ async function rtg_downloadPDF() { if (!rtg_codeOutput.textContent || rtg_codeOutput.textContent.trim().length === 0) { alert("Please generate the robots.txt file first."); return; } if (typeof jspdf === 'undefined' || typeof html2canvas === 'undefined') { alert("Error: PDF libraries failed to load."); return; } rtg_renderPdfClone(); const { jsPDF } = window.jspdf; try { const contentDiv = rtg_pdfRenderClone.querySelector('#pdf-code-content'); if (!contentDiv) return; const canvas = await html2canvas(contentDiv, { scale: 1.5, useCORS: true, windowWidth: contentDiv.scrollWidth, windowHeight: contentDiv.scrollHeight }); const imgData = canvas.toDataURL('image/png'); const imgProps = { width: canvas.width, height: canvas.height }; const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const margin = 40; const contentWidth = pdfWidth - (margin * 2); const contentHeight = (contentWidth * imgProps.height) / imgProps.width; let heightLeft = contentHeight; let position = 0; pdf.addImage(imgData, 'PNG', margin, position + margin, contentWidth, contentHeight); heightLeft -= (pdfHeight - margin * 2); while (heightLeft > 0) { position -= (pdfHeight - margin * 2); pdf.addPage(); pdf.addImage(imgData, 'PNG', margin, position + margin, contentWidth, contentHeight); heightLeft -= (pdfHeight - margin * 2); } pdf.save('robots.txt_Generated.pdf'); } catch (error) { console.error("PDF generation failed:", error); alert("An error occurred while generating the PDF."); } } /** * Copies output to clipboard. */ function rtg_copyToClipboard() { if (navigator.clipboard) { navigator.clipboard.writeText(rtg_codeOutput.textContent).then(() => { rtg_copyButton.textContent = 'Copied!'; setTimeout(() => rtg_copyButton.textContent = 'Copy to Clipboard', 1500); }).catch(err => { console.error('Could not copy text: ', err); }); } else { alert('Clipboard access denied. Please copy manually.'); } } // --- EVENT LISTENERS --- // Tab link clicks rtg_tabLinks.forEach((link, index) => { link.addEventListener('click', () => rtg_switchTab(index)); }); // Next/Prev button clicks if (rtg_prevButton) { rtg_prevButton.addEventListener('click', () => { if (rtg_currentTab > 0) rtg_switchTab(rtg_currentTab - 1); }); } if (rtg_nextButton) { rtg_nextButton.addEventListener('click', () => { if (rtg_currentTab === rtg_tabLinks.length - 1) { rtg_updateDataFromConfig(); rtg_switchTab(0); } else { if (rtg_currentTab < rtg_tabLinks.length - 1) rtg_switchTab(rtg_currentTab + 1); } }); } // PDF download if (rtg_downloadPdfButton) { rtg_downloadPdfButton.addEventListener('click', rtg_downloadPDF); } // Copy button if (rtg_copyButton) { rtg_copyButton.addEventListener('click', rtg_copyToClipboard); } // --- Config Tab Listeners --- if (rtg_addGlobalRuleButton) { rtg_addGlobalRuleButton.addEventListener('click', () => { rtg_globalRulesContainer.appendChild(rtg_createRuleInput()); }); } if (rtg_addAgentButton) { rtg_addAgentButton.addEventListener('click', () => { rtg_agentsContainer.appendChild(rtg_createAgentInput({ id: rtg_itemIdCounter++, name: '', rules: [] })); }); } if (rtg_addSitemapButton) { rtg_addSitemapButton.addEventListener('click', () => { rtg_sitemapUrlsContainer.appendChild(rtg_createSitemapInput()); }); } if (rtg_configTab) { // Handle removal and dynamic additions for nested elements rtg_configTab.addEventListener('click', (e) => { const removeRuleButton = e.target.closest('.rtg-remove-item'); const removeAgentButton = e.target.closest('.rtg-remove-agent'); const removeSitemapButton = e.target.closest('.rtg-remove-sitemap'); const addRuleToAgentButton = e.target.closest('.rtg-add-rule-to-agent'); if (removeRuleButton) { removeRuleButton.closest('.flex[data-id]').remove(); } else if (removeAgentButton) { removeAgentButton.closest('.p-4[data-id]').remove(); } else if (removeSitemapButton) { removeSitemapButton.closest('.flex[data-id]').remove(); } else if (addRuleToAgentButton) { const rulesContainer = addRuleToAgentButton.closest('.p-4').querySelector('.rtg-agent-rules-container'); rulesContainer.appendChild(rtg_createRuleInput()); } }); } // --- INITIALIZATION --- rtg_initSampleData(); // Load initial data rtg_renderConfig(); rtg_renderDashboard(); // Render initial state // Set initial tab state rtg_tabPanes.forEach((pane, index) => { pane.classList.toggle('hidden', index !== 0); pane.classList.toggle('rtg-active', index === 0); }); rtg_tabLinks.forEach((link, index) => { TAB_CLASSES.active.forEach(cls => link.classList.remove(cls)); TAB_CLASSES.inactive.forEach(cls => link.classList.remove(cls)); if (index === 0) { TAB_CLASSES.active.forEach(cls => link.classList.add(cls)); } else { TAB_CLASSES.inactive.forEach(cls => link.classList.add(cls)); } }); });
Scroll to Top