You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -16,10 +16,76 @@ If you prefer to write in ReStructured Text instead of Markdown for your technic
16
16
17
17
Another great offering is GitHub Pages, with automatic publishing when a known branch, such as master or gh-pages is updated.
18
18
19
+
So, how about the best of both? Let's dive into two key configurations that enable you to publish Python Sphinx pages to GitHub Pages.
19
20
21
+
## Naming the GitHub repository can affect the resulting URL
20
22
23
+
If you want a URL like `<username>.github.io` or ``<orgname>.github.io`, name the repo `<username>.github.io` or `<orgname>.github.io`. Then, by default, GitHub Pages publishes to the URL matching the repo name.
21
24
25
+
## Enable GitHub Pages for the GitHub repository
22
26
23
-
I've been working on a talk titled, "Make an Instant Web Site with Webhooks" for DevNet Create. In it, I show how to publish and host on GitHub Pages, which is built to use Jekyll by default, using Python Sphinx instead.
27
+
> Note: You must have admin privileges on the repository to see the **Settings** tab.
28
+
29
+
1. Go to the repository on the GitHub website and make sure you are logged in.
30
+
1. Add a `/docs` directory to the `master` branch. Otherwise you do not get the **master branch /docs folder** for the Source option in the drop-down list.
31
+
1. Click the **Settings** tab. You first go to the Options section.
32
+
1. Scroll down to the **GitHub Pages** section and choose the drop-down list under Source.
33
+
> Note: Your choices will differ based on whether you're in a User repo or an Org repo. [Read all about the differences in the GitHub docs](https://help.github.com/en/articles/user-organization-and-project-pages).
34
+
35
+
1. To keep source and output HTML separate, choose **master branch /docs folder** for Source.
36
+
37
+
Next, you set up the `.nojekyll` file to indicate you aren't using Jekyll as your static site generator in this repository.
38
+
39
+
## Add a .nojekyll file in the /docs directory
40
+
41
+
When GitHub sees a `.nojekyll` file, it serves the root `index.html` file. Read more in the [original blog post about this feature](https://github.blog/2009-12-29-bypassing-jekyll-on-github-pages/).
42
+
43
+
> Note: I'd recommend using the `/docs` directory on the `master` branch, so that you are sure to keep source and output HTML separate. You could also use a `_build` directory in the root of your repo as the served HTML.
44
+
45
+
1. Create a new branch locally, named `docs-config` in this example, based on `master`:
46
+
```
47
+
$ git checkout -b docs-config
48
+
```
49
+
1. Create an empty dot file, named `.nojekyll` within the `/docs` folder of your repo. A dot file has a period prefix and may not be visible in all text editors or your Finder windows, so be aware and don't panic if you can't "see" it later.
50
+
1. Use the add command to make sure Git starts tracking the file:
51
+
```
52
+
$ git add docs/.nojekyll
53
+
```
54
+
1. Commit the change with the `-a` option to add new files to the commit, and the `-m` option for a message:
55
+
```
56
+
$ git commit -a -m "Adds a .nojekyll file for docs builds"
57
+
```
58
+
1. Push the change to the remote, in this case named "origin", so you can compare the change to `master`.
59
+
```
60
+
$ git push origin docs-config
61
+
```
62
+
1. On the GitHub website, go to your repository and create a Pull Request.
63
+
1. Merge the Pull Request to add the `.nojekyll` file to the `master` branch.
64
+
65
+
## Create a "docsource" or "docsrc" folder for the source files
66
+
67
+
Now, in the root of your repository, you can create a source folder for your doc builds:
68
+
* If you're working with code and docs in the same repo, you can name the folder `docsource` or `docsrc`.
69
+
* If your repo is for only documentation, you can name the folder `source`.
70
+
71
+
Next, make sure that your `conf.py` file has been set up with these source and destination directories. The Sphinx documentation has a good [Configuration section](http://www.sphinx-doc.org/en/master/usage/configuration.html).
72
+
73
+
## Make sure you can still build Sphinx locally for reviews
74
+
75
+
Here's another pro tip I found while browsing [Issues in the Sphinx repository itself](https://github.com/sphinx-doc/sphinx/issues/3382#issuecomment-470772316). Since you want to keep the source and output separate, but still be able to both publish on GitHub Pages and preview builds locally, you can add an option to your `Makefile` to do both.
76
+
77
+
```
78
+
github:
79
+
@make html
80
+
@cp -a _build/html/. ../docs
81
+
```
82
+
83
+
Now you can run `make github` from the doc source directory to generate a local preview and move the docs where GitHub wants to serve them from.
84
+
85
+
> Note: Realize that there's a `conf.py` setting for both where the `make` command is run and where files are built to. Read up in the [Configuration section](http://www.sphinx-doc.org/en/master/usage/configuration.html) of the Sphinx docs for all the details.
86
+
87
+
## Pull it all together
88
+
89
+
I've been working on a talk titled, "Make an Instant Web Site with Webhooks" for DevNet Create. In it, I show how to publish and host on GitHub Pages, which is built to use Jekyll by default, using Python Sphinx instead. I'll post the slides when it's done. In the meantime, we'd love to see you next week! Visit the [DevNet Create site](https://developer.cisco.com/devnetcreate/2019) for more information.
0 commit comments