Skip to content

Commit d61cfb9

Browse files
committed
[docs] Add new script for automatically generating an publishing the documentation
1 parent cb6d1b0 commit d61cfb9

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# You can set these variables from the command line.
55
SPHINXOPTS =
66
SPHINXBUILD = sphinx-build
7-
PAPER =
7+
PAPER = a4
88
BUILDDIR = build
99

1010
# Internal variables.

docs/publish.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/python3
2+
import os
3+
import sys
4+
__dir__ = os.path.dirname(__file__)
5+
sys.path.insert(0, os.path.join(__dir__, ".."))
6+
7+
import sphinx.cmd.build
8+
import ipfshttpclient
9+
10+
# Ensure working directory is script directory
11+
os.chdir(__dir__)
12+
13+
def main(argv=sys.argv[1:], program=sys.argv[0]):
14+
if len(argv) != 1:
15+
print("Usage: {0} [IPNS-key]".format(os.path.basename(program)))
16+
print()
17+
print("!! Continuing without publishing to IPNS !!")
18+
print()
19+
20+
# Invoke Sphinx like the Makefile does
21+
result = sphinx.cmd.build.build_main(["-b", "html", "-d", "build/doctrees", ".", "build/html"])
22+
if result != 0:
23+
return result
24+
25+
print()
26+
print("Exporting files to IPFS…")
27+
client = ipfshttpclient.connect()
28+
hash_docs = client.add("build/html", recursive=True, raw_leaves=True, pin=False)[-1]["Hash"]
29+
hash_main = client.object.new("unixfs-dir")["Hash"]
30+
hash_main = client.object.patch.add_link(hash_main, "docs", hash_docs)["Hash"]
31+
client.pin.add(hash_main)
32+
print("Final IPFS path: /ipfs/{0}".format(hash_main))
33+
34+
if len(argv) == 1:
35+
key = argv[0]
36+
print()
37+
print("Exporting files to IPNS…")
38+
name_main = client.name.publish(hash_main, key=key)["Name"]
39+
print("Final IPNS path: /ipns/{0}".format(name_main))
40+
41+
print()
42+
print("Run the following commandline on all systems that mirror this documentation:")
43+
print(" ipfs pin add {0} && ipfs name publish -k {1} /ipfs/{0}".format(hash_main, name_main))
44+
45+
return 0
46+
47+
if __name__ == "__main__":
48+
sys.exit(main())

0 commit comments

Comments
 (0)