Skip to content

Commit e546b04

Browse files
authored
Set edit links dynamically for RtD preview and PR builds (#3280)
* Set edit links dynamically for RtD preview and PR builds * Replaced edit with blob
1 parent 028da83 commit e546b04

4 files changed

Lines changed: 17 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/vendor/
22
**/.DS_Store
33
__pycache__/*
4+
hooks/__pycache__/*
45
/site/
56
**/.idea/
67
.php-cs-fixer.cache

hooks/edit_uri.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
3+
def on_config(config, **kwargs):
4+
if os.environ.get("READTHEDOCS_VERSION_TYPE") == "external":
5+
ref = os.environ.get("READTHEDOCS_GIT_COMMIT_HASH")
6+
else:
7+
ref = os.environ.get("GITHUB_HEAD_REF")
8+
9+
if ref:
10+
config["edit_uri"] = f"blob/{ref}/docs/"
11+
12+
return config

mkdocs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ INHERIT: plugins.yml
22

33
site_name: Developer Documentation
44
repo_url: https://github.com/ibexa/documentation-developer
5-
edit_uri: edit/5.0/docs
5+
edit_uri: blob/5.0/docs
66
site_url: https://doc.ibexa.co/en/latest/
7+
hooks:
8+
- hooks/edit_uri.py
79
copyright: "Copyright 1999-2026 Ibexa AS and others"
810
validation:
911
omitted_files: warn

theme/partials/source.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% import "partials/language.html" as lang with context %}
2-
<a href="{{ page.edit_url|replace('/edit/', '/blob/') }}" title="{{ lang.t('source.link.title') }}" class="source-github">
2+
<a href="{{ page.edit_url }}" title="{{ lang.t('source.link.title') }}" class="source-github">
33
<div class="md-source__icon md-icon">
44
{% include ".icons/fontawesome/brands/github-alt.svg" %}
55
</div>

0 commit comments

Comments
 (0)