Single-File SPA HTML Channel Exporter & Publisher (#2) - #3249
Open
dsainvg001 wants to merge 1 commit into
Open
Conversation
feat(publish): add single-file SPA HTML export for channels/pages
Adds an opt-in single-file HTML export mode for publishing, alongside
the existing default publish pipeline, with zero changes to existing
behavior.
## Single-File SPA HTML Generator (core/publish/html_spa_exporter.go)
- Implements SingleFileHtmlBuilder, which processes exported object
snapshots (.pb files) from exportService.Export(..., IncludeNested: true)
when publishing a channel/page.
- Page graph traversal: automatically discovers the root page and all
nested sub-pages, profile pages, workspaces, and objects in the
channel. Wraps each page into a <div id="route-<id>" data-path="/<id>"
class="page"> section inside index.html.
- Block-to-HTML rendering: converts text (paragraphs, headings,
callouts with emojis, quotes, code, bulleted/numbered lists), tables,
layouts (columns/rows), dividers, bookmarks, and media/file
attachments (<img>, <video>, <audio>, download links) into valid
HTML. Small images (< 32KB) are embedded directly as inline base64
data URIs.
- Client-side JS routing: converts internal links (anytype://... or
target page IDs) into client-side routing triggers, e.g.
<a href="/<subPageId>" onclick="navigate(event, '/<subPageId>')">.
- Styling & themes: embeds a vanilla JS router (pushState, popstate,
DOMContentLoaded) plus responsive CSS with dark/light theme toggle
support (.page { display: none; } .page.active { display: block; }).
## Publishing Service Integration (core/publish/service.go)
- Opt-in format parsing: adds parseUriFormat(uri) to detect
?format=html_spa directly from the request URI, with no changes to
.proto schema files or regenerated protobuf Go files
(pb/commands.pb.go).
- Strips format query parameters before server registration so the
public URI registered with publishclient stays clean
(e.g., https://any.coop/identity/my-page).
- Bundles index.html alongside files/ in tempPublishDir, enforces
existing size limits against default/membership publishing limits,
and uploads the directory via publishClientService.UploadDir.
## Zero Regression & Compatibility
- Default publishing behavior (index.json.gz + files/) is 100%
unchanged for standard requests.
- Fully compatible with anytype-publish-server (publishclient),
gomobile C-bindings, and existing client applications.
## Testing
- Adds tests/publish_html_spa_exporter_test.go covering page graph
traversal, client-side routing link transformations, media
rendering, and vanilla JS router embedding.
- Updates core/publish/service_test.go to cover the Publish pipeline
with ?format=html_spa.
- All publish unit tests pass with a 100% pass rate.
|
CLA Assistant Lite bot: I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request |
Author
|
I have read the CLA Document and I hereby sign the CLA |
Author
|
recheck |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
feat(publish): add single-file SPA HTML export for channels/pages
Adds an opt-in single-file HTML export mode for publishing, alongside the existing default publish pipeline, with zero changes to existing behavior.
Single-File SPA HTML Generator (core/publish/html_spa_exporter.go)
Publishing Service Integration (core/publish/service.go)
Zero Regression & Compatibility
Testing
Description
This PR adds a new opt-in single-file HTML export/publish format for channels and pages. When selected via
?format=html_spaon the publish request, the entire channel (root page plus all nested sub-pages) is exported into one self-containedindex.htmlfile with built-in client-side routing, instead of the defaultindex.json.gzsnapshot bundle. This makes published channels viewable directly in any browser or static host, with no reader client required. Default publishing behavior is fully preserved.What type of PR is this? (check all applicable)
Related Tickets & Documents
Mobile & Desktop Screenshots/Recordings
Added tests?
Added to documentation?
[optional] Are there any post-deployment tasks we need to perform?
Yes — frontend work is needed as a follow-up: the frontend (for both channels and pages) needs to be updated to support this new export mode, including handling sub-pages so they're included and navigable when publishing with
?format=html_spa.