From 8a4a4c16a8ae79ec3674e95a5cfae5aa22356d7a Mon Sep 17 00:00:00 2001 From: mgarbs Date: Fri, 14 Feb 2025 12:12:54 -0500 Subject: [PATCH 1/2] hide draft list on idividual hip pages Signed-off-by: mgarbs --- _layouts/default.html | 33 ++++---- assets/js/pr-integration.js | 153 +++++++++++++++++------------------- 2 files changed, 91 insertions(+), 95 deletions(-) diff --git a/_layouts/default.html b/_layouts/default.html index 5ba896c89..fa8d2412f 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -4,21 +4,26 @@ {%- include head.html -%} -{%- include header.html -%} + {%- include header.html -%} -
-
- {{ content }} -
-
+
+
+ {{ content }} +
+
-{%- include footer.html -%} - - - - - - + {%- include footer.html -%} + + + + + + + {% if page.layout == 'page' and page.title == 'HIPs' %} + + + + + {% endif %} - \ No newline at end of file diff --git a/assets/js/pr-integration.js b/assets/js/pr-integration.js index 121f97b6d..6c56a3155 100644 --- a/assets/js/pr-integration.js +++ b/assets/js/pr-integration.js @@ -1,56 +1,72 @@ class HIPPRIntegration { constructor() { - this.initialize(); - this.setupStyles(); + // Only initialize if we're on the hipstable page + if (this.isHipTablePage()) { + this.initialize(); + this.setupStyles(); + } + } + + isHipTablePage() { + // Check if we're on the main HIPs page + return ( + document.querySelector('.hip-filters') !== null || + (window.location.pathname === '/' || + window.location.pathname === '/index.html' || + window.location.pathname.endsWith('/HIPs/')) + ); } setupStyles() { - const styles = ` - .hip-modal { - position: fixed; - top: 0; - left: 0; - width: 100%; - height: 100%; - background: rgba(0, 0, 0, 0.7); - display: flex; - justify-content: center; - align-items: center; - z-index: 1000; - } - .hip-modal-content { - background: white; - padding: 20px; - border-radius: 8px; - max-width: 80%; - max-height: 80vh; - overflow-y: auto; - position: relative; - } - .hip-modal-header { - display: flex; - justify-content: space-between; - align-items: center; - margin-bottom: 20px; - border-bottom: 1px solid #eee; - padding-bottom: 10px; - } - .close-button { - background: none; - border: none; - font-size: 24px; - cursor: pointer; - } - .hip-modal-body { - line-height: 1.6; - } - .hip-modal-body img { - max-width: 100%; - } - `; - const styleSheet = document.createElement('style'); - styleSheet.textContent = styles; - document.head.appendChild(styleSheet); + if (!document.querySelector('#hip-modal-styles')) { + const styles = ` + .hip-modal { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: rgba(0, 0, 0, 0.7); + display: flex; + justify-content: center; + align-items: center; + z-index: 1000; + } + .hip-modal-content { + background: white; + padding: 20px; + border-radius: 8px; + max-width: 80%; + max-height: 80vh; + overflow-y: auto; + position: relative; + } + .hip-modal-header { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 20px; + border-bottom: 1px solid #eee; + padding-bottom: 10px; + } + .close-button { + background: none; + border: none; + font-size: 24px; + cursor: pointer; + } + .hip-modal-body { + line-height: 1.6; + } + .hip-modal-body img { + max-width: 100%; + } + `; + const styleSheet = document.createElement('style'); + styleSheet.id = 'hip-modal-styles'; + styleSheet.textContent = styles; + document.head.appendChild(styleSheet); + } } async initialize() { @@ -69,7 +85,6 @@ class HIPPRIntegration { async fetchPRData() { try { - // Try with site.baseurl if it's set in _config.yml const baseUrl = document.querySelector('meta[name="site-baseurl"]')?.content || ''; const response = await fetch(`${baseUrl}/_data/draft_hips.json`); @@ -94,7 +109,6 @@ class HIPPRIntegration { let bestMetadata = null; let bestFile = null; - // Try all MD files and pick the one with the most complete metadata for (const file of mdFiles) { try { const contentUrl = `https://raw.githubusercontent.com/hashgraph/hedera-improvement-proposal/${pr.headRefOid}/${file.node.path}`; @@ -102,12 +116,10 @@ class HIPPRIntegration { const content = await response.text(); const metadata = this.parseHIPMetadata(content); - // Skip template files and empty metadata if (file.node.path.includes('template') || !metadata.title) { continue; } - // If we don't have metadata yet, or this file has a better title if (!bestMetadata || (metadata.title && metadata.title.length > 3 && (!bestMetadata.title || metadata.title.length > bestMetadata.title.length))) { @@ -119,7 +131,6 @@ class HIPPRIntegration { } } - // If we found valid metadata, add it to the results if (bestMetadata && bestFile) { validHips.push({ pr, @@ -133,29 +144,6 @@ class HIPPRIntegration { return validHips; } - checkForNewHipFormat(content) { - const frontmatterMatch = content.match(/^---\s*\n([\s\S]*?)\n---/); - if (!frontmatterMatch) return false; - - const frontmatter = frontmatterMatch[1].toLowerCase(); - const requiredPatterns = [ - /\btitle\s*:/, - /\bauthor\s*:/, - /\bcategory\s*:/, - /\bcreated\s*:/ - ]; - - return requiredPatterns.every(pattern => pattern.test(frontmatter)); - } - - isValidHIPContent(metadata) { - const essentialFields = ['title', 'type']; - const hasEssentialFields = essentialFields.every(field => metadata[field]); - const desiredFields = ['hip', 'author', 'status', 'created']; - const desiredFieldCount = desiredFields.filter(field => metadata[field]).length; - return hasEssentialFields && desiredFieldCount >= 2; - } - parseHIPMetadata(content) { const frontmatterMatch = content.match(/^---\s*\n([\s\S]*?)\n---/); if (!frontmatterMatch) return {}; @@ -241,8 +229,12 @@ class HIPPRIntegration { tbody.appendChild(row); }); + this.setupTableSorting(table); + } + + setupTableSorting(table) { table.querySelectorAll('th').forEach(header => { - header.addEventListener('click', function () { + header.addEventListener('click', function() { const tbody = table.querySelector('tbody'); const index = Array.from(header.parentNode.children).indexOf(header); const isAscending = header.classList.contains('asc'); @@ -255,21 +247,19 @@ class HIPPRIntegration { let cellB = rowB.querySelectorAll('td')[index].textContent; if (isNumeric && cellA.startsWith('PR-') && cellB.startsWith('PR-')) { - // Extract numbers from PR-XXX format const numA = parseInt(cellA.replace('PR-', '')); const numB = parseInt(cellB.replace('PR-', '')); return (numA - numB) * (isAscending ? 1 : -1); } - // Version sorting logic if (isVersion) { cellA = cellA.replace('v', '').split('.').map(Number); cellB = cellB.replace('v', '').split('.').map(Number); return cellA > cellB ? (isAscending ? 1 : -1) : cellA < cellB ? (isAscending ? -1 : 1) : 0; } - // Default sorting logic - return isNumeric ? (parseFloat(cellA) - parseFloat(cellB)) * (isAscending ? 1 : -1) : cellA.localeCompare(cellB) * (isAscending ? 1 : -1); + return isNumeric ? (parseFloat(cellA) - parseFloat(cellB)) * (isAscending ? 1 : -1) : + cellA.localeCompare(cellB) * (isAscending ? 1 : -1); }) .forEach(tr => tbody.appendChild(tr)); @@ -284,6 +274,7 @@ class HIPPRIntegration { } } +// Initialize when DOM is loaded document.addEventListener('DOMContentLoaded', () => { new HIPPRIntegration(); }); \ No newline at end of file From a2807d5675031df59db533ac89c580c052c8f393 Mon Sep 17 00:00:00 2001 From: mgarbs Date: Tue, 18 Feb 2025 09:07:21 -0500 Subject: [PATCH 2/2] add logging and restriction on path filtering Signed-off-by: mgarbs --- _layouts/default.html | 35 ++++++++++++++++-- assets/js/pr-integration.js | 73 +++++++++++++++++++++++++++++++------ 2 files changed, 93 insertions(+), 15 deletions(-) diff --git a/_layouts/default.html b/_layouts/default.html index fa8d2412f..c3f81d4c2 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -3,7 +3,7 @@ {%- include head.html -%} - + {%- include header.html -%}
@@ -18,12 +18,41 @@ - - {% if page.layout == 'page' and page.title == 'HIPs' %} + + + + + {% if page.layout == 'page' and page.title == 'HIPs' and page.url contains 'index.html' %} + + {% elsif page.layout == 'hip' %} + + {% else %} + {% endif %} \ No newline at end of file diff --git a/assets/js/pr-integration.js b/assets/js/pr-integration.js index 6c56a3155..84e8523c7 100644 --- a/assets/js/pr-integration.js +++ b/assets/js/pr-integration.js @@ -1,20 +1,42 @@ class HIPPRIntegration { constructor() { - // Only initialize if we're on the hipstable page + console.log('Current pathname:', window.location.pathname); + console.log('Has hip-filters:', document.querySelector('.hip-filters') !== null); + console.log('Page layout:', document.querySelector('body').dataset.layout); + + // Check if we're on an individual HIP page + const isHipPage = document.querySelector('.page-heading')?.textContent.includes('HIP-'); + console.log('Is individual HIP page:', isHipPage); + if (this.isHipTablePage()) { + console.log('Initializing HIP PR Integration'); this.initialize(); this.setupStyles(); + } else { + console.log('Skipping HIP PR Integration - not on main page'); } } isHipTablePage() { - // Check if we're on the main HIPs page - return ( - document.querySelector('.hip-filters') !== null || - (window.location.pathname === '/' || - window.location.pathname === '/index.html' || - window.location.pathname.endsWith('/HIPs/')) - ); + // Enhanced page detection + const isMainPage = + window.location.pathname === '/' || + window.location.pathname === '/index.html' || + window.location.pathname.endsWith('/HIPs/') || + window.location.pathname === '/hips/' || + document.querySelector('.hip-filters') !== null; + + const isIndividualHipPage = + document.querySelector('.page-heading')?.textContent.includes('HIP-') || + document.querySelector('body').dataset.layout === 'hip'; + + console.log('Page detection:', { + isMainPage, + isIndividualHipPage, + pathname: window.location.pathname + }); + + return isMainPage && !isIndividualHipPage; } setupStyles() { @@ -71,10 +93,13 @@ class HIPPRIntegration { async initialize() { try { + console.log('Starting initialization'); const prData = await this.fetchPRData(); if (prData) { + console.log('Fetched PR data successfully'); const validHips = await this.filterHIPPRs(prData); if (validHips.length > 0) { + console.log(`Found ${validHips.length} valid HIPs`); this.addHIPsToTable(validHips); } } @@ -86,6 +111,7 @@ class HIPPRIntegration { async fetchPRData() { try { const baseUrl = document.querySelector('meta[name="site-baseurl"]')?.content || ''; + console.log('Fetching PR data from baseUrl:', baseUrl); const response = await fetch(`${baseUrl}/_data/draft_hips.json`); if (!response.ok) { @@ -144,6 +170,21 @@ class HIPPRIntegration { return validHips; } + checkForNewHipFormat(content) { + const frontmatterMatch = content.match(/^---\s*\n([\s\S]*?)\n---/); + if (!frontmatterMatch) return false; + + const frontmatter = frontmatterMatch[1].toLowerCase(); + const requiredPatterns = [ + /\btitle\s*:/, + /\bauthor\s*:/, + /\bcategory\s*:/, + /\bcreated\s*:/ + ]; + + return requiredPatterns.every(pattern => pattern.test(frontmatter)); + } + parseHIPMetadata(content) { const frontmatterMatch = content.match(/^---\s*\n([\s\S]*?)\n---/); if (!frontmatterMatch) return {}; @@ -163,8 +204,12 @@ class HIPPRIntegration { } addHIPsToTable(hips) { + console.log('Adding HIPs to table'); const wrapper = document.querySelector('main .wrapper'); - if (!wrapper) return; + if (!wrapper) { + console.error('Could not find wrapper element'); + return; + } const lastStatusSection = wrapper.lastElementChild; const draftContainer = document.createElement('div'); @@ -230,6 +275,7 @@ class HIPPRIntegration { }); this.setupTableSorting(table); + console.log('Finished adding HIPs to table'); } setupTableSorting(table) { @@ -258,8 +304,9 @@ class HIPPRIntegration { return cellA > cellB ? (isAscending ? 1 : -1) : cellA < cellB ? (isAscending ? -1 : 1) : 0; } - return isNumeric ? (parseFloat(cellA) - parseFloat(cellB)) * (isAscending ? 1 : -1) : - cellA.localeCompare(cellB) * (isAscending ? 1 : -1); + return isNumeric ? + (parseFloat(cellA) - parseFloat(cellB)) * (isAscending ? 1 : -1) : + cellA.localeCompare(cellB) * (isAscending ? 1 : -1); }) .forEach(tr => tbody.appendChild(tr)); @@ -274,7 +321,9 @@ class HIPPRIntegration { } } -// Initialize when DOM is loaded +// Add debugging information about script loading +console.log('PR Integration script loaded at:', new Date().toISOString()); document.addEventListener('DOMContentLoaded', () => { + console.log('DOM Content Loaded - initializing HIPPRIntegration'); new HIPPRIntegration(); }); \ No newline at end of file