Skip to content

Commit de1b05d

Browse files
committed
Renaming, plus code to check for renaming of files and to create stubs that redirect (fix #493)
1 parent a6c8f1e commit de1b05d

40 files changed

+152
-103
lines changed

Code Examples.md

-8
This file was deleted.

RENAMED.csv

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Old File to New file mappings
2+
# build.sh scans these and makes stubs for the website that redirect
3+
EspruinoBoard,/Original
4+
PuckJS,/Puck.js
5+
Code Examples,/Tutorials
6+
Notes,/FAQ
7+
Puck.js Quick Start,/Quick+Start+BLE#puckjs
8+
Puck.js BLE UART,/BLE UART
9+
Puck.js Advertising,/BLE Advertising
10+
Puck.js and Bluetooth Lightbulbs,/BLE Lightbulbs
11+
Puck.js Eddystone,/Eddystone
12+
Puck.js iBeacon,/iBeacon
13+
Puck.js IFTTT,/BLE IFTTT
14+
Puck.js MIDI,/BLE MIDI
15+
Puck.js Node-RED,/BLE Node-RED
16+
Puck.js Printer,/BLE Printers
17+
Puck.js Security,/BLE Security
18+
Puck.js Web Bluetooth,/Web Bluetooth
19+
Puck.js Keyboard,/BLE Keyboard
20+
Puck.js HTTP Proxy,/BLE HTTP Proxy
21+
Puck.js Music Control,/BLE Music Control

Tutorials.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ Tutorials
1515

1616
* APPEND_KEYWORD: Tutorials
1717

18-
Tasks
19-
-----
18+
Information
19+
-----------
2020

21-
* APPEND_KEYWORD: tasks
21+
* APPEND_KEYWORD: info
2222

2323
Peripherals
2424
----------
2525

2626
* APPEND_KEYWORD: peripherals
2727

2828
Devices
29-
------
29+
--------
3030

3131
* APPEND_KEYWORD: devices,-Module
3232

@@ -36,4 +36,3 @@ Examples
3636
--------
3737

3838
* APPEND_KEYWORD: examples,-Tutorials
39-

bin/build.js

+93-17
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ var ESPRUINO_DIR = path.resolve(BASEDIR, "../Espruino");
4444
var FUNCTION_KEYWORD_FILE = path.resolve(BASEDIR, "../Espruino/function_keywords.js");
4545
var KEYWORD_JS_FILE = path.resolve(HTML_DIR, "keywords.js");
4646

47+
var warnings = [];
48+
function WARNING(s) {
49+
console.log("WARNING: "+s);
50+
warnings.push(s);
51+
}
52+
53+
4754
var marked = require('marked');
4855
// Set default options except highlight which has no default
4956
var markedOptions = {
@@ -81,19 +88,33 @@ if (fs.existsSync(BASEDIR+"/ordering.txt")) {
8188
fileOrdering[line] = linenumber;
8289
});
8390
} else {
84-
console.log("WARNING: No 'ordering.txt' - not ordering tutorials");
91+
WARNING("No 'ordering.txt' - not ordering tutorials");
8592
console.log(' - Generate with: git ls-tree -r --name-only HEAD | xargs -I{} git log -1 --format="%at {}" -- {} | sort > ordering.txt');
8693
}
8794

95+
// Get list of files that have been renamed
96+
var renamedFiles = {};
97+
if (fs.existsSync(BASEDIR+"/RENAMED.csv")) {
98+
fs.readFileSync(BASEDIR+"/RENAMED.csv").toString().split("\n").map(function(line) {
99+
if (line[0]=="#") return;
100+
var csv = line.trim().split(",");
101+
if (csv=="") return;
102+
if (csv.length==2) {
103+
renamedFiles[csv[0]] = csv[1];
104+
} else WARNING("RENAMED.csv: Badly formatted line "+JSON.stringify(line));
105+
});
106+
} else {
107+
console.log("ERROR: No 'RENAMED.csv'");
108+
process.exit(1);
109+
}
110+
111+
88112
if (OFFLINE) {
89113
// if offline, copy the offline.css file in
90114
fs.createReadStream(path.resolve(BASEDIR, "bin/offline.css")).pipe(
91115
fs.createWriteStream(path.resolve(HTML_DIR, "offline.css")));
92116
}
93117

94-
function WARNING(s) {
95-
console.log("WARNING: "+s);
96-
}
97118

