mirror of
git://git.yoctoproject.org/poky.git
synced 2025-07-19 21:09:03 +02:00
bitbake: sphinx: Enhance the sphinx experience/nagivation with:
* Remove the pointless looking parts of breadcrumb navigtation * Add a document type switcher to the breadcrumb navigation * Add a version selection switch to the breadcrumb navigation (Bitbake rev: cb19159cf8972713a2063387849804c5cea72d24) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> Signed-off-by: Nicolas Dechesne <nicolas.dechesne@linaro.org> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
390fc75bd6
commit
caf24e8ddd
14
bitbake/doc/_templates/breadcrumbs.html
vendored
Normal file
14
bitbake/doc/_templates/breadcrumbs.html
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{% extends "!breadcrumbs.html" %}
|
||||||
|
|
||||||
|
{% block breadcrumbs %}
|
||||||
|
<li>
|
||||||
|
<span class="doctype_switcher_placeholder">{{ doctype or 'single' }}</span>
|
||||||
|
<span class="version_switcher_placeholder">{{ release }}</span>
|
||||||
|
</li>
|
||||||
|
<li> »</li>
|
||||||
|
{% for doc in parents %}
|
||||||
|
<li><a href="{{ doc.link|e }}">{{ doc.title }}</a> »</li>
|
||||||
|
{% endfor %}
|
||||||
|
<li>{{ title }}</li>
|
||||||
|
{% endblock %}
|
||||||
|
|
7
bitbake/doc/_templates/layout.html
vendored
Normal file
7
bitbake/doc/_templates/layout.html
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{% extends "!layout.html" %}
|
||||||
|
|
||||||
|
{% block extrabody %}
|
||||||
|
<div id="outdated-warning" style="text-align: center; background-color: #FFBABA; color: #6A0E0E;">
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -16,6 +16,15 @@
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
current_version = "dev"
|
||||||
|
|
||||||
|
# String used in sidebar
|
||||||
|
version = 'Version: ' + current_version
|
||||||
|
if current_version == 'dev':
|
||||||
|
version = 'Version: Current Development'
|
||||||
|
# Version seen in documentation_options.js and hence in js switchers code
|
||||||
|
release = current_version
|
||||||
|
|
||||||
# -- Project information -----------------------------------------------------
|
# -- Project information -----------------------------------------------------
|
||||||
|
|
||||||
project = 'Bitbake'
|
project = 'Bitbake'
|
||||||
|
@ -67,6 +76,7 @@ html_static_path = ['sphinx-static']
|
||||||
|
|
||||||
# Add customm CSS and JS files
|
# Add customm CSS and JS files
|
||||||
html_css_files = ['theme_overrides.css']
|
html_css_files = ['theme_overrides.css']
|
||||||
|
html_js_files = ['switchers.js']
|
||||||
|
|
||||||
# Hide 'Created using Sphinx' text
|
# Hide 'Created using Sphinx' text
|
||||||
html_show_sphinx = False
|
html_show_sphinx = False
|
||||||
|
|
233
bitbake/doc/sphinx-static/switchers.js
Normal file
233
bitbake/doc/sphinx-static/switchers.js
Normal file
|
@ -0,0 +1,233 @@
|
||||||
|
(function() {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var all_versions = {
|
||||||
|
'dev': 'dev (3.2)',
|
||||||
|
'3.1.2': '3.1.2',
|
||||||
|
'3.0.3': '3.0.3',
|
||||||
|
'2.7.4': '2.7.4',
|
||||||
|
};
|
||||||
|
|
||||||
|
var all_doctypes = {
|
||||||
|
'single': 'Individual Webpages',
|
||||||
|
'mega': "All-in-one 'Mega' Manual",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Simple version comparision
|
||||||
|
// Return 1 if a > b
|
||||||
|
// Return -1 if a < b
|
||||||
|
// Return 0 if a == b
|
||||||
|
function ver_compare(a, b) {
|
||||||
|
if (a == "dev") {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a === b) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var a_components = a.split(".");
|
||||||
|
var b_components = b.split(".");
|
||||||
|
|
||||||
|
var len = Math.min(a_components.length, b_components.length);
|
||||||
|
|
||||||
|
// loop while the components are equal
|
||||||
|
for (var i = 0; i < len; i++) {
|
||||||
|
// A bigger than B
|
||||||
|
if (parseInt(a_components[i]) > parseInt(b_components[i])) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// B bigger than A
|
||||||
|
if (parseInt(a_components[i]) < parseInt(b_components[i])) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If one's a prefix of the other, the longer one is greater.
|
||||||
|
if (a_components.length > b_components.length) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a_components.length < b_components.length) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise they are the same.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_version_select(current_series, current_version) {
|
||||||
|
var buf = ['<select>'];
|
||||||
|
|
||||||
|
$.each(all_versions, function(version, title) {
|
||||||
|
var series = version.substr(0, 3);
|
||||||
|
if (series == current_series) {
|
||||||
|
if (version == current_version)
|
||||||
|
buf.push('<option value="' + version + '" selected="selected">' + title + '</option>');
|
||||||
|
else
|
||||||
|
buf.push('<option value="' + version + '">' + title + '</option>');
|
||||||
|
|
||||||
|
if (version != current_version)
|
||||||
|
buf.push('<option value="' + current_version + '" selected="selected">' + current_version + '</option>');
|
||||||
|
} else {
|
||||||
|
buf.push('<option value="' + version + '">' + title + '</option>');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buf.push('</select>');
|
||||||
|
return buf.join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_doctype_select(current_doctype) {
|
||||||
|
var buf = ['<select>'];
|
||||||
|
|
||||||
|
$.each(all_doctypes, function(doctype, title) {
|
||||||
|
if (doctype == current_doctype)
|
||||||
|
buf.push('<option value="' + doctype + '" selected="selected">' +
|
||||||
|
all_doctypes[current_doctype] + '</option>');
|
||||||
|
else
|
||||||
|
buf.push('<option value="' + doctype + '">' + title + '</option>');
|
||||||
|
});
|
||||||
|
if (!(current_doctype in all_doctypes)) {
|
||||||
|
// In case we're browsing a doctype that is not yet in all_doctypes.
|
||||||
|
buf.push('<option value="' + current_doctype + '" selected="selected">' +
|
||||||
|
current_doctype + '</option>');
|
||||||
|
all_doctypes[current_doctype] = current_doctype;
|
||||||
|
}
|
||||||
|
buf.push('</select>');
|
||||||
|
return buf.join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
function navigate_to_first_existing(urls) {
|
||||||
|
// Navigate to the first existing URL in urls.
|
||||||
|
var url = urls.shift();
|
||||||
|
|
||||||
|
// Web browsers won't redirect file:// urls to file urls using ajax but
|
||||||
|
// its useful for local testing
|
||||||
|
if (url.startsWith("file://")) {
|
||||||
|
window.location.href = url;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (urls.length == 0) {
|
||||||
|
window.location.href = url;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
success: function() {
|
||||||
|
window.location.href = url;
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
navigate_to_first_existing(urls);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_docroot_url() {
|
||||||
|
var url = window.location.href;
|
||||||
|
var root = DOCUMENTATION_OPTIONS.URL_ROOT;
|
||||||
|
|
||||||
|
var urlarray = url.split('/');
|
||||||
|
// Trim off anything after '/'
|
||||||
|
urlarray.pop();
|
||||||
|
var depth = (root.match(/\.\.\//g) || []).length;
|
||||||
|
for (var i = 0; i < depth; i++) {
|
||||||
|
urlarray.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
return urlarray.join('/') + '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
function on_version_switch() {
|
||||||
|
var selected_version = $(this).children('option:selected').attr('value');
|
||||||
|
var url = window.location.href;
|
||||||
|
var current_version = DOCUMENTATION_OPTIONS.VERSION;
|
||||||
|
var docroot = get_docroot_url()
|
||||||
|
|
||||||
|
var new_versionpath = selected_version + '/';
|
||||||
|
if (selected_version == "dev")
|
||||||
|
new_versionpath = '';
|
||||||
|
|
||||||
|
// dev versions have no version prefix
|
||||||
|
if (current_version == "dev") {
|
||||||
|
var new_url = docroot + new_versionpath + url.replace(docroot, "");
|
||||||
|
var fallback_url = docroot + new_versionpath;
|
||||||
|
} else {
|
||||||
|
var new_url = url.replace('/' + current_version + '/', '/' + new_versionpath);
|
||||||
|
var fallback_url = new_url.replace(url.replace(docroot, ""), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(get_docroot_url())
|
||||||
|
console.log(url + " to url " + new_url);
|
||||||
|
console.log(url + " to fallback " + fallback_url);
|
||||||
|
|
||||||
|
if (new_url != url) {
|
||||||
|
navigate_to_first_existing([
|
||||||
|
new_url,
|
||||||
|
fallback_url,
|
||||||
|
'https://www.yoctoproject.org/docs/',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function on_doctype_switch() {
|
||||||
|
var selected_doctype = $(this).children('option:selected').attr('value');
|
||||||
|
var url = window.location.href;
|
||||||
|
if (selected_doctype == 'mega') {
|
||||||
|
var docroot = get_docroot_url()
|
||||||
|
var current_version = DOCUMENTATION_OPTIONS.VERSION;
|
||||||
|
// Assume manuals before 3.2 are using old docbook mega-manual
|
||||||
|
if (ver_compare(current_version, "3.2") < 0) {
|
||||||
|
var new_url = docroot + "/mega-manual/mega-manual.html";
|
||||||
|
} else {
|
||||||
|
var new_url = docroot + "/singleindex.html";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var new_url = url.replace("/singleindex.html", "/index.html")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new_url != url) {
|
||||||
|
navigate_to_first_existing([
|
||||||
|
new_url,
|
||||||
|
'https://www.yoctoproject.org/docs/',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the current doctype based upon the url
|
||||||
|
function doctype_segment_from_url(url) {
|
||||||
|
if (url.includes("singleindex") || url.includes("mega-manual"))
|
||||||
|
return "mega";
|
||||||
|
return "single";
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
var release = DOCUMENTATION_OPTIONS.VERSION;
|
||||||
|
var current_doctype = doctype_segment_from_url(window.location.href);
|
||||||
|
var current_series = release.substr(0, 3);
|
||||||
|
var version_select = build_version_select(current_series, release);
|
||||||
|
|
||||||
|
$('.version_switcher_placeholder').html(version_select);
|
||||||
|
$('.version_switcher_placeholder select').bind('change', on_version_switch);
|
||||||
|
|
||||||
|
var doctype_select = build_doctype_select(current_doctype);
|
||||||
|
|
||||||
|
$('.doctype_switcher_placeholder').html(doctype_select);
|
||||||
|
$('.doctype_switcher_placeholder select').bind('change', on_doctype_switch);
|
||||||
|
|
||||||
|
if (ver_compare(release, "3.1") < 0) {
|
||||||
|
$('#outdated-warning').html('Version ' + release + ' of the project is now considered obsolete, please select and use a more recent version');
|
||||||
|
$('#outdated-warning').css('padding', '.5em');
|
||||||
|
} else if (release != "dev") {
|
||||||
|
$.each(all_versions, function(version, title) {
|
||||||
|
var series = version.substr(0, 3);
|
||||||
|
if (series == current_series && version != release) {
|
||||||
|
$('#outdated-warning').html('This document is for outdated version ' + release + ', you should select the latest release version in this series, ' + version + '.');
|
||||||
|
$('#outdated-warning').css('padding', '.5em');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user