Export articles to your own blog with Swiftinit
Some users may prefer to use Unidoc and SwiftPM to author and compile a personal developer blog, but publish the rendered articles on their own website. This article explains how to use the Swiftinit API to render articles and export HTML that you can republish on your own website.
Prerequisites
You should have completed the Self-serve documentation tutorial.
Querying the API
Querying the API is simple. Every article on Swiftinit has a unique URL. For example, the NIO and Swift Concurrency article from the Swift NIO package can be found at:
https://swiftinit.org/docs/swift-nio/niocore/swift-concurrency
To obtain the equivalent rendering endpoint, replace swiftinit.org
with api.swiftinit.org
, and the /docs
path component with /render
.
https://api.swiftinit.org/render/swift-nio/niocore/swift-concurrency
TO use the render API, you must pass the Authorization
header with your User ID (from your account settings page) and the API key you previously generated under API keys. For more information on how to authenticate with the API, see Authenticating with the API.
Here’s an example of how to query the rendering endpoint with curl
:
curl -v \
-H "Authorization: Unidoc 4460509622_aaaabbbbccccdddd" \
'https://api.swiftinit.org/render/swift-nio/niocore/swift-concurrency'
If successful, the rendering endpoint will return a fragment of HTML with content type text/plain; charset=utf-8
. Unlike normal Swiftinit documentation, this HTML contains absolute URLs to symbol references, allowing you to embed it on your website under your own domain.
Rate limits
There is an hourly, per-account rate limit in effect on Swiftinit. Please note that some other actions on Swiftinit also decrement the limit, such as requesting a documentation build or fetching tags.
Syntax highlighting
Most users of the render API are interested in customizing the appearance of the rendered articles. For syntax highlighting, Swiftinit uses the following token classes.
token | class |
---|---|
attribute | xa |
binding | xb |
comment | xc |
directive | xr |
doccomment | xd |
identifier | xv |
interpolation | xj |
keyword | xk |
label | xl |
literal number | xn |
literal string | xs |
magic | xm |
operator | xo |
pseudo | xp |
actor | xy |
class | xz |
type | xt |
typealias | xu |
indent | xi |
Going further
You may want to read the Building docs programmatically tutorial to learn how to use the Swiftinit API to automate this process.