98119
function createSafeFilename(filename) {
99120
filename = filename.replace(/\//g,"_");
@@ -207,8 +228,8 @@ function grabInfo(markdownFiles, preloadedFiles) {
207228
var contents = preloadedFiles[file] ? preloadedFiles[file] : fs.readFileSync(BASEDIR+"/"+file).toString();
208229
// console.log(file,contents.length);
209230
var contentLines = contents.split("\n");
210-
if (contentLines[0].substr(0,15)!="<!--- Copyright") WARNING(file+" doesn't have a copyright line");
211-
if (contentLines[1].trim()=="" || contentLines[2].substr(0,3)!="===") WARNING(file+" doesn't have a title on the first line");
231+
if (!contentLines[0].match(/<!--+ Copyright/)) WARNING(file+": No copyright line");
232+
if (contentLines[1].trim()=="" || contentLines[2].substr(0,3)!="===") WARNING(file+": No title on the first line");
212233
var fileInfo = {
213234
path : file,
214235
title : contentLines[1], // second line
@@ -324,7 +345,7 @@ function handleImages(file, contents) {
324345
// now rename the image in the tag
325346
contents = contents.substr(0,tagMid+2)+newPath+contents.substr(tagEnd);
326347
} else {
327-
WARNING(file+": Image '"+imagePath+"' does not exist");
348+
WARNING(file+": Image '"+imagePath+"' does not exist ("+tagStart+","+tagMid+","+tagEnd+")");
328349
}
329350
}
330351
}
@@ -358,27 +379,51 @@ exampleFiles.forEach(function(exampleFile) {
358379
markdownFiles.push(exampleFile);
359380
preloadedFiles[exampleFile] = newFile;
360381

361-
} else WARNING(exampleFile+" has no comment block at the start");
382+
} else WARNING(exampleFile+": no comment block at the start");
362383
});
363384

364385

365-
366386
//console.log(markdownFiles);
367387
var fileInfo = grabInfo(markdownFiles, preloadedFiles);
368388
//console.log(fileInfo.keywords);
369389
grabWebsiteKeywords(fileInfo.keywords);
370390

371-
htmlFiles = {};
372-
htmlLinks = {};
391+
htmlFiles = {}; // filename -> file on disk with full path (for copy/etc)
392+
htmlLinks = {}; // filename -> actual URL link
393+
knownPageLinks = []; // pages that we know exist on this site
394+
// Go through all referenced files on the main Espruino site
395+
// TODO: in offline mode we should detect these links and go direct
396+
"Order Search Reference Download binaries".split(" ").forEach(function(file) {
397+
var htmlLink = file + (OFFLINE?".html":"");
398+
knownPageLinks.push((OFFLINE?"":"/")+htmlLink);
399+
});
400+
// Add JS files to our known files list
401+
["devices","modules","boards"].forEach(function(moduledir) {
402+
fs.readdirSync(path.resolve(BASEDIR,moduledir)).filter(function(file) {
403+
return file.substr(-3) == ".js";
404+
}).forEach(function(file) {
405+
knownPageLinks.push("/modules/"+file);
406+
});
407+
});
408+
// Go through all Markdown files
373409
markdownFiles.forEach(function (file) {
374410
var htmlFile = file.substring(file.lastIndexOf("/")+1);
375411
htmlFile = htmlFile.replace(/ /g,"+");
376412
htmlFile = htmlFile.substring(0,htmlFile.lastIndexOf("."));
377413
htmlFiles[file] = HTML_DIR+htmlFile+".html";
378-
if (OFFLINE)
379-
htmlLinks[file] = htmlFile+".html";
380-
else
381-
htmlLinks[file] = htmlFile;
414+
var htmlLink = htmlFile + (OFFLINE?".html":"");
415+
htmlLinks[file] = htmlLink;
416+
knownPageLinks.push((OFFLINE?"":"/")+htmlLink);
417+
});
418+
//console.log(JSON.stringify(knownPageLinks,null,2));process.exit(1);
419+
420+
// For files that have been renamed, create placeholder files that redirect
421+
Object.keys(renamedFiles).forEach(function(originalFile) {
422+
var newFile = renamedFiles[originalFile];
423+
var htmlFile = HTML_DIR+originalFile.replace(/ /g,"+")+".html";
424+
var html = `<p>This page has moved to <a href="${newFile}">${newFile}</a></p>
425+
<script>window.location = "${newFile}";</script>`;
426+
fs.writeFileSync(htmlFile, html);
382427
});
383428

