-
Notifications
You must be signed in to change notification settings - Fork 116
Minor changes in the html web page. #806
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
Changes from all commits
26a7ed8
59a0585
e93e4be
c9192d2
69bc0bc
f7934d8
4f66212
b5e109c
c180dd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,82 +14,119 @@ | |
| from pathlib import Path | ||
|
|
||
|
|
||
| # Navigation header templates | ||
| # Version link placeholder — replaced at build time based on --dev flag | ||
| VERSION_LINK_PLACEHOLDER = '{{VERSION_LINK}}' | ||
|
|
||
| # Navigation header templates (use placeholder for version link) | ||
| HEADERS = { | ||
| 'root': '''<header class="doc-header"><div class="doc-header-brand"><a href="./index.html">SDRF-Proteomics</a></div><nav class="doc-header-nav"><a href="./index.html">Home</a><a href="./specification.html" class="nav-current">Specification</a><a href="./index.html#metadata-guidelines">Metadata Guidelines</a><a href="./index.html#templates">Templates</a><a href="./index.html#tools">Tools</a><a href="./sdrf-explorer.html">Explorer</a><a href="./sdrf-editor.html">Editor</a><a href="./index.html#contributors">Contributors</a><a href="/dev/" class="version-link">Dev Version</a><a href="https://github.com/bigbio/proteomics-metadata-standard" target="_blank">GitHub</a></nav></header>''', | ||
| 'root': f'''<header class="doc-header"><div class="doc-header-brand"><a href="./index.html">SDRF-Proteomics</a></div><nav class="doc-header-nav"><a href="./index.html">Home</a><a href="./specification.html" class="nav-current">Specification</a><a href="./index.html#metadata-guidelines">Metadata Guidelines</a><a href="./index.html#templates">Templates</a><a href="./index.html#tools">Tools</a><a href="./sdrf-explorer.html">Explorer</a><a href="./sdrf-editor.html">Editor</a><a href="./sdrf-builder.html">Template Builder</a><a href="./index.html#contributors">Contributors</a>{VERSION_LINK_PLACEHOLDER}<a href="https://github.com/bigbio/proteomics-metadata-standard" target="_blank">GitHub</a></nav></header>''', | ||
|
|
||
| 'tools': '''<header class="doc-header"><div class="doc-header-brand"><a href="./index.html">SDRF-Proteomics</a></div><nav class="doc-header-nav"><a href="./index.html">Home</a><a href="./specification.html">Specification</a><a href="./index.html#metadata-guidelines">Metadata Guidelines</a><a href="./index.html#templates">Templates</a><a href="./index.html#tools" class="nav-current">Tools</a><a href="./sdrf-explorer.html">Explorer</a><a href="./sdrf-editor.html">Editor</a><a href="./index.html#contributors">Contributors</a><a href="/dev/" class="version-link">Dev Version</a><a href="https://github.com/bigbio/proteomics-metadata-standard" target="_blank">GitHub</a></nav></header>''', | ||
| 'tools': f'''<header class="doc-header"><div class="doc-header-brand"><a href="./index.html">SDRF-Proteomics</a></div><nav class="doc-header-nav"><a href="./index.html">Home</a><a href="./specification.html">Specification</a><a href="./index.html#metadata-guidelines">Metadata Guidelines</a><a href="./index.html#templates">Templates</a><a href="./index.html#tools" class="nav-current">Tools</a><a href="./sdrf-explorer.html">Explorer</a><a href="./sdrf-editor.html">Editor</a><a href="./sdrf-builder.html">Template Builder</a><a href="./index.html#contributors">Contributors</a>{VERSION_LINK_PLACEHOLDER}<a href="https://github.com/bigbio/proteomics-metadata-standard" target="_blank">GitHub</a></nav></header>''', | ||
|
|
||
| 'guidelines': '''<header class="doc-header"><div class="doc-header-brand"><a href="../index.html">SDRF-Proteomics</a></div><nav class="doc-header-nav"><a href="../index.html">Home</a><a href="../specification.html">Specification</a><a href="../index.html#metadata-guidelines" class="nav-current">Metadata Guidelines</a><a href="../index.html#templates">Templates</a><a href="../index.html#tools">Tools</a><a href="../sdrf-explorer.html">Explorer</a><a href="../sdrf-editor.html">Editor</a><a href="../index.html#contributors">Contributors</a><a href="/dev/" class="version-link">Dev Version</a><a href="https://github.com/bigbio/proteomics-metadata-standard" target="_blank">GitHub</a></nav></header>''', | ||
| 'guidelines': f'''<header class="doc-header"><div class="doc-header-brand"><a href="../index.html">SDRF-Proteomics</a></div><nav class="doc-header-nav"><a href="../index.html">Home</a><a href="../specification.html">Specification</a><a href="../index.html#metadata-guidelines" class="nav-current">Metadata Guidelines</a><a href="../index.html#templates">Templates</a><a href="../index.html#tools">Tools</a><a href="../sdrf-explorer.html">Explorer</a><a href="../sdrf-editor.html">Editor</a><a href="../sdrf-builder.html">Template Builder</a><a href="../index.html#contributors">Contributors</a>{VERSION_LINK_PLACEHOLDER}<a href="https://github.com/bigbio/proteomics-metadata-standard" target="_blank">GitHub</a></nav></header>''', | ||
|
|
||
| 'templates': '''<header class="doc-header"><div class="doc-header-brand"><a href="../index.html">SDRF-Proteomics</a></div><nav class="doc-header-nav"><a href="../index.html">Home</a><a href="../specification.html">Specification</a><a href="../index.html#metadata-guidelines">Metadata Guidelines</a><a href="../index.html#templates" class="nav-current">Templates</a><a href="../index.html#tools">Tools</a><a href="../sdrf-explorer.html">Explorer</a><a href="../sdrf-editor.html">Editor</a><a href="../index.html#contributors">Contributors</a><a href="/dev/" class="version-link">Dev Version</a><a href="https://github.com/bigbio/proteomics-metadata-standard" target="_blank">GitHub</a></nav></header>''', | ||
| 'templates': f'''<header class="doc-header"><div class="doc-header-brand"><a href="../index.html">SDRF-Proteomics</a></div><nav class="doc-header-nav"><a href="../index.html">Home</a><a href="../specification.html">Specification</a><a href="../index.html#metadata-guidelines">Metadata Guidelines</a><a href="../index.html#templates" class="nav-current">Templates</a><a href="../index.html#tools">Tools</a><a href="../sdrf-explorer.html">Explorer</a><a href="../sdrf-editor.html">Editor</a><a href="../sdrf-builder.html">Template Builder</a><a href="../index.html#contributors">Contributors</a>{VERSION_LINK_PLACEHOLDER}<a href="https://github.com/bigbio/proteomics-metadata-standard" target="_blank">GitHub</a></nav></header>''', | ||
|
|
||
| 'sample_guidelines': '''<header class="doc-header"><div class="doc-header-brand"><a href="./index.html">SDRF-Proteomics</a></div><nav class="doc-header-nav"><a href="./index.html">Home</a><a href="./specification.html">Specification</a><a href="./index.html#metadata-guidelines" class="nav-current">Metadata Guidelines</a><a href="./index.html#templates">Templates</a><a href="./index.html#tools">Tools</a><a href="./sdrf-explorer.html">Explorer</a><a href="./sdrf-editor.html">Editor</a><a href="./index.html#contributors">Contributors</a><a href="/dev/" class="version-link">Dev Version</a><a href="https://github.com/bigbio/proteomics-metadata-standard" target="_blank">GitHub</a></nav></header>''', | ||
| 'sample_guidelines': f'''<header class="doc-header"><div class="doc-header-brand"><a href="./index.html">SDRF-Proteomics</a></div><nav class="doc-header-nav"><a href="./index.html">Home</a><a href="./specification.html">Specification</a><a href="./index.html#metadata-guidelines" class="nav-current">Metadata Guidelines</a><a href="./index.html#templates">Templates</a><a href="./index.html#tools">Tools</a><a href="./sdrf-explorer.html">Explorer</a><a href="./sdrf-editor.html">Editor</a><a href="./sdrf-builder.html">Template Builder</a><a href="./index.html#contributors">Contributors</a>{VERSION_LINK_PLACEHOLDER}<a href="https://github.com/bigbio/proteomics-metadata-standard" target="_blank">GitHub</a></nav></header>''', | ||
|
|
||
| 'templates_guide': '''<header class="doc-header"><div class="doc-header-brand"><a href="./index.html">SDRF-Proteomics</a></div><nav class="doc-header-nav"><a href="./index.html">Home</a><a href="./specification.html">Specification</a><a href="./index.html#metadata-guidelines">Metadata Guidelines</a><a href="./index.html#templates" class="nav-current">Templates</a><a href="./index.html#tools">Tools</a><a href="./sdrf-explorer.html">Explorer</a><a href="./sdrf-editor.html">Editor</a><a href="./index.html#contributors">Contributors</a><a href="/dev/" class="version-link">Dev Version</a><a href="https://github.com/bigbio/proteomics-metadata-standard" target="_blank">GitHub</a></nav></header>''' | ||
| 'templates_guide': f'''<header class="doc-header"><div class="doc-header-brand"><a href="./index.html">SDRF-Proteomics</a></div><nav class="doc-header-nav"><a href="./index.html">Home</a><a href="./specification.html">Specification</a><a href="./index.html#metadata-guidelines">Metadata Guidelines</a><a href="./index.html#templates" class="nav-current">Templates</a><a href="./index.html#tools">Tools</a><a href="./sdrf-explorer.html">Explorer</a><a href="./sdrf-editor.html">Editor</a><a href="./sdrf-builder.html">Template Builder</a><a href="./index.html#contributors">Contributors</a>{VERSION_LINK_PLACEHOLDER}<a href="https://github.com/bigbio/proteomics-metadata-standard" target="_blank">GitHub</a></nav></header>''' | ||
| } | ||
|
|
||
|
|
||
| def inject_header(filepath: str, header_html: str) -> None: | ||
| def inject_header(filepath: str, header_html: str, is_dev: bool = False) -> None: | ||
| """Inject navigation header into an HTML file.""" | ||
| with open(filepath, 'r', encoding='utf-8') as f: | ||
| content = f.read() | ||
|
|
||
| # Resolve version link based on dev/stable mode | ||
| 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>' | ||
| resolved_header = header_html.replace(VERSION_LINK_PLACEHOLDER, version_link) | ||
|
|
||
| # Add has-doc-header class to body | ||
| content = re.sub(r'<body class="([^"]*)"', r'<body class="has-doc-header \1"', content) | ||
| content = re.sub(r'<body>', '<body class="has-doc-header">', content) | ||
|
|
||
| # Insert header after opening body tag | ||
| content = re.sub(r'(<body[^>]*>)', r'\1\n' + header_html, content) | ||
| content = re.sub(r'(<body[^>]*>)', r'\1\n' + resolved_header, content) | ||
|
|
||
| with open(filepath, 'w', encoding='utf-8') as f: | ||
| 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.).""" | ||
| 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 | ||
|
|
||
| with open(filepath, 'w', encoding='utf-8') as f: | ||
| f.write(content) | ||
|
|
||
|
|
||
| def main(): | ||
| if len(sys.argv) < 2: | ||
| print("Usage: python3 inject-headers.py <output_dir>") | ||
| print("Usage: python3 inject-headers.py <output_dir> [--dev]") | ||
| sys.exit(1) | ||
|
|
||
| is_dev = '--dev' in sys.argv | ||
| output_dir = Path(sys.argv[1]) | ||
|
Comment on lines
75
to
81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 81 always treats Suggested change+import argparse
import sys
@@
def main():
- if len(sys.argv) < 2:
- print("Usage: python3 inject-headers.py <output_dir> [--dev]")
- sys.exit(1)
-
- is_dev = '--dev' in sys.argv
- output_dir = Path(sys.argv[1])
+ parser = argparse.ArgumentParser()
+ parser.add_argument("output_dir")
+ parser.add_argument("--dev", action="store_true")
+ args = parser.parse_args()
+
+ is_dev = args.dev
+ output_dir = Path(args.output_dir)🤖 Prompt for AI Agents |
||
|
|
||
| print(f"Dev mode: {is_dev}") | ||
|
|
||
| # Inject header into specification.html | ||
| spec_file = output_dir / "specification.html" | ||
| if spec_file.exists(): | ||
| print(f"Injecting header into: {spec_file}") | ||
| inject_header(str(spec_file), HEADERS['root']) | ||
| inject_header(str(spec_file), HEADERS['root'], is_dev) | ||
|
|
||
| # Inject header into tools.html | ||
| tools_file = output_dir / "tools.html" | ||
| if tools_file.exists(): | ||
| print(f"Injecting header into: {tools_file}") | ||
| inject_header(str(tools_file), HEADERS['tools']) | ||
| inject_header(str(tools_file), HEADERS['tools'], is_dev) | ||
|
|
||
| # Inject header into sample-guidelines.html | ||
| sg_file = output_dir / "sample-guidelines.html" | ||
| if sg_file.exists(): | ||
| print(f"Injecting header into: {sg_file}") | ||
| inject_header(str(sg_file), HEADERS['sample_guidelines']) | ||
| inject_header(str(sg_file), HEADERS['sample_guidelines'], is_dev) | ||
|
|
||
| # Inject header into templates.html (templates guide) | ||
| tpl_guide = output_dir / "templates.html" | ||
| if tpl_guide.exists(): | ||
| print(f"Injecting header into: {tpl_guide}") | ||
| inject_header(str(tpl_guide), HEADERS['templates_guide']) | ||
| inject_header(str(tpl_guide), HEADERS['templates_guide'], is_dev) | ||
|
|
||
| # Inject headers into metadata-guidelines pages | ||
| guidelines_dir = output_dir / "metadata-guidelines" | ||
| if guidelines_dir.exists(): | ||
| for html_file in guidelines_dir.glob("*.html"): | ||
| print(f"Injecting header into: {html_file}") | ||
| inject_header(str(html_file), HEADERS['guidelines']) | ||
| inject_header(str(html_file), HEADERS['guidelines'], is_dev) | ||
|
|
||
| # Inject headers into template pages | ||
| templates_dir = output_dir / "templates" | ||
| if templates_dir.exists(): | ||
| for html_file in templates_dir.glob("*.html"): | ||
| print(f"Injecting header into: {html_file}") | ||
| inject_header(str(html_file), HEADERS['templates']) | ||
| inject_header(str(html_file), HEADERS['templates'], is_dev) | ||
|
|
||
| # Rewrite version links in static HTML pages (index.html, quickstart.html, etc.) | ||
| 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("Header injection complete!") | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't splice
OUTPUT_DIRinto executable Python.Line 15 turns the shell argument into part of the Python source. A valid path containing
'will break the script, and it also makes the injection step harder to reason about. Pass the directory viasys.argvor the environment instead.Suggested change
📝 Committable suggestion
🤖 Prompt for AI Agents