Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
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
Binary file modified psi-document/sdrf-proteomics-specification-v1.1.0-dev.pdf
Binary file not shown.
33 changes: 20 additions & 13 deletions scripts/inject-headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def inject_header(filepath: str, header_html: str, is_dev: bool = False) -> None
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()

# Resolve version link based on dev/stable mode
# Resolve version link: only show in dev builds (link back to stable)
if is_dev:
version_link = '<a href="/" class="version-link">Stable Version</a>'
else:
version_link = '<a href="/dev/" class="version-link">Dev Version</a>'
version_link = ''
resolved_header = header_html.replace(VERSION_LINK_PLACEHOLDER, version_link)
Comment on lines +41 to 46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid hard-coding the Stable Version link to "/".

Every other nav URL in this script is relative, but these two injections jump to the domain root. That breaks the version switch when the docs are served from a project subpath or opened from a generated local build. Please derive the stable target from the deployment base/page depth instead of baking in "/".

Also applies to: 71-76

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/inject-headers.py` around lines 41 - 46, The Stable Version link is
hard-coded to "/" which breaks docs served from subpaths; replace that literal
with a computed stable target derived from the deployment base or page depth
(e.g., compute a relative base like "../" repeated page_depth or use an existing
deployment_base variable if present) and use that value when building
version_link instead of "/". Update the block that sets version_link (refer to
is_dev, VERSION_LINK_PLACEHOLDER, header_html, resolved_header) to compute
stable_target = computed_base + maybe "index.html" or root of the docs site and
then set version_link = f'<a href="{stable_target}" class="version-link">Stable
Version</a>'; apply the same change to the analogous footer/footer injection
code around lines 71-76 so both injections derive the stable URL the same way.


# Add has-doc-header class to body
Expand All @@ -56,17 +56,24 @@ def inject_header(filepath: str, header_html: str, is_dev: bool = False) -> None
f.write(content)


def rewrite_version_links(filepath: str, is_dev: bool) -> None:
"""Rewrite version links in static HTML pages (index.html, quickstart.html, etc.)."""
def inject_version_link_into_static(filepath: str, is_dev: bool) -> None:
"""Inject a 'Stable Version' link into static HTML pages for dev builds."""
if not is_dev:
return # Stable builds don't show a version link

with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()

if is_dev:
content = content.replace(
'<a href="/dev/" class="version-link">Dev Version</a>',
'<a href="/" class="version-link">Stable Version</a>'
)
# No change needed for stable — the source files already have /dev/ links
# Already has a version link — skip
if 'class="version-link"' in content:
return

# Insert "Stable Version" link before the GitHub link
stable_link = '<a href="/" class="version-link">Stable Version</a>'
content = content.replace(
'<a href="https://github.com/bigbio/proteomics-metadata-standard"',
stable_link + '<a href="https://github.com/bigbio/proteomics-metadata-standard"'
)

with open(filepath, 'w', encoding='utf-8') as f:
f.write(content)
Expand Down Expand Up @@ -120,13 +127,13 @@ def main():
print(f"Injecting header into: {html_file}")
inject_header(str(html_file), HEADERS['templates'], is_dev)

# Rewrite version links in static HTML pages (index.html, quickstart.html, etc.)
# Inject version link into static HTML pages for dev builds
for static_page in ["index.html", "quickstart.html", "sdrf-terms.html",
"sdrf-explorer.html", "sdrf-editor.html", "sdrf-builder.html"]:
static_file = output_dir / static_page
if static_file.exists():
print(f"Rewriting version links in: {static_file}")
rewrite_version_links(str(static_file), is_dev)
print(f"Processing version link in: {static_file}")
inject_version_link_into_static(str(static_file), is_dev)

print("Header injection complete!")

Expand Down
35 changes: 29 additions & 6 deletions site/js/sdrf-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
affinitySubtype: null,
extraColumns: [], // columns from sdrf-terms.tsv added by user
addedOptionals: [], // optional template columns the user opted into
removedColumns: [], // recommended columns the user explicitly removed
factorValues: [] // characteristics chosen as factor values
};

Expand Down Expand Up @@ -180,6 +181,9 @@
if (req === 'optional') {
// Only include if user explicitly added it
if (state.addedOptionals.indexOf(colName) === -1) continue;
} else if (req === 'recommended') {
// Exclude if user explicitly removed it
if (state.removedColumns.indexOf(colName) !== -1) continue;
}
result.push(col2);
}
Expand Down Expand Up @@ -380,6 +384,7 @@
state.experiments = [];
state.affinitySubtype = null;
state.addedOptionals = [];
state.removedColumns = [];
state.extraColumns = [];
state.factorValues = [];

Expand Down Expand Up @@ -608,8 +613,9 @@
continue;
}

if (req === 'optional' && !includedNames[colName]) {
// Optional and not enabled -> goes in "optional" section
if ((req === 'optional' && !includedNames[colName]) ||
(req === 'recommended' && state.removedColumns.indexOf(colName) !== -1)) {
// Optional not enabled, or recommended that user removed -> "optional" section
optionalCols.push(col);
} else if (includedNames[colName] && state.extraColumns.indexOf(colName) === -1) {
// Included from template (not user-added extra)
Expand Down Expand Up @@ -734,7 +740,14 @@
item.appendChild(toggleBtn);

item.addEventListener('click', function () {
state.addedOptionals.push(col.name);
var req = col.requirement || 'optional';
if (req === 'recommended') {
// Re-add: remove from removedColumns
var idx = state.removedColumns.indexOf(col.name);
if (idx !== -1) state.removedColumns.splice(idx, 1);
} else {
state.addedOptionals.push(col.name);
}
updatePreview();
});
optDiv.appendChild(item);
Expand Down Expand Up @@ -844,6 +857,11 @@
// Remove from extra
var idx = state.extraColumns.indexOf(colName);
if (idx !== -1) state.extraColumns.splice(idx, 1);
} else if (col.requirement === 'recommended') {
// Move recommended column to removed list
if (state.removedColumns.indexOf(colName) === -1) {
state.removedColumns.push(colName);
}
} else {
// Toggle optional template column off (remove from addedOptionals)
var idx2 = state.addedOptionals.indexOf(colName);
Expand Down Expand Up @@ -896,11 +914,16 @@
var columns = resolveColumns();
if (!columns.length) return;

var names = [];
var headers = [];
var values = [];
for (var i = 0; i < columns.length; i++) {
names.push(columns[i].name);
headers.push(columns[i].name);
values.push(columns[i].example_value || '');
}
window.open('sdrf-editor.html?columns=' + encodeURIComponent(names.join(',')));

var tsv = headers.join('\t') + '\n' + values.join('\t') + '\n';
var encoded = btoa(unescape(encodeURIComponent(tsv)));
window.open('sdrf-editor.html?content=' + encodeURIComponent(encoded));
}

/* ---------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion site/quickstart.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
<a href="./sdrf-explorer.html">Explorer</a>
<a href="./sdrf-editor.html">Editor</a>
<a href="./quickstart.html" class="nav-current">Quick Start</a>
<a href="/dev/" class="version-link">Dev Version</a>
<a href="https://github.com/bigbio/proteomics-metadata-standard" target="_blank">GitHub</a>
</nav>
</div>
Expand Down
1 change: 0 additions & 1 deletion site/sdrf-builder.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<a href="./index.html#tools">Tools</a>
<a href="./sdrf-explorer.html">Explorer</a>
<a href="./sdrf-editor.html">Editor</a>
<a href="/dev/" class="version-link">Dev Version</a>
<a href="https://github.com/bigbio/proteomics-metadata-standard" target="_blank">GitHub</a>
</nav>
</div>
Expand Down
Loading