Skip to content

Commit f4f50eb

Browse files
committed
Update Jekyll template to inject warnings in old help pages
1 parent 191861c commit f4f50eb

File tree

5 files changed

+89
-6
lines changed

5 files changed

+89
-6
lines changed

_config.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ github-fork-path: https://github.com/mu-editor/mu
2828

2929
gems: ["jekyll-sitemap"]
3030

31-
pages:
32-
- title: help
33-
url: help/0.9.11
34-
35-
3631

3732
# All Jekyll-Bootstrap specific configurations are namespaced into this hash
3833
#

_includes/themes/mu/page-help.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="page-header">
2+
<h1>{{ page.title }} {% if page.tagline %} <small>{{ page.tagline }}</small>{% endif %}</h1>
3+
</div>
4+
5+
<div class="row">
6+
<div class="col-xs-12">
7+
{{ content }}
8+
</div>
9+
</div>
10+
11+
<script src="/js/helpinject.js"></script>

_includes/themes/mu/settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
theme :
2-
name : bootstrap-3
2+
name : mu

_layouts/page-help.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
theme :
3+
name : mu
4+
layout: default
5+
---
6+
{% include JB/setup %}
7+
{% include themes/mu/page-help.html %}

js/helpinject.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @fileoverview This file executes on load and is meant to check if the help
3+
* page is the latest version and inject warnings into the page if not.
4+
* TODO: Need to use GitHub API to retrieve latest version published
5+
*/
6+
7+
'use strict';
8+
9+
(function() {
10+
// RegEx in semverRegex() function © Sindre Sorhus, MIT licensed
11+
// From https://github.com/sindresorhus/semver-regex
12+
var semverRegex = function () {
13+
return /\bv?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?\b/ig;
14+
};
15+
16+
var semverNumbersOnly = function(verStr) {
17+
// Simple rules here, remove prepended 'v' and appended '-identifier'
18+
var verArray = verStr.split('.');
19+
if (verArray[0].startsWith('v')) {
20+
verArray[0] = verArray[0].substring(1);
21+
}
22+
verArray[2] = verArray[2].split('-')[0];
23+
return verArray.join('.');
24+
};
25+
26+
var getUrlVersion = function() {
27+
var urlPath = window.location.pathname.split('/');
28+
for (var i = 0; i < urlPath.length; i++) {
29+
if (semverRegex().test(urlPath[i])) {
30+
return semverNumbersOnly(semverRegex().exec(urlPath[i])[0]);
31+
}
32+
}
33+
return null;
34+
};
35+
36+
var getLatestReleaseVersion = function() {
37+
// TODO: This is a hard-coded version string, need to use GH API instead
38+
var version = "0.9.13";
39+
return semverRegex().test(version) ? semverRegex().exec(version)[0] : null;
40+
};
41+
42+
var isVersionLowerThan = function(baseVersion, compareVersion) {
43+
// Version strings checked before, we trust they are formatted correctly
44+
var verBase = baseVersion.split('.');
45+
var verCompare = compareVersion.split('.');
46+
return (verBase[0] < verCompare[0]) || (verBase[1] < verCompare[1]) ||
47+
(verBase[2] < verCompare[2]);
48+
};
49+
50+
window.addEventListener('load', function load(event) {
51+
window.removeEventListener('load', load, false);
52+
var helpInjectDiv = document.getElementById('mu-help-header-inject');
53+
if (helpInjectDiv) {
54+
var urlVersion = getUrlVersion();
55+
var latestVersion = getLatestReleaseVersion();
56+
if (urlVersion && latestVersion && isVersionLowerThan(urlVersion, latestVersion)) {
57+
helpInjectDiv.innerHTML = [
58+
'<div class="alert alert-danger" role="alert">',
59+
' <h2><strong>Update Mu!</strong></h2>',
60+
' <p>You appear to be using an old version of Mu. Please <a href="https://codewith.mu" target="_blank">download the latest version</a>.</p>',
61+
'</div>',
62+
'<div role="alert" class="alert alert-warning">',
63+
' <h2><strong>This is not the latest Documentation!</strong></h2>',
64+
' <p>This documentation corresponds to the Mu version you are using, however documentation for newer versions of Mu might contain more content and troubleshooting information.</p>',
65+
' <p><a href="/help">View documentation for newest versions of Mu.</a></p>',
66+
'</div>'].join('\n');
67+
}
68+
}
69+
});
70+
})();

0 commit comments

Comments
 (0)