In the DocC documentation, "Distributing Documentation to External Developers", Apple provided documentation to Host a Documentation Archive on Your Website. Unfortunately, when I open .doccarchive/index.html
, I just get a white page. They have only shown guidance for Apache servers. They have specified using a .htaccess
file, and using RewriteRule .* SlothCreator.doccarchive/$0 [L]
to rewrite URLs when a user visits the documentation page.
Is there a way to open the documentation web app without running an Apache server? (I don’t want to make any machine specific configuration like modifying /etc/hosts
). It would be ideal to be able to host this as a static site (e.g. on Github pages, Cloudflare pages, Netlify, etc.)
Edit: With @Ranoiaetep’s answer, I have built and pushed it to a GitHub repo and it can be viewed through a Netlify site: https://xcode-docc.netlify.app/documentation/
3
Answers
This is now documented in the
SwiftDocCPlugin
guide:Example
Warning
You'll see a few
Unfortunately
's in this answer. I highly recommend you avoid using DocC for the reasons explained below. If you find workarounds to these, do let me know :). In terms of comparison, DocC competes with so many successful static site generators and open source documentation frameworks (Docusaurus) and doesn't do very well.Steps
Package.swift
:cd docs
python3 -m http.server
.http://localhost:8000/documentation/target_name/
http://localhost:8000
, you get an error:The page you’re looking for can’t be found.
You cannot just open theindex.html
page without a server./<output-path-specified-by-command-line>/documentation/<target-name>
, for example, it could be:localhost:8000/documentation/slothcreator/
git add docs
andgit commit -m "Update GitHub pages documentation site."
. This is because services like Github Pages, Cloudflare Workers Sites can't build your site for you.docs/
) is 31MB and contains what appears to be unnecessary files and large, unoptimised assets. For some services eg Cloudflare Workers Sites, you have to upload the entire website every time you publish.As of current, I don’t think there’s any option of hosting it as a static site.
However it is pretty easy to host it on Netlify with a .toml file set up:
Update for Xcode 13.3
Note: I recommend iOS developers to avoid using the DocC plugin as outlined above because it’s an extra dependency that’s unnecessary if we have Xcode CLI tools installed already.
This wasn’t possible until recently enabled by the improvements in Xcode 13.3.
I’ve outlined multiple steps for DocC app/Package doccarchive deployment through GitHub Pages in my latest blog post.
The key steps to resolve several issues I had:
xcodebuild -project ModularSlothCreator.xcodeproj -scheme ModularSlothCreator -parallelizeTargets docbuild
to build a modular documentation archive.transform-for-static-hosting
flag provided by the docc cli${xcrun docc} transform-for-static-hosting ..
.For more details and a CI script, feel free to reference the blog post.