Skip to content

Commit e502081

Browse files
fix: route shared navigation to the main website (#526)
1 parent c1e3af6 commit e502081

11 files changed

Lines changed: 298 additions & 20 deletions

File tree

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Project titles and banners link to a repository's HTTP(S) `homepage`, or its Git
3636
homepage is configured. Set that field to the project's public site, including its new subdomain.
3737
The consumer does not infer a site URL from an organization or repository name.
3838

39+
### Shared navigation
40+
41+
`url-canonical` in `_config_theme.yml` is the main-site address used by the shared brand, navigation, and footer links.
42+
Project pages keep their own `url` and `baseurl` for assets and database requests. Read the Docs project previews link
43+
to the published main site; previews of the main site override `url-canonical` with their own version path.
44+
3945
### CrowdIn Localization
4046

4147
<p align="center">

‎_config_theme.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ share-links-active:
5454
vk: false
5555
remove-ads: true # remove the "Powered by Beautiful Jekyll" text in the footer
5656
url-pretty: "app.LizardByte.dev"
57+
url-canonical: "https://app.lizardbyte.dev"
5758
title-on-all-pages: true
5859
excerpt_length: 50
5960
feed_show_excerpt: true

‎_includes/footer-extra.html‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% include open-in-new-window.html %}
22

3-
<a title="Privacy Policy" href="{{ '/privacy' | relative_url }}" class="text_muted">Privacy</a>
3+
<a title="Privacy Policy" href="{% include shared-site-url.html path='/privacy' %}" class="text_muted">Privacy</a>
44
&nbsp;&bull;&nbsp;
5-
<a title="Terms and Conditions" href="{{ '/terms' | relative_url }}" class="text_muted">Terms</a>
5+
<a title="Terms and Conditions" href="{% include shared-site-url.html path='/terms' %}" class="text_muted">Terms</a>
66
&nbsp;&bull;&nbsp;
7-
<a title="Licenses and Attribution" href="{{ '/licenses' | relative_url }}" class="text_muted">Licenses</a>
7+
<a title="Licenses and Attribution" href="{% include shared-site-url.html path='/licenses' %}" class="text_muted">Licenses</a>

‎_includes/nav.html‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<nav class="navbar navbar-expand-xl navbar-light fixed-top navbar-custom {% if page.nav-short %}top-nav-short-permanent{% else %}top-nav-regular{% endif %}">
2+
<div class="container-fluid">
3+
4+
{%- if site.title-img -%}
5+
<a class="navbar-brand navbar-brand-logo" href="{% include shared-site-url.html path='/' %}"><img alt="{{ site.title }} Logo" src="{{ site.title-img | relative_url}}"/></a>
6+
{%- elsif site.title -%}
7+
<a class="navbar-brand" href="{% include shared-site-url.html path='/' %}">{{ site.title }}</a>
8+
{%- endif -%}
9+
10+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false" aria-label="Toggle navigation">
11+
<span class="navbar-toggler-icon"></span>
12+
</button>
13+
14+
<div class="collapse navbar-collapse" id="main-navbar">
15+
<ul class="navbar-nav ms-auto">
16+
{%- for link in site.navbar-links -%}
17+
{%- if link[1].first %}
18+
<li class="nav-item dropdown">
19+
<button class="nav-link dropdown-toggle" id="navbarDropdown{{ forloop.index }}" type="button" data-bs-toggle="dropdown" aria-expanded="false">{{ link[0] }}</button>
20+
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown{{ forloop.index }}">
21+
{%- for childlink in link[1] -%}
22+
{%- for linkparts in childlink %}
23+
{%- assign navbar_link_url = linkparts[1] -%}
24+
<a class="dropdown-item" href="{% include shared-site-url.html path=navbar_link_url %}">{{ linkparts[0] }}</a>
25+
{%- endfor -%}
26+
{%- endfor %}
27+
</div>
28+
</li>
29+
{% else %}
30+
<li class="nav-item">
31+
{%- assign navbar_link_url = link[1] -%}
32+
<a class="nav-link" href="{% include shared-site-url.html path=navbar_link_url %}">{{ link[0] }}</a>
33+
</li>
34+
{%- endif -%}
35+
{%- endfor -%}
36+
{% if site.theme-switcher != false %}
37+
{% assign theme_style = site.theme-switcher-style | default: 'button' %}
38+
{% if theme_style == 'dropdown' %}
39+
<li class="nav-item dropdown">
40+
<button class="nav-link dropdown-toggle" id="themeDropdown" type="button" data-bs-toggle="dropdown" aria-expanded="false" title="Change theme">
41+
<span id="theme-icon-dropdown" class="fas fa-fw fa-circle-half-stroke"></span>
42+
<span class="d-xl-none ms-1">Theme</span>
43+
</button>
44+
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="themeDropdown">
45+
<a class="dropdown-item" href="#" data-bs-theme-value="light">
46+
<span class="fas fa-fw fa-sun me-2"></span>Light
47+
</a>
48+
<a class="dropdown-item" href="#" data-bs-theme-value="dark">
49+
<span class="fas fa-fw fa-moon me-2"></span>Dark
50+
</a>
51+
<a class="dropdown-item" href="#" data-bs-theme-value="auto">
52+
<span class="fas fa-fw fa-circle-half-stroke me-2"></span>Auto
53+
</a>
54+
</div>
55+
</li>
56+
{% else %}
57+
<li class="nav-item">
58+
<button class="nav-link" id="theme-toggle" type="button" title="Toggle theme (currently: auto)">
59+
<span id="theme-icon-button" class="fas fa-fw fa-circle-half-stroke"></span>
60+
<span class="d-xl-none ms-1">Theme</span>
61+
</button>
62+
</li>
63+
{% endif %}
64+
{%- endif -%}
65+
{% if site.post_search %}
66+
<li class="nav-item">
67+
<a class="nav-link" id="nav-search-link" href="#" title="Search">
68+
<span id="nav-search-icon" class="fa fa-fw fa-search"></span>
69+
<span id="nav-search-text">Search</span>
70+
</a>
71+
</li>
72+
{%- endif -%}
73+
</ul>
74+
</div>
75+
76+
{% if site.navbar-extra %}
77+
{% for file in site.navbar-extra %}
78+
{% include {{ file }} %}
79+
{% endfor %}
80+
{% endif %}
81+
82+
{% if site.avatar and page.show-avatar != false %}
83+
<div class="avatar-container">
84+
<div class="avatar-img-border">
85+
<a href="{{ '/' | relative_url }}">
86+
<img alt="Navigation bar avatar" class="avatar-img" src="{{ site.avatar | relative_url }}" />
87+
</a>
88+
</div>
89+
</div>
90+
{% endif %}
91+
92+
</div>
93+
</nav>
94+
95+
{% include search.html %}

