How to Serve a Sphinx Site as a Subdirectory of a Static Blog?

0
6
Asked By CreativeCheetah42 On

I'm running a static site blog served by Caddy, located in the directory `~/containers/caddy/site`. I want to add a Sphinx-generated static site in a subdirectory, accessible at `myblog.com/newsite`. The main blog uses Zola to generate the static site. I'm considering adding a hardlink to the Sphinx project directory in the `static` folder that Zola outputs. I tried a test on my local setup with Podman and faced an issue: I can't create a hardlink for a directory, and symlinks don't work well with containers as they point to paths inside the container. Is there a simple way to achieve this without modifying my Podman compose or quadlet file? I want to manage the new site files separately but serve them in a subdirectory—ideally through linking or some other method.

2 Answers

Answered By SassySphinx68 On

The simplest solution would be to set the Sphinx output directory directly in your Caddy site folder (`~/containers/caddy/site/newsite/`). You can override where Sphinx writes its HTML output in the `conf.py` file. This way, you won’t need any linking since Sphinx can directly write to where Caddy serves from.

If you want to keep the Sphinx project separated for organization, you could run a one-liner build step after your Zola build: `sphinx-build -b html /your/sphinx/project ~/containers/caddy/site/newsite/` so that both sites are served from the same directory. This linking approach seems like it might complicate things compared to just managing where each tool outputs its files.

CuriousCat53 -

Running that after my Zola build means I'll have both sites in the same tree, but it creates a headache since generating directly could overwrite files. Plus, I often copy everything to the server immediately after building, so I need to hold onto or rebuild the new output locally to recopy it into the subdirectory. I’m really trying to avoid touching the Sphinx project after the initial publish... I guess I’ll just go for the bind mount option and adjust Caddy. Seems like it's the least complicated way.

Answered By TechieTiger88 On

You could definitely use a bind mount for the Sphinx subdirectory in your compose file, but if you want to avoid that, here’s a workaround: try using `rsync` or a simple script to copy the Sphinx output into Zola’s static directory before building. Something like `rsync -av ../sphinx-project/_build/html/ static/newsite/` in your build pipeline could do the trick.

Alternatively, if you're using Caddy, you can configure it to serve multiple roots with a route matcher, allowing Caddy to handle requests to `/newsite/*` from a different directory. This way, your blog and the Sphinx site remain separate on disk but appear unified when served. Your Caddy configuration could look like this:

```
myblog.com {
handle /newsite/* {
root * /path/to/sphinx/output
file_server
}
handle {
root * /path/to/zola/public
file_server
}
}
```

This method is cleaner and avoids the hassle of symlinks across container boundaries.

QuickFox11 -

Thanks for the Caddy file tips!

I actually had the third option in mind. But I guess I still need a bind mount too since the Sphinx output is separate.

HelpfulHedgehog99 -

If it's possible, I’d prefer to modify just the compose file and leave the Caddy configuration alone. Will a bind mount to `/var/www/newsite/` from the Sphinx directory on the host work?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.