Skip to content

Commit a9fcffb

Browse files
dgarcia360avelanarius
authored andcommitted
fix: redirection to api reference
Fix javadoc redirect Fix
1 parent 9c5695f commit a9fcffb

File tree

3 files changed

+63
-51
lines changed

3 files changed

+63
-51
lines changed

docs/Makefile

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ ifeq ($(OS),Windows_NT)
1818
POETRY = $(APPDATA)\Python\Scripts\poetry
1919
endif
2020

21-
define javadoc
22-
cd .. && ./docs/_utils/javadoc.sh
23-
endef
2421

2522
.PHONY: all
2623
all: dirhtml
@@ -56,7 +53,7 @@ dirhtml: setup
5653

5754
.PHONY: javadoc
5855
javadoc: setup
59-
@$(javadoc)
56+
cd .. && ./docs/_utils/javadoc.sh
6057
@echo
6158
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
6259

docs/pyproject.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ python = "^3.7"
99
pyyaml = "6.0"
1010
pygments = "2.2.0"
1111
recommonmark = "0.7.1"
12-
redirects_cli ="~0.1.2"
12+
redirects_cli ="~0.1.3"
1313
sphinx-scylladb-theme = "~1.3.1"
1414
sphinx-sitemap = "2.1.0"
1515
sphinx-autobuild = "2021.3.14"
1616
Sphinx = "4.3.2"
1717
sphinx-multiversion-scylla = "~0.2.12"
18+
setuptools = "^65.6.3"
19+
wheel = "^0.38.4"
1820

1921
[build-system]
2022
requires = ["poetry>=0.12"]

docs/source/conf.py

+59-46
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from recommonmark.transform import AutoStructify
88
from recommonmark.parser import CommonMarkParser, splitext, urlparse
99
from sphinx_scylladb_theme.utils import multiversion_regex_builder
10-
10+
from redirects_cli import cli as redirects_cli
1111

1212
# -- General configuration ------------------------------------------------
1313

@@ -44,51 +44,6 @@
4444
}
4545
autosectionlabel_prefix_document = True
4646

47-
class CustomCommonMarkParser(CommonMarkParser):
48-
49-
def visit_document(self, node):
50-
pass
51-
52-
def visit_link(self, mdnode):
53-
# Override to avoid checking if relative links exists
54-
ref_node = nodes.reference()
55-
destination = mdnode.destination
56-
_, ext = splitext(destination)
57-
58-
url_check = urlparse(destination)
59-
scheme_known = bool(url_check.scheme)
60-
61-
if not scheme_known and ext.replace('.', '') in self.supported:
62-
destination = destination.replace(ext, '')
63-
ref_node['refuri'] = destination
64-
ref_node.line = self._get_line(mdnode)
65-
if mdnode.title:
66-
ref_node['title'] = mdnode.title
67-
next_node = ref_node
68-
69-
self.current_node.append(next_node)
70-
self.current_node = ref_node
71-
72-
def replace_relative_links(app, docname, source):
73-
result = source[0]
74-
for key in app.config.replacements:
75-
result = re.sub(key, app.config.replacements[key], result)
76-
source[0] = result
77-
78-
def setup(app):
79-
app.add_source_parser(CustomCommonMarkParser)
80-
app.add_config_value('recommonmark_config', {
81-
'enable_eval_rst': True,
82-
'enable_auto_toc_tree': False,
83-
}, True)
84-
app.add_transform(AutoStructify)
85-
86-
# Replace DataStax links
87-
current_slug = os.getenv("SPHINX_MULTIVERSION_NAME", "stable")
88-
replacements = {r'docs.datastax.com/en/drivers/java\/(.*?)\/': "java-driver.docs.scylladb.com/" + current_slug + "/api/"}
89-
app.add_config_value('replacements', replacements, True)
90-
app.connect('source-read', replace_relative_links)
91-
9247
# The master toctree document.
9348
master_doc = 'contents'
9449

@@ -177,3 +132,61 @@ def setup(app):
177132

178133
# Dictionary of values to pass into the template engine’s context for all pages
179134
html_context = {'html_baseurl': html_baseurl}
135+
136+
# -- Initialize Sphinx ----------------------------------------------
137+
138+
class CustomCommonMarkParser(CommonMarkParser):
139+
140+
def visit_document(self, node):
141+
pass
142+
143+
def visit_link(self, mdnode):
144+
# Override MarkDownParser to avoid checking if relative links exists
145+
ref_node = nodes.reference()
146+
destination = mdnode.destination
147+
_, ext = splitext(destination)
148+
149+
url_check = urlparse(destination)
150+
scheme_known = bool(url_check.scheme)
151+
152+
if not scheme_known and ext.replace('.', '') in self.supported:
153+
destination = destination.replace(ext, '')
154+
ref_node['refuri'] = destination
155+
ref_node.line = self._get_line(mdnode)
156+
if mdnode.title:
157+
ref_node['title'] = mdnode.title
158+
next_node = ref_node
159+
160+
self.current_node.append(next_node)
161+
self.current_node = ref_node
162+
163+
def replace_relative_links(app, docname, source):
164+
result = source[0]
165+
for key in app.config.replacements:
166+
result = re.sub(key, app.config.replacements[key], result)
167+
source[0] = result
168+
169+
def build_finished(app, exception):
170+
version_name = os.getenv("SPHINX_MULTIVERSION_NAME", "")
171+
version_name = "/" + version_name if version_name else ""
172+
redirect_to = version_name +'/api/index.html'
173+
out_file = app.outdir +'/api.html'
174+
redirects_cli.create(redirect_to=redirect_to,out_file=out_file)
175+
176+
def setup(app):
177+
# Setup Markdown parser
178+
app.add_source_parser(CustomCommonMarkParser)
179+
app.add_config_value('recommonmark_config', {
180+
'enable_eval_rst': True,
181+
'enable_auto_toc_tree': False,
182+
}, True)
183+
app.add_transform(AutoStructify)
184+
185+
# Replace DataStax links
186+
current_slug = os.getenv("SPHINX_MULTIVERSION_NAME", "stable")
187+
replacements = {r'docs.datastax.com/en/drivers/java\/(.*?)\/': "java-driver.docs.scylladb.com/" + current_slug + "/api/"}
188+
app.add_config_value('replacements', replacements, True)
189+
app.connect('source-read', replace_relative_links)
190+
191+
# Create redirect to JavaDoc API
192+
app.connect('build-finished', build_finished)

0 commit comments

Comments
 (0)