Skip to content

Commit 4739a0f

Browse files
## Add sitemap generation for documentation ### Summary - Added `sphinx-sitemap` extension to automatically generate a sitemap for the PennyLane lightning documentation, improving SEO and to reduce number of [404 pages](https://www.notion.so/xanaduai/404-URLs-on-PennyLane-Website-2a7bc6bd1764807ba9a4c145e9d15ee8?pvs=26&qid=1%3A95a102a1-752c-4dff-8481-3a834455b689%3A3) showing up in Google Console. - marks C++ API pages a `no-index` to prevent C++ pages from getting indexed in Google. ### Changes - Added `sphinx_sitemap` to Sphinx extensions in `doc/conf.py` - Updated `html_baseurl` to use proper canonical URL with ReadTheDocs fallback - Added `sitemap_url_scheme` configuration for standard sitemap format - Added `sphinx-sitemap` dependency to: - `doc/requirements.txt` - `pyproject.toml` (docs optional dependencies) - Added `add_noindex_to_cpp_pages` to exclude C++ API pages - Rest are just formatting changes by `black` ## Ticket - [sc-103646-add-sitemap-for-docs-pennylane-ai-lightning](https://app.shortcut.com/xanaduai/story/103646/add-sitemap-for-docs-pennylane-ai-lightning) - [sc-103649-add-no-index-to-c-library-pages-in-lightning](https://app.shortcut.com/xanaduai/story/103649/add-no-index-to-c-library-pages-in-lightning-docs?vc_group_by=day&ct_workflow=all&cf_workflow=500000005) ## Testing - Check the sitemap [here](https://xanaduai-pennylane--1331.com.readthedocs.build/projects/lightning/en/1331/sitemap.xml) which includes list of all pages excluding C++ API ones. - Screenshot below to confirm addition of `no-index` tag to tell google to not index C++ API pages <img width="1865" height="571" alt="Screenshot 2026-01-16 at 10 15 54 AM" src="https://github.com/user-attachments/assets/1bafd238-25ae-49f7-ac3b-0bb2880389ff" /> --------- Co-authored-by: ringo-but-quantum <[email protected]>
1 parent b82f0b1 commit 4739a0f

File tree

5 files changed

+66
-13
lines changed

5 files changed

+66
-13
lines changed

.github/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
<h3>Improvements 🛠</h3>
1212

