问题
I am currently using sphinx to automatically generate my documentation site from ReStructuredText files within a bitbucket repo.
This is of course all managed/hosted internally but I have been thinking more and more about whether I could switch this out for a more serverless model, using FaaS to generate the site and then a cloud based site hosting for the actual hosting (e.g S3 static site hosting).
I was wondering whether it was possible to use sphinx in a programmatic way (e.g within a AWS Lambda or Azure Function)?
Thanks, John
回答1:
Instead of executing sphinx-build from the command line, you can generate output by using a sphinx.application.Sphinx object directly.
A basic example:
import os
from sphinx.application import Sphinx
# Main arguments
srcdir = "/path/to/source"
confdir = srcdir
builddir = os.path.join(srcdir, "_build")
doctreedir = os.path.join(builddir, "doctrees")
builder = "html"
# Create the Sphinx application object
app = Sphinx(srcdir, confdir, builddir, doctreedir, builder)
# Run the build
app.build()
来源:https://stackoverflow.com/questions/48839993/use-sphinx-within-a-serverless-model