384429
// ---------------------------------------------- Inference code
@@ -588,7 +633,7 @@ markdownFiles.forEach(function (file) {
588633
});
589634
content = '<div class="thumblinklist thumblinklist-thumbnails">\n '+contentThumbs.join("\n ")+'\n</div>';
590635
} else {
591-
WARNING(kwName+" for '"+kw+"' in "+file+" found nothing");
636+
WARNING(file+": "+kwName+" for '"+kw+"' found nothing");
592637
content = ifNone;
593638
}
594639
html = html.substr(0,match.index)+content+html.substr(match.index+match[0].length);
@@ -705,9 +750,32 @@ markdownFiles.forEach(function (file) {
705750
}
706751

707752
// If compiling for offline, quick hack to modify most links to go direct
708-
if (OFFLINE)
753+
if (OFFLINE) // FIXME - move this into the code below, do it properly with knownPageLinks
709754
html = html.replace(/(<[aA] .*href=")\/([^"#]*)/g, '$1$2.html');
710755

756+
// Scan all links in HTML to find possible replaced files
757+
{
758+
regex = /href="([^"]+)"/g;
759+
var m = regex.exec(html);
760+
while (m) {
761+
var url = m[1];
762+
var baseURL = url.replace(/#.*$/,"");
763+
if (baseURL!="") {
764+
if (baseURL in renamedFiles) {
765+
WARNING(`${file}: ${JSON.stringify(baseURL)} was renamed to ${JSON.stringify(renamedFiles[baseURL])}`);
766+
} else {
767+
if (baseURL.startsWith("http:") || baseURL.startsWith("https:")) {
768+
// we're ok...
769+
} else { // TODO: check if we know the page link
770+
/*if (knownPageLinks.indexOf(baseURL)<0)
771+
WARNING(`${file}: ${JSON.stringify(baseURL)} is not found`);*/
772+
}
773+
}
774+
}
775+
m = regex.exec(html);
776+
}
777+
}
778+
711779
// work out of we have any images that might be at the top of the page
712780
var hasImageContent = html.indexOf("<iframe ")>=0; // do we have a video?
713781
// do we have an image in the first few lines of markdown?
@@ -750,6 +818,14 @@ fs.writeFileSync(refPath, JSON.stringify(urls,null,1));
750818
// Write out keywords
751819
fs.writeFileSync(KEYWORD_JS_FILE, "var keywords = "+JSON.stringify(createKeywordsJS(fileInfo.keywords),null,1)+";");
752820

821+
console.log("====================================================== WARNINGS");
822+
console.log("====================================================== WARNINGS");
823+
console.log("====================================================== WARNINGS");
824+
warnings.forEach(w=>console.log(w));
825+
console.log("====================================================== WARNINGS");
826+
console.log("====================================================== WARNINGS");
827+
console.log("====================================================== WARNINGS");
828+
753829
// -----------------------------------------------------------
754830
// Newest tutorials
755831
/*child_process.exec(

boards/EspruinoBoard.md

-11
This file was deleted.

boards/PuckJS.md

-11
This file was deleted.

devices/ADNS5050.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ You can solve this in a few ways:
5656
* Create a smaller pinhole. Simply get some black tape and put it over the camera, then make a very small hole with a pin. Note that electrical tape won't be suitable as its stretchiness causes the hole you made to close up. You can however use Magic Tape that has been blackened with a marker pen.
5757
* Use a hemispherical clear stick-on foot as a lens. It is by no means perfect, but is significantly better than nothing:
5858

59-
![Small rubber foot][ADNS5050/optical_lens.jpg]
59+
![Small rubber foot](ADNS5050/optical_lens.jpg)
6060

6161
**Note:** The sensor comes with a small piece of Kapton Tape over the front of it, which is meant to be removed during production. Without this tape, the silicon of the sensor inside the module appears to be completly unprotected.
6262

@@ -74,7 +74,7 @@ sensor.drawImage(sensor.getImage());
7474
You'll get an ASCII art representation of the sensor's view, a bit like this:
7575

7676
```
77-
77+
7878
....
7979
........
8080
.........
@@ -102,7 +102,7 @@ There are also more functions to get movement, or values from just the first lin
102102

103103
* APPEND_JSDOC: ADNS5050.js
104104

105-
Using
105+
Using
106106
-----
107107

108108
* APPEND_USES: ADNS5050

devices/QuectelBG96.png

88.2 KB
Loading

devices/Robot.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ The kit contains the chassis, motors and wheels, but you still need something to
1818

1919
We used:
2020

21-
* An [Espruino Board](EspruinoBoard)
21+
* An [Espruino Board](Original)
2222
* A [[L293D]] Motor Driver IC soldered on to the board
2323
* A [[HC-SR04]] Ultrasonic Distance Sensor so that the Robot could sense the distance to obstacles.
2424

25-
Using
25+
Using
2626
-----
2727

2828
* APPEND_USES: Robot

info/Notes.md

-11
This file was deleted.
File renamed without changes.
File renamed without changes.

tutorials/Puck.js HTTP Proxy.md tutorials/BLE HTTP Proxy.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--- Copyright (c) 2016 Gordon Williams, Pur3 Ltd. See the file LICENSE for copying permission. -->
2-
Puck.js and HTTP Proxies
2+
Bluetooth LE HTTP Proxies
33
=========================
44

55
<span style="color:red">:warning: **Please view the correctly rendered version of this page at https://www.espruino.com/Puck.js+HTTP+Proxy. Links, lists, videos, search, and other features will not work correctly when viewed on GitHub** :warning:</span>
File renamed without changes.

tutorials/Puck.js IFTTT.md tutorials/BLE IFTTT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--- Copyright (c) 2016 Gordon Williams, Pur3 Ltd. See the file LICENSE for copying permission. -->
2-
Puck.js and If This Then That
2+
Bluetooth LE and If This Then That
33
==============================
44

55
<span style="color:red">:warning: **Please view the correctly rendered version of this page at https://www.espruino.com/Puck.js+IFTTT. Links, lists, videos, search, and other features will not work correctly when viewed on GitHub** :warning:</span>
File renamed without changes.

tutorials/Puck.js Keyboard.md tutorials/BLE Keyboard.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--- Copyright (c) 2016 Gordon Williams, Pur3 Ltd. See the file LICENSE for copying permission. -->
2-
Puck.js and HID Keyboards
3-
=========================
2+
Bluetooth LE HID Keyboards
3+
==========================
44

55
<span style="color:red">:warning: **Please view the correctly rendered version of this page at https://www.espruino.com/Puck.js+Keyboard. Links, lists, videos, search, and other features will not work correctly when viewed on GitHub** :warning:</span>
66

@@ -121,3 +121,9 @@ You can find key codes at https://www.usb.org/sites/default/files/documents/hut1
121121
* `0` is 39
122122
* Return is 40
123123
* Space is 44
124+
125+
126+
Uses
127+
----
128+
129+
* APPEND_USES: ble_hid
File renamed without changes.
File renamed without changes.

tutorials/Puck.js MIDI.md tutorials/BLE MIDI.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--- Copyright (c) 2017 Gordon Williams, Pur3 Ltd. See the file LICENSE for copying permission. -->
2-
Puck.js MIDI
3-
============
2+
Bluetooth LE MIDI
3+
=================
44

55
<span style="color:red">:warning: **Please view the correctly rendered version of this page at https://www.espruino.com/Puck.js+MIDI. Links, lists, videos, search, and other features will not work correctly when viewed on GitHub** :warning:</span>
66

File renamed without changes.

tutorials/Puck.js Music Control.md tutorials/BLE Music Control.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<!--- Copyright (c) 2017 Gordon Williams, Pur3 Ltd. See the file LICENSE for copying permission. -->
2-
Puck.js Music Controller
3-
========================
2+
Bluetooth Music Controller
3+
==========================
44

55
<span style="color:red">:warning: **Please view the correctly rendered version of this page at https://www.espruino.com/Puck.js+Music+Control. Links, lists, videos, search, and other features will not work correctly when viewed on GitHub** :warning:</span>
66

77
* KEYWORDS: Tutorials,Puck.js,BLE,Bluetooth,Car,Hands free,Handsfree,Music,Playback,Play,Pause,Next Track
8-
* USES: Puck.js,BLE,Only BLE
8+
* USES: Puck.js,BLE,Only BLE,ble_hid
99

1010
[[http://youtu.be/3iZ9j_ga6zs]]
1111

0 commit comments

Comments
 (0)