Skip to content

Commit

Permalink
update readme scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
theo-armour committed Jul 24, 2016
1 parent cca51ce commit 62c5667
Show file tree
Hide file tree
Showing 48 changed files with 2,191 additions and 1,642 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<!doctype html>
<html lang=en >
<head>
<meta charset=utf-8 >
<title>GitHub API Menu of Read Me Files R4</title>
<meta name=viewport content='width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no' >
<meta name=description content='Browse and view files written in Markdown format.
Uses Github API to find directories with readme.md files.' >
<meta name=keywords content='Jaanga,GitHub API,JavaScript,GitHub,FOSS' >
<meta name=date content='2016-07-23' >
</head>
<body>
<script src=https://cdnjs.cloudflare.com/ajax/libs/showdown/1.4.2/showdown.min.js ></script>
<script>

// http://jaanga.github.io/cookbook-html/templates/menu-content-browser/github-api-menu-of-readme-files/

var urlAPIContents = 'https://api.github.com/repos/jaanga/jaanga.github.io/git/trees/master?recursive=1';
var converter = new showdown.Converter( { strikethrough: true, literalMidWordUnderscores: true, simplifiedAutoLink: true, tables: true });

var dirs = location.href.split( '/' );

home = 'jaanga.github.io';
index = dirs.indexOf( home ) + 1;

folders = dirs.slice( index, dirs.length - 1 ).join( '/' ) + '/' ;

console.log( 'folder', folders );

var searchForFile = 'readme.md';

// var searchInFolder = 'cookbook-html/templates/';
var searchInFolder = folders;

var path = './';

var files;

init();

function init() {

var css, menu, contents;

css = document.body.appendChild( document.createElement( 'style' ) );
css.innerHTML =

'body { font: 12pt monospace; margin: 0; }' +
'h2 a { color: crimson; }' +
'a { text-decoration: none; }' +
'button, input[type=button] { background-color: #eee; border: 2px #eee solid; color: #888; }' +

'#menu { box-sizing: border-box; background-color: #ccc; max-width: 300px; padding: 0 10px; position: absolute; }' +
'#contents { border: 0px red solid; left: 350px; overflow: auto; position: absolute; top: 0; width: ' + ( window.innerWidth - 370 ) + 'px; }' +

'';

menu = document.body.appendChild( document.createElement( 'div' ) );
menu.id = 'menu';

contents = document.body.appendChild( document.createElement( 'div' ) );
contents.id = 'contents';

window.addEventListener ( 'hashchange', hashChange, false );

requestAPIContents();

hashChange();

}

function requestAPIContents() {

var xhr, response, file;

xhr = new XMLHttpRequest();
xhr.open( 'GET', urlAPIContents, true );
xhr.onload = callback;
xhr.send( null );

function callback() {

response = JSON.parse( xhr.response );
files = [];

for ( var i = 0; i < response.tree.length; i++ ) {

file = response.tree[ i ].path;

if ( !file.match( searchInFolder ) ) { continue; }

if ( !file.match( searchForFile ) ) { continue; }

files.push( file );

}

//console.log( 'files', files );

createTableOfContents();

}

}

function createTableOfContents() {

var txt =

'<h2>' +
'<a href=http://jaanga.github.io title="Jaanga - your 3D happy place" > &#x2766 </a><br>' +
'<a href="" title="Click here to refresh this page" >' + document.title + '</a>' +
// '<a href=index.html#readme.md title="Click here for help and information" > &#x24D8; </a>' +
'</h2>';

for ( var i = 0; i < files.length; i++ ) {

file = files[ i ].replace( searchInFolder, '' );
txt +=

'<h3><a href=#' + path + file + ' >'+ file.replace( '/readme.md', '' ).replace( /-/g, ' ' ) + '<a></h3>' +

'';

}

menu.innerHTML = txt +

'<details >' +
'<summary><h3 style=display:inline; >About</h3></summary>' +
'<p>Copyright &copy; 2016 Jaanga authors. <a href=http://jaanga.github.io/home/r4/index.html#http://jaanga.github.io/jaanga-copyright-and-mit-license.md >MIT license</a>.</p>' +
'<p>Click the \'i in a circle\' icon for more <a href=index.html#readme.md title="Click here for help and information" >help</a>.</p>' +
'<p></p>' +
'</details>' +

'<hr><center><a href=javascript:window.scrollTo(0,0); style=text-decoration:none; title="Jaanga - your 3D happy place" ><h1> &#x2766 <h1></a></center>' +

'';

}

function hashChange() {

var fileName;

fileName = location.hash ? location.hash.slice( 1 ) : searchForFile;

getMarkdown( fileName, contents );

}

function getMarkdown( fileName, target ) {

var xhr;

xhr = new XMLHttpRequest();
xhr.open( 'GET', fileName, true );
xhr.onload = function() { target.innerHTML = converter.makeHtml( xhr.responseText ); };
xhr.send( null );

}