‎_includes/shared-site-url.html‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{%- assign shared_path = include.path | default: '' -%}
2+
{%- assign shared_first = shared_path | slice: 0, 1 -%}
3+
{%- assign shared_prefix = shared_path | slice: 0, 2 -%}
4+
{%- if shared_path contains ':' or shared_prefix == '//' or shared_first == '#' -%}
5+
{{- shared_path | escape -}}
6+
{%- else -%}
7+
{%- assign shared_base = site.url-canonical | default: site.root_baseurl | default: '' -%}
8+
{%- assign shared_last = shared_base | slice: -1, 1 -%}
9+
{%- if shared_first == '/' -%}
10+
{%- assign shared_path = shared_path | remove_first: '/' -%}
11+
{%- endif -%}
12+
{{- shared_base | escape -}}{%- unless shared_last == '/' -%}/{%- endunless -%}{{- shared_path | escape -}}
13+
{%- endif -%}

‎_includes/support.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h3 class="fw-bolder">Support Center</h3>
1313
– Confucius.
1414
</p>
1515
<div class="input-group mb-2">
16-
<a href="{{ site.root_baseurl }}/support">
16+
<a href="{% include shared-site-url.html path='/support' %}">
1717
<button class="btn btn-outline-light rounded-0"
1818
id="button-support"
1919
type="button"

‎package-lock.json‎

Lines changed: 86 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"jest": "30.5.2",
4040
"jest-environment-jsdom": "30.5.2",
4141
"jest-junit": "17.0.0",
42+
"js-yaml": "5.5.0",
43+
"liquidjs": "10.30.1",
4244
"npm-run-all2": "9.0.4"
4345
},
4446
"repository": {

‎scripts/readthedocs_build.sh‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,19 +245,23 @@ cd "${TMPDIR}"
245245
gem install bundle
246246
bundle install
247247
echo "baseurl: ${READTHEDOCS_VERSION}" > _config_rtd.yml
248-
# Shared root links need the preview prefix without consumer repository paths.
249-
echo "root_baseurl: /${READTHEDOCS_VERSION}" >> _config_rtd.yml
248+
if [[ "${sub_project}" == "false" ]]; then
249+
# Main-site pages exist in this preview; consumer previews link to the published main site.
250+
echo "root_baseurl: /${READTHEDOCS_VERSION}" >> _config_rtd.yml
251+
echo "url-canonical: /${READTHEDOCS_VERSION}/" >> _config_rtd.yml
252+
fi
250253
echo "_config_rtd.yml:"
251254
cat _config_rtd.yml
252255
echo "_config_theme.yml:"
253256
cat _config_theme.yml
254257

255-
config_files=_config_rtd.yml,_config_theme.yml
258+
config_files=_config_theme.yml
256259
if [[ -n "${config_file}" ]] && [[ -e "${config_file}" ]]; then
257260
config_files="${config_files},${config_file}"
258261
echo "config file: ${config_file}"
259262
cat "${config_file}"
260263
fi
264+
config_files="${config_files},_config_rtd.yml"
261265

262266
bundle exec jekyll build \
263267
--future \
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{%- comment -%}Search UI rendering is independent of the shared navigation URL tests.{%- endcomment -%}

0 commit comments

Comments
 (0)