Overview
I’d like to pitch an experimental feature/option to let authors provide the absolute hosting URL for documentation. Today, --hosting-base-path allows specifying a path prefix, but not the absolute host path. From the option's doc (p.s., which could be confusing to someone new to DocC, like here):
The base path your documentation website will be hosted at.
For example, if you deploy your site to
'example.com/my_name/my_project/documentation' instead of
'example.com/documentation', pass '/my_name/my_project' as the base path.
As discussed in swiftlang/swift-docc issue #779, the current option does not provide sufficient information for features that depend on canonical absolute URLs.
There are several use cases where DocC knowing the absolute hosting location is useful:
- Sitemap requires absolute URLs. Adding this feature would make generating the sitemap (which would be my subsequent pitch) for the DocC website easier.
- Social metadata (for example Open Graph canonical URL fields) requires absolute URLs.
- Establishing links to external documentation dependencies (that are not part of the developer's package documentation).
- …some work in this area has been added via
--enable-experimental-external-link-support
- …some work in this area has been added via
My immediate goal is to unblock downstream sitemap generation workflows, but this feature could be useful beyond sitemaps.
Proposed Feature
Add an experimental argument to docc convert:
docc convert ... \
--enable-experimental-hosting-absolute-path https://docs.example.com/path
--enable-experimental-hosting-absolute-pathaccepts an absolute URL (for example https://docs.example.com/path).- DocC validates that the path is absolute (scheme + host provided).
- If provided, this value is treated as the canonical base for absolute URL needs, that take precedence over
--hosting-base-path.- When both this experimental flag and
--hosting-base-pathare provided, the latter is ignored. - When both are provided, generate error log diagnostics to indicate that they are mutually exclusive.
- When both this experimental flag and
Alternatives considered
- Continue with
--hosting-base-pathonly: insufficient for absolute URL requirements for sitemaps. - Add absolute URL support in
swift-docc-render: harder to configure per documentation build and less aligned with DocC’s archive-generation context. - Pitch this together with the sitemap generation: I think the mutual exclusiveness of this and
--hosting-base-pathis pretty complex, better to be dealt as its own pitch. - *Only for sitemaps, if we cannot have the absolute hosting path, maybe a placeholder can be used for the absolute path. The intermediate sitemap output can be processed more easily with that.
Feedback request
Would like to hear feedback on
- naming of this experimental argument
- side effect and conflict with
--hosting-base-path - other potential usecases and reasons to give an absolute path to DocC
Thanks @ronnqvist for providing initial feedback in swiftlang/swift-docc issue #779 and pointing me to the draft pitch message. This is my first time writing a pitch for DocC so feedback and comments are welcome!
*Human written, AI polished