</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<!doctype html>
<html lang=en >
<head>
<meta charset=utf-8 >
<title>GitHub API Menu of Read Me Files R4</title>
<meta name=viewport content='width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no' >
<meta name=description content='Browse and view files written in Markdown format.
Uses Github API to find directories with readme.md files.' >
<meta name=keywords content='Jaanga,GitHub API,JavaScript,GitHub,FOSS' >
<meta name=date content='2016-07-23' >
</head>
<body>
<script src=https://cdnjs.cloudflare.com/ajax/libs/showdown/1.4.2/showdown.min.js ></script>
<script>

// http://jaanga.github.io/cookbook-html/templates/menu-content-browser/github-api-menu-of-readme-files/

var urlAPIContents = 'https://api.github.com/repos/jaanga/jaanga.github.io/git/trees/master?recursive=1';
var converter = new showdown.Converter( { strikethrough: true, literalMidWordUnderscores: true, simplifiedAutoLink: true, tables: true });

var dirs = location.href.split( '/' );

home = 'jaanga.github.io';
index = dirs.indexOf( home ) + 1;

folders = dirs.slice( index, dirs.length - 1 ).join( '/' ) + '/' ;

console.log( 'folder', folders );

var searchForFile = 'readme.md';

// var searchInFolder = 'cookbook-html/templates/';
var searchInFolder = folders;

var path = '../';

var files;

init();

function init() {

var css, menu, contents;

css = document.body.appendChild( document.createElement( 'style' ) );
css.innerHTML =

'body { font: 12pt monospace; margin: 0; }' +
'h2 a { color: crimson; }' +
'a { text-decoration: none; }' +
'button, input[type=button] { background-color: #eee; border: 2px #eee solid; color: #888; }' +

'#menu { box-sizing: border-box; background-color: #ccc; max-width: 300px; padding: 0 10px; position: absolute; }' +
'#contents { border: 0px red solid; left: 350px; overflow: auto; position: absolute; top: 0; width: ' + ( window.innerWidth - 370 ) + 'px; }' +

'';

menu = document.body.appendChild( document.createElement( 'div' ) );
menu.id = 'menu';

contents = document.body.appendChild( document.createElement( 'div' ) );
contents.id = 'contents';

window.addEventListener ( 'hashchange', hashChange, false );

requestAPIContents();

hashChange();

}

function requestAPIContents() {

var xhr, response, file;

xhr = new XMLHttpRequest();
xhr.open( 'GET', urlAPIContents, true );
xhr.onload = callback;
xhr.send( null );

function callback() {

response = JSON.parse( xhr.response );
files = [];

for ( var i = 0; i < response.tree.length; i++ ) {

file = response.tree[ i ].path;

if ( !file.match( searchInFolder ) ) { continue; }

if ( !file.match( searchForFile ) ) { continue; }

files.push( file );

}

//console.log( 'files', files );

createTableOfContents();

}

}

function createTableOfContents() {

var txt =

'<h2>' +
'<a href=http://jaanga.github.io title="Jaanga - your 3D happy place" > &#x2766 </a><br>' +
'<a href="" title="Click here to refresh this page" >' + document.title + '</a>' +
// '<a href=index.html#readme.md title="Click here for help and information" > &#x24D8; </a>' +
'</h2>';

for ( var i = 0; i < files.length; i++ ) {

file = files[ i ].replace( searchInFolder, '' );
txt +=

'<h3><a href=#' + path + file + ' >'+ file.replace( '/readme.md', '' ).replace( /-/g, ' ' ) + '<a></h3>' +

'';

}

menu.innerHTML = txt +

'<details >' +
'<summary><h3 style=display:inline; >About</h3></summary>' +
'<p>Copyright &copy; 2016 Jaanga authors. <a href=http://jaanga.github.io/home/r4/index.html#http://jaanga.github.io/jaanga-copyright-and-mit-license.md >MIT license</a>.</p>' +
'<p>Click the \'i in a circle\' icon for more <a href=index.html#readme.md title="Click here for help and information" >help</a>.</p>' +
'<p></p>' +
'</details>' +

'<hr><center><a href=javascript:window.scrollTo(0,0); style=text-decoration:none; title="Jaanga - your 3D happy place" ><h1> &#x2766 <h1></a></center>' +

'';

}

function hashChange() {

var fileName;

fileName = location.hash ? location.hash.slice( 1 ) : searchForFile;

getMarkdown( fileName, contents );

}

function getMarkdown( fileName, target ) {

var xhr;

xhr = new XMLHttpRequest();
xhr.open( 'GET', fileName, true );
xhr.onload = function() { target.innerHTML = converter.makeHtml( xhr.responseText ); };
xhr.send( null );

}

</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@

## Where Used

* https://Art.github.io/globes/
* https://jaanga.github.io/cookbook-html/templates/menu-contents-browser/
* https://jaanga.github.io/cookbook-html/templates/
* https://jaanga.github.io/cookbook-threejs/examples/google-api/
* https://fgx.github.io/sandbox/ << needs update


## Wish list

* Read Me template
* Brings in gallery view of files found


## Change Log

### 2016-07-21 ~ R3
Expand Down
Loading

0 comments on commit 62c5667

Please sign in to comment.