Skip to content

Commit bb5c6ba

Browse files
committed
add docs versions
1 parent f0888a8 commit bb5c6ba

File tree

4 files changed

+80
-14
lines changed

4 files changed

+80
-14
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
with open('docs/versions.json', 'w') as f:
6363
json.dump(versions, f)
6464
- name: Publish to GitHub Pages
65-
uses: fantix/ghaction-github-pages@master
65+
uses: python-gino/ghaction-github-pages@master
6666
with:
6767
repo: python-gino/python-gino.org
6868
target_branch: master

docs/theme/layout.html

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
}}<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">{{
112112
"知识共享署名-相同方式共享 4.0 国际许可协议"
113113
if language.startswith('zh') else
114-
"Creative Commons Attribution-ShareAlike 4.0 International License"
114+
" Creative Commons Attribution-ShareAlike 4.0 International License"
115115
}}</a>{{ "进行许可。" if language.startswith('zh') else "." }}
116116
</p>
117117
</div>
@@ -121,6 +121,11 @@
121121
{% if pagename != master_doc %}
122122
{{ toc }}
123123
{% endif %}
124+
<div id="version-selector">
125+
{% if pagename != master_doc and toc.count('href') > 1 %}
126+
<hr>
127+
{% endif %}
128+
</div>
124129
</div>
125130
</div>
126131

@@ -132,9 +137,7 @@
132137
{{ (language or "EN")[:2].upper() }}
133138
</div>
134139
</a>
135-
<ul>
136-
<li><a href="/docs/en/{{ VERSION.split('/')[-1] }}/{{ pagename }}.html" class="btn-floating blue">EN</a></li>
137-
<li><a href="/docs/zh/{{ VERSION.split('/')[-1] }}/{{ pagename }}.html" class="btn-floating red">ZH</a></li>
140+
<ul id="lang-selector">
138141
</ul>
139142
</div>
140143
</main>
@@ -144,6 +147,11 @@
144147
<script id="documentation_options" data-url_root="{{ pathto('', 1) }}" src="{{ pathto('_static/js/documentation_options.js', 1) }}"></script>
145148
<script type="text/javascript" src="{{ pathto('_static/js/underscore.js', 1) }}"></script>
146149
<script type="text/javascript" src="{{ pathto('_static/js/jquery.js', 1) }}"></script>
150+
<script type="text/javascript">
151+
var sver = '{{ '.'.join(VERSION.split('/')[-1].lstrip('v').split('.')[:2]) }}';
152+
var language = '{{ language or "en" }}';
153+
var pagename = '{{ pagename }}';
154+
</script>
147155
<script type="text/javascript" src="{{ pathto('_static/js/gino.js', 1) }}"></script>
148156
<script type="text/javascript" src="{{ pathto('searchindex.js', 1) }}"></script>
149157
</body>

docs/theme/static/css/gino.css

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,6 @@ div.search i {
295295
overflow-y: auto;
296296
}
297297

298-
.table-of-contents > ul {
299-
padding-bottom: 80px;
300-
}
301-
302298
.table-of-contents li {
303299
padding: 0;
304300
}
@@ -343,6 +339,37 @@ div.search i {
343339
font-weight: 500;
344340
}
345341

342+
.table-of-contents #version-selector hr {
343+
margin-top: 48px;
344+
}
345+
346+
.table-of-contents #version-selector div {
347+
margin-top: 16px;
348+
color: #757575;
349+
}
350+
351+
.table-of-contents #version-selector a {
352+
color: #757575;
353+
}
354+
355+
.table-of-contents #version-selector span,
356+
.table-of-contents #version-selector a,
357+
.table-of-contents #version-selector a:active,
358+
.table-of-contents #version-selector a:hover {
359+
border-left: none;
360+
padding: 8px;
361+
margin-left: 16px;
362+
}
363+
364+
.table-of-contents #version-selector a:active,
365+
.table-of-contents #version-selector a:hover {
366+
color: var(--v-info-light);
367+
}
368+
369+
.table-of-contents #version-selector span {
370+
color: var(--v-info-light);
371+
}
372+
346373
h1 {
347374
font-size: 32px;
348375
margin: 32px 0 20px 0;
@@ -637,6 +664,10 @@ nav a.sidenav-trigger hr {
637664
height: 2px;
638665
}
639666

667+
.fixed-action-btn {
668+
display: none;
669+
}
670+
640671
@media (min-width: 993px) {
641672
main {
642673
padding-left: 300px;
@@ -738,6 +769,10 @@ nav a.sidenav-trigger hr {
738769
.sidenav {
739770
top: 56px;
740771
}
772+
773+
.fixed-action-btn {
774+
display: block;
775+
}
741776
}
742777

743778
@media (max-width: 510px) {

docs/theme/static/js/gino.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,6 @@ document.addEventListener('DOMContentLoaded', function () {
476476
}
477477
sidenav.scrollTop = current.offsetTop - sidenav.clientHeight / 2;
478478

479-
// language and version selector
480-
M.FloatingActionButton.init(document.querySelectorAll('.fixed-action-btn'), {
481-
hoverEnabled: false
482-
});
483-
484479
// customize ScrollSpy
485480
var ScrollSpy = M.ScrollSpy, $ = window.cash;
486481
ScrollSpy._last = null;
@@ -616,4 +611,32 @@ document.addEventListener('DOMContentLoaded', function () {
616611
jQuery('.boxed-nav li').each(function (i, li) {
617612
jQuery(li).wrapInner('<a href="' + jQuery('a:first', li).attr('href') + '"><div></div></a>');
618613
});
614+
fetch('/docs/versions.json').then(function (r) {
615+
r.json().then(function (resp) {
616+
var langSel = jQuery('#lang-selector');
617+
var verSel = jQuery('#version-selector');
618+
var langColors = {zh: '#ff0000', en: '#0000ff'};
619+
var langNames = {
620+
zh: language.startsWith('zh') ? '中文' : 'Chinese',
621+
en: language.startsWith('zh') ? '英文' : 'English'
622+
}
623+
Object.keys(resp).forEach(function (loc) {
624+
langSel.append('<li><a href="/docs/' + loc + '/' + sver + '/' + pagename + '.html" class="btn-floating" style="background-color: ' + langColors[loc] + '!important">' + loc.toUpperCase() + '</a></li>');
625+
var curLoc = verSel.append('<div>' + langNames[loc] + '</div>')
626+
curLoc.append('<a href="https://python-gino.readthedocs.io/' + loc + '/v0.8.5/" target="_blank">0.8</a>')
627+
resp[loc].forEach(function (ver) {
628+
if (sver === ver && language.startsWith(loc)) {
629+
curLoc.append('<span>' + ver + '</span>')
630+
} else {
631+
curLoc.append('<a href="/docs/' + loc + '/' + ver + '/' + pagename + '.html">' + ver + '</a>')
632+
}
633+
});
634+
})
635+
636+
// language and version selector
637+
M.FloatingActionButton.init(document.querySelectorAll('.fixed-action-btn'), {
638+
hoverEnabled: false
639+
});
640+
})
641+
});
619642
});

0 commit comments

Comments
 (0)