Skip to content

Commit 6b0e3c7

Browse files
committed
ci: Only allow index, follow for production
1 parent 4f678de commit 6b0e3c7

File tree

8 files changed

+73
-1
lines changed

8 files changed

+73
-1
lines changed

.github/workflows/deploy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
if: github.ref == 'refs/heads/master'
3232
run: |
3333
echo "DOCS_BASE_URL=https://docs.hypernode.com/" >> $GITHUB_ENV
34+
echo "DOCS_INDEX_FOLLOW=1" >> $GITHUB_ENV
3435
- run: hypernode-deploy build -vvv
3536
- name: archive production artifacts
3637
uses: actions/upload-artifact@v3

docs/_templates/layout.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
{{- metatags }}
2121
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
2222
<meta name="theme-color" content="#063b67" />
23+
{%- if meta_robots %}
24+
<meta name="robots" content="{{ meta_robots }}">
25+
{%- endif %}
2326
{%- block htmltitle %}
2427
<title>{{ title|striptags|e }}{{ titlesuffix }}</title>
2528
{%- endblock -%}

docs/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"sphinx_copybutton",
4545
"notfound.extension",
4646
"hypernode.sphinx.extensions.updated_at",
47+
"hypernode.sphinx.extensions.meta_robots",
4748
"sphinxcontrib.mermaid",
4849
]
4950

@@ -80,6 +81,9 @@
8081

8182
sitemap_url_scheme = "{link}"
8283

84+
if os.getenv("DOCS_INDEX_FOLLOW", 0):
85+
html_meta_robots = "index, follow"
86+
8387
if os.getenv("DOCS_BASE_URL"):
8488
html_baseurl = os.getenv("DOCS_BASE_URL")
8589
extensions.append("sphinx_sitemap") # Only generate sitemap when we have a base url
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from sphinx.application import Sphinx
2+
3+
4+
def page_context_handler(app: Sphinx, pagename: str, templatename, context, doctree):
5+
context["meta_robots"] = app.config.html_meta_robots
6+
7+
8+
def setup_sphinx(app: Sphinx):
9+
app.add_config_value("html_meta_robots", "noindex, nofollow", "html")
10+
app.connect("html-page-context", page_context_handler)
11+
12+
return {
13+
"version": "0.1",
14+
"parallel_read_safe": True,
15+
"parallel_write_safe": True,
16+
}
17+
18+
19+
def setup(app: Sphinx):
20+
return setup_sphinx(app)

requirements/development.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pre-commit==2.18.1
55
black==22.10.0
66
pytest==7.1.2
77
pytest-xdist==2.5.0
8-
mypy==0.950
8+
mypy==1.0.0
99
flake8==3.9.2
1010
tox==3.25.0
1111
inotify==0.2.10

tests/sphinx/__init__.py

Whitespace-only changes.

tests/sphinx/extensions/__init__.py

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from unittest.mock import Mock
2+
3+
from sphinx.application import Sphinx
4+
from sphinx.config import Config
5+
6+
from hypernode.sphinx.extensions.meta_robots import page_context_handler, setup_sphinx
7+
from tests.testcase import HypernodeTestCase
8+
9+
10+
class TestPageContextHandler(HypernodeTestCase):
11+
def setUp(self) -> None:
12+
self.app = Mock(spec=Sphinx)
13+
self.app.config = Config({})
14+
self.app.config["html_meta_robots"] = "noindex, nofollow"
15+
self.context: dict = {}
16+
17+
def test_page_context_handler_sets_noindex_nofollow(self):
18+
page_context_handler(self.app, "", "", self.context, None)
19+
20+
self.assertIn("meta_robots", self.context)
21+
self.assertEqual("noindex, nofollow", self.context["meta_robots"])
22+
23+
def test_page_context_handler_sets_index_follow(self):
24+
self.app.config.html_meta_robots = "index, follow"
25+
26+
page_context_handler(self.app, "", "", self.context, None)
27+
28+
self.assertIn("meta_robots", self.context)
29+
self.assertEqual("index, follow", self.context["meta_robots"])
30+
31+
32+
class TestSetupSphinx(HypernodeTestCase):
33+
def setUp(self) -> None:
34+
self.app = Mock(spec=Sphinx)
35+
36+
def test_setup_adds_config_value(self):
37+
setup_sphinx(self.app)
38+
39+
self.app.add_config_value.assert_called_once_with(
40+
"html_meta_robots", "noindex, nofollow", "html"
41+
)
42+
self.app.connect.assert_called_once_with(
43+
"html-page-context", page_context_handler
44+
)

0 commit comments

Comments
 (0)