13+
- Added sitemap configuration and SEO improvements to documentation, including noindex meta tags for C++ API reference pages.
14+
[(#1331)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1331)
15+
1316
- Added a C++ kernel for the `qml.PauliRot` simulation on `lightning.gpu`.
1417
[(#1329)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1329)
1518

@@ -46,6 +49,7 @@
4649
This release contains contributions from (in alphabetical order):
4750

4851
Ali Asadi,
52+
Ashish Kanwar Singh
4953
Jeffrey Kam,
5054
Jake Zaia.
5155

doc/conf.py

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,25 @@ def obtain_cpp_files():
3939
print("The project directory structure is corrupted.")
4040
sys.exit(1)
4141

42-
exclude_dirs = [CPP_SOURCE_DIR.joinpath(exclude_dir) for exclude_dir in CPP_EXCLUDE_DIRS]
42+
exclude_dirs = [
43+
CPP_SOURCE_DIR.joinpath(exclude_dir) for exclude_dir in CPP_EXCLUDE_DIRS
44+
]
4345

4446
p = subprocess.run(
45-
[str(script_path), "--header-only", CPP_SOURCE_DIR, "--exclude-dirs", *exclude_dirs],
47+
[
48+
str(script_path),
49+
"--header-only",
50+
CPP_SOURCE_DIR,
51+
"--exclude-dirs",
52+
*exclude_dirs,
53+
],
4654
capture_output=True,
4755
)
4856
file_list = json.loads(p.stdout)
4957

50-
file_list = ["../" + str(Path(f).relative_to(PROJECT_SOURCE_DIR)) for f in file_list]
58+
file_list = [
59+
"../" + str(Path(f).relative_to(PROJECT_SOURCE_DIR)) for f in file_list
60+
]
5161
return file_list
5262

5363

@@ -63,8 +73,10 @@ def __getattr__(cls, name):
6373
return MagicMock()
6474

6575

66-
MOCK_MODULES = ["pennylane_lightning.lightning_qubit_ops",
67-
"pennylane_lightning.lightning_qubit_ops.algorithms"]
76+
MOCK_MODULES = [
77+
"pennylane_lightning.lightning_qubit_ops",
78+
"pennylane_lightning.lightning_qubit_ops.algorithms",
79+
]
6880

6981
mock = Mock()
7082
for mod_name in MOCK_MODULES:
@@ -94,6 +106,7 @@ def __getattr__(cls, name):
94106
"sphinx_automodapi.automodapi",
95107
"sphinx_automodapi.smart_resolver",
96108
"sphinxext.opengraph",
109+
"sphinx_sitemap",
97110
]
98111

99112
# Open Graph metadata
@@ -106,9 +119,11 @@ def __getattr__(cls, name):
106119
ogp_image = "_static/pennylane_lightning.png"
107120

108121
# The base URL with a proper language and version.
109-
html_baseurl = os.environ.get("READTHEDOCS_CANONICAL_URL", "/")
122+
html_baseurl = os.environ.get(
123+
"READTHEDOCS_CANONICAL_URL", "https://docs.pennylane.ai/projects/lightning/"
124+
)
110125

111-
intersphinx_mapping = {'pennylane':("https://docs.pennylane.ai/en/stable/", None)}
126+
intersphinx_mapping = {"pennylane": ("https://docs.pennylane.ai/en/stable/", None)}
112127

113128
autosummary_generate = True
114129
autosummary_imported_members = False
@@ -119,9 +134,7 @@ def __getattr__(cls, name):
119134
breathe_projects = {"Lightning-Qubit": "./doxyoutput/xml"}
120135
breathe_default_project = "Lightning-Qubit"
121136

122-
mathjax_path = (
123-
"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"
124-
)
137+
mathjax_path = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"
125138

126139
# Exhale extension
127140
# Setup the exhale extension
@@ -136,7 +149,9 @@ def __getattr__(cls, name):
136149
# TIP: if using the sphinx-bootstrap-theme, you need
137150
# "treeViewIsBootstrap": True,
138151
"exhaleExecutesDoxygen": True,
139-
"exhaleDoxygenStdin": ("INPUT = " + " ".join(CPP_FILES) + "\nEXCLUDE_SYMBOLS = std::* "),
152+
"exhaleDoxygenStdin": (
153+
"INPUT = " + " ".join(CPP_FILES) + "\nEXCLUDE_SYMBOLS = std::* "
154+
),
140155
"afterTitleDescription": inspect.cleandoc(
141156
"""
142157
The Pennylane Lightning C++ API is intended to be called from Python through Nanobind. Direct use of the C++ API is currently unsupported and is provided for reference only.
@@ -237,13 +252,42 @@ def __getattr__(cls, name):
237252
edit_on_github_project = "PennyLaneAI/pennylane-lightning"
238253
edit_on_github_branch = "master/doc"
239254

255+
# -- Sitemap settings -----------------------------------------------------
256+
sitemap_url_scheme = "{link}"
257+
# Exclude C++ API pages from sitemap (reference only, not for public indexing)
258+
sitemap_excludes = ["api/*"]
259+
260+
261+
# -- Add noindex to C++ API pages -----------------------------------------
262+
def add_noindex_to_cpp_pages(
263+
app, pagename, templatename, context, doctree
264+
): # pylint: disable=unused-argument
265+
"""
266+
Add noindex meta tag to C++ API pages generated by Exhale.
267+
268+
The C++ API is for reference only and should not be indexed by search engines.
269+
"""
270+
if pagename.startswith("api/"):
271+
metatags = context.get("metatags", "")
272+
context["metatags"] = (
273+
metatags + '<meta name="robots" content="noindex, nofollow" />\n'
274+
)
275+
276+
277+
def setup(app):
278+
"""Sphinx application setup hook."""
279+
app.connect("html-page-context", add_noindex_to_cpp_pages)
280+
281+
240282
# ============================================================
241283

242284
# the order in which autodoc lists the documented members
243285
autodoc_member_order = "bysource"
244286

245287
# inheritance_diagram graphviz attributes
246-
inheritance_node_attrs = dict(color="lightskyblue1", fillcolor="lightskyblue1", style="filled")
288+
inheritance_node_attrs = dict(
289+
color="lightskyblue1", fillcolor="lightskyblue1", style="filled"
290+
)
247291

248292
# autodoc_default_flags = ['members']
249293
autosummary_generate = True

doc/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ sphinxcontrib-htmlhelp==2.0.6
2020
sphinxcontrib-serializinghtml==2.0.0
2121
pennylane-sphinx-theme
2222
sphinxext-opengraph
23+
sphinx-sitemap
2324
matplotlib

doc/robots.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
User-agent: *
2+
3+
Sitemap: https://docs.pennylane.ai/projects/lightning/sitemap.xml
4+

pennylane_lightning/core/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
Version number (major.minor.patch[-label])
1717
"""
1818

19-
__version__ = "0.45.0-dev9"
19+
__version__ = "0.45.0-dev10"

0 commit comments

Comments
 (0)