Skip to content

Commit

Permalink
Merge pull request #90 from omichel/update-move-from-webots-doc-to-we…
Browse files Browse the repository at this point in the history
…bots

Prepare to move the doc from the webots-doc to the webots repository
  • Loading branch information
omichel committed Dec 17, 2018
2 parents 2c04dad + 6ec2cb5 commit e104047
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions docs/doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ function endsWith($haystack, $needle) {
if ($branch === '') {
# get HEAD commit SHA, to ensure that when master is updated the latest version is cached by the CDN
ini_set('user_agent', 'omichel'); # every GitHub request needs a valid user agent header
$githubHead = file_get_contents("https://api.github.com/repos/omichel/webots-doc/git/refs/heads/master");
$githubHead = file_get_contents("https://api.github.com/repos/omichel/webots/git/refs/heads/master");
// failed request / github is down
if ($githubHead === FALSE)
$cacheUrl = "https://cdn.jsdelivr.net/gh/$repository/webots-doc@master"; // fall back to dev URL at worst
$cacheUrl = "https://cdn.jsdelivr.net/gh/$repository/webots@master"; // fall back to dev URL at worst
else {
$githubPhp = json_decode($githubHead);
$sha = $githubPhp->object->sha;
$cacheUrl = "https://cdn.jsdelivr.net/gh/$repository/webots-doc@$sha"; // Load the current master snapshot from RawGit CDN.
$cacheUrl = "https://cdn.jsdelivr.net/gh/$repository/webots@$sha"; // Load the current master snapshot from RawGit CDN.
}
} else
$cacheUrl = "https://cdn.jsdelivr.net/gh/$repository/webots-doc@"; // Load master snapshot from dev URL.
$cacheUrl = "https://cdn.jsdelivr.net/gh/$repository/webots@"; // Load master snapshot from dev URL.

$scripts = "
<script>
Expand All @@ -81,14 +81,14 @@ function endsWith($haystack, $needle) {
'branch': '$branch',
'repository': '$repository',
'tag': '', // For backward compatibility < R2018a.
'url': 'https://raw.githubusercontent.com/$repository/webots-doc/'
'url': 'https://raw.githubusercontent.com/$repository/webots/'
}
console.log('Setup: ' + JSON.stringify(setup));
</script>
<link rel='stylesheet' type='text/css' href='$cacheUrl$branch/css/webots-doc.css'/>
<link rel='stylesheet' type='text/css' href='$cacheUrl$branch/docs/css/webots-doc.css'/>
";

$dependencies = file_get_contents("$cacheUrl$branch/dependencies.txt");
$dependencies = file_get_contents("$cacheUrl$branch/docs/dependencies.txt");
if ($dependencies == FALSE) // fallback for doc < R2018a.rev2
$dependencies = file_get_contents("https://www.cyberbotics.com/files/repository/www/wwi/R2018a/dependencies_fallback.txt");
foreach (explode(PHP_EOL, $dependencies) as $dependency) {
Expand All @@ -108,8 +108,8 @@ function endsWith($haystack, $needle) {
}

$scripts .= "
<script src='$cacheUrl$branch/js/showdown-extensions.js'></script>
<script src='$cacheUrl$branch/js/viewer.js'></script>
<script src='$cacheUrl$branch/docs/js/showdown-extensions.js'></script>
<script src='$cacheUrl$branch/docs/js/viewer.js'></script>
";
include 'header.php';
?>
Expand Down
8 changes: 4 additions & 4 deletions docs/js/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function computeTargetPath() {
if (localSetup.branch)
branch = localSetup.branch;
if (localSetup.url.startsWith('http'))
targetPath = localSetup.url + branch + '/';
targetPath = localSetup.url + branch + '/docs/';
targetPath += localSetup.book + '/';
return targetPath;
}
Expand Down Expand Up @@ -321,7 +321,7 @@ function addContributionBanner() {
// append contribution sticker to primary doc element
document.querySelector('#center').innerHTML += '<div style="top:' + displacement + '" class="contribution-banner">' +
'Found an error?' +
'<a target="_blank" class="contribution-banner-url" href="https://github.com/omichel/webots-doc"> ' +
'<a target="_blank" class="contribution-banner-url" href="https://github.com/omichel/webots/tree/master/docs"> ' +
'Contribute on GitHub!' +
'<span class=github-logo />' +
'</a>' +
Expand All @@ -339,7 +339,7 @@ function addContributionBanner() {
function updateContributionBannerUrl() {
var contributionBanner = document.querySelector('.contribution-banner-url');
if (contributionBanner)
contributionBanner.href = 'https://github.com/omichel/webots-doc/edit/master/' + localSetup.book + '/' + localSetup.page + '.md';
contributionBanner.href = 'https://github.com/omichel/webots/edit/master/docs/' + localSetup.book + '/' + localSetup.page + '.md';
}

function addNavigationToBlogIfNeeded() {
Expand Down Expand Up @@ -1307,7 +1307,7 @@ document.addEventListener('DOMContentLoaded', function() {

if (!isCyberboticsUrl) {
if (!localSetup.url)
localSetup.url = getGETQueryValue('url', 'https://raw.githubusercontent.com/omichel/webots-doc/');
localSetup.url = getGETQueryValue('url', 'https://raw.githubusercontent.com/omichel/webots/');
if (!localSetup.book)
localSetup.book = getGETQueryValue('book', 'guide');
if (!localSetup.page)
Expand Down

0 comments on commit e104047

Please sign in to comment.