Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide draft list on idividual hip pages #1123

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@
{%- include head.html -%}

<body>
{%- include header.html -%}
{%- include header.html -%}

<main class="page-content" aria-label="Content">
<div class="wrapper">
{{ content }}
</div>
</main>
<main class="page-content" aria-label="Content">
<div class="wrapper">
{{ content }}
</div>
</main>

{%- include footer.html -%}
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="{{ '/assets/js/tooltip.js' | relative_url }}"></script>
<script src="{{ '/assets/js/hipstable.js' | relative_url }}"></script>
<script src="{{ '/assets/js/filter.js' | relative_url }}"></script>
<script src="{{ '/assets/js/pr-integration.js' | relative_url }}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
{%- include footer.html -%}

<!-- Core Scripts -->
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="{{ '/assets/js/tooltip.js' | relative_url }}"></script>

<!-- Only include hipstable-related scripts on the main HIPs page -->
{% if page.layout == 'page' and page.title == 'HIPs' %}
<script src="{{ '/assets/js/hipstable.js' | relative_url }}"></script>
<script src="{{ '/assets/js/filter.js' | relative_url }}"></script>
<script src="{{ '/assets/js/pr-integration.js' | relative_url }}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
{% endif %}
</body>

</html>
153 changes: 72 additions & 81 deletions assets/js/pr-integration.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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`);

Expand All @@ -94,20 +109,17 @@ 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}`;
const response = await fetch(contentUrl);
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))) {
Expand All @@ -119,7 +131,6 @@ class HIPPRIntegration {
}
}

// If we found valid metadata, add it to the results
if (bestMetadata && bestFile) {
validHips.push({
pr,
Expand All @@ -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 {};
Expand Down Expand Up @@ -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');
Expand All @@ -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));

Expand All @@ -284,6 +274,7 @@ class HIPPRIntegration {
}
}

// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
new HIPPRIntegration();
});
Loading