-
Notifications
You must be signed in to change notification settings - Fork 9
Generate static deployment for GH Pages #80
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e1cc0f5
Generate static deployment, add conda-map route to vercel to create b…
aganders3 382ac6c
Skip auto-commit on PRs to avoid conflicts
aganders3 6a72554
Fix gh-pages script
aganders3 560bfb6
Use relative paths in index.html for gh-pages subpath deployment
aganders3 0a16e41
Ensure root json files
aganders3 865f88d
Fix link to errors.json
aganders3 8714087
Fix extended summary endpoint
aganders3 6044f49
[bot] Update Plugin Index
github-actions[bot] 2c6fd1a
Revert "[bot] Update Plugin Index"
aganders3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
| # production | ||
| /build | ||
| /gh-pages | ||
|
|
||
| # misc | ||
| .DS_Store | ||
|
|
||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| #!/usr/bin/env python3 | ||
| """Prepare static files for GitHub Pages deployment. | ||
|
|
||
| This script creates a gh-pages directory with the same structure as public/ | ||
| but formatted for static file serving: | ||
| - No .json file extensions (to match API routes) | ||
| - conda.json -> conda-map (to avoid /conda conflicts with /conda/{plugin_name}) | ||
| - Everything nested under an 'api' directory | ||
| - Simple index.html at the root | ||
| """ | ||
|
|
||
| import json | ||
| import shutil | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def prepare_gh_pages(): | ||
| """Generate gh-pages directory structure from public directory.""" | ||
| root_dir = Path(__file__).parent.parent | ||
| public_dir = root_dir / "public" | ||
| gh_pages_dir = root_dir / "gh-pages" | ||
| api_dir = gh_pages_dir / "api" | ||
|
|
||
| if gh_pages_dir.exists(): | ||
| shutil.rmtree(gh_pages_dir) | ||
| gh_pages_dir.mkdir(exist_ok=True) | ||
| api_dir.mkdir(exist_ok=True) | ||
|
|
||
| print(f"📁 Preparing gh-pages directory at {gh_pages_dir}") | ||
|
|
||
| file_count = 0 | ||
|
|
||
| for source_file in public_dir.rglob("*"): | ||
| if not source_file.is_file(): | ||
| continue | ||
|
|
||
| if source_file.parent == "github": | ||
| # TODO: replace when github fetching is fixed | ||
| continue | ||
|
|
||
| rel_path = source_file.relative_to(public_dir) | ||
| dest_paths = [] | ||
|
|
||
| # special cases for some json files avaialable *outside* the API route | ||
| if source_file == public_dir / "classifiers.json": | ||
| dest_paths.append(gh_pages_dir / "classifiers.json") | ||
| elif source_file == public_dir / "conda.json": | ||
| dest_paths.append(gh_pages_dir / "conda.json") | ||
| dest_paths.append(api_dir / "conda-map") | ||
| elif source_file == public_dir / "errors.json": | ||
| dest_paths.append(gh_pages_dir / "errors.json") | ||
| elif source_file == public_dir / "extended_summary.json": | ||
| dest_paths.append(gh_pages_dir / "extended_summary.json") | ||
| dest_paths.append(api_dir / "extended_summary") | ||
| elif source_file == public_dir / "index.json": | ||
| dest_paths.append(gh_pages_dir / "index.json") | ||
| dest_paths.append(api_dir / "plugins") | ||
| elif source_file == public_dir / "readers.json": | ||
| dest_paths.append(gh_pages_dir / "readers.json") | ||
| else: | ||
| dest_paths.append(api_dir / str(rel_path).removesuffix(".json")) | ||
|
|
||
| for dest_path in dest_paths: | ||
| dest_path.parent.mkdir(parents=True, exist_ok=True) | ||
| shutil.copy2(source_file, dest_path) | ||
| file_count += 1 | ||
|
|
||
| if file_count % 100 == 0: | ||
| print(f" Copied {file_count} files...") | ||
|
|
||
| print(f"✅ Copied {file_count} files to gh-pages/api/") | ||
|
|
||
| create_index_html(gh_pages_dir, api_dir) | ||
|
|
||
| print("🎉 gh-pages directory ready for deployment!") | ||
|
|
||
|
|
||
| def create_index_html(gh_pages_dir: Path, api_dir: Path): | ||
| """Create a simple index.html that mimics the Next.js homepage.""" | ||
|
|
||
| # get the list of all plugins | ||
| index_file = api_dir / "plugins" | ||
| with open(index_file) as f: | ||
| index_data = json.load(f) | ||
|
|
||
| plugin_list_html = "\n".join( | ||
| [ | ||
| f' <li><a href="api/manifest/{name}">{name}-{version}</a></li>' | ||
| for name, version in sorted(index_data.items()) | ||
| ] | ||
| ) | ||
|
|
||
| html_content = f"""<!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>napari plugins</title> | ||
| </head> | ||
| <body> | ||
| <div> | ||
| <h1>napari plugins</h1> | ||
| <p>This page serves the REST API for napari plugins.</p> | ||
| <p> | ||
| It is generated by the source code in the | ||
| <a href="https://github.com/napari/npe2api">npe2api repo</a>. | ||
| </p> | ||
| <p> | ||
| A user-friendly site for napari plugin information is | ||
| <a href="https://napari-hub.org/">napari-hub.org</a> | ||
| </p> | ||
| <h3>Commonly used API endpoints</h3> | ||
| <p>Plugin index: <a href="api/plugins">api/plugins</a></p> | ||
| <p> | ||
| Summary info: | ||
| <a href="api/extended_summary">api/extended_summary</a> | ||
| </p> | ||
| <p> | ||
| PyPI information: | ||
| Use <code>api/pypi/pypi_plugin_name</code> | ||
| endpoint for an individual plugin. | ||
| </p> | ||
| <p> | ||
| Conda index: <a href="api/conda-map">api/conda-map</a> | ||
| (see conda info for each plugin at api/conda/pypi_name) | ||
| </p> | ||
| <p>Fetch errors: <a href="errors.json">errors.json</a></p> | ||
| <h3>Plugin manifests</h3> | ||
| <ul> | ||
| {plugin_list_html} | ||
| </ul> | ||
| </div> | ||
| </body> | ||
| </html> | ||
| """ | ||
|
|
||
| index_html = gh_pages_dir / "index.html" | ||
| with open(index_html, "w") as f: | ||
| f.write(html_content) | ||
|
|
||
| print(f"📄 Created index.html with {len(index_data)} plugins listed") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| prepare_gh_pages() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
so I notice sometimes we append the path with no
.jsontodest_pathsas well as with the.jsonsuffix. Can you explain why that is? I guessapi_diris the pages that are actually going to be served, andgh_pages_diris like... backup files? Why do we put them in there at all?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.
It's really an attempt to provide some backward-compatibility, but perhaps we don't need it. I think it's really an accident that both https://api.napari.org/conda.json and https://api.napari.org/api/conda point to the same thing in the current implementation.