Performing Scripts
git and html scripts
This commit is contained in:
parent
474b259cef
commit
3b1bca9c41
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
node_modules
|
node_modules
|
||||||
|
export
|
||||||
|
|||||||
130
index.js
130
index.js
@ -1,35 +1,141 @@
|
|||||||
var nodegit = require('nodegit')
|
var nodegit = require('nodegit')
|
||||||
var path = require('path')
|
var path = require('path')
|
||||||
|
var fs = require('fs')
|
||||||
|
|
||||||
|
var all = []
|
||||||
|
|
||||||
|
var git_data = []
|
||||||
|
|
||||||
|
var cnt = 0;
|
||||||
|
|
||||||
|
//var export_path = 'export/';
|
||||||
|
var export_path = '/Users/gauthiier/Desktop/vbox/reckon_export/export';
|
||||||
|
var export_index_fname = 'index.json';
|
||||||
|
var export_index = null;
|
||||||
|
|
||||||
|
var template = '';
|
||||||
|
|
||||||
|
var imgs_list_ext_valid = ['.png', '.jpeg', '.jpg', '.gif']
|
||||||
|
|
||||||
|
fs.readFile('template.html', 'utf8', function(err, data) {
|
||||||
|
if(err) console.log(err);
|
||||||
|
template = data;
|
||||||
|
});
|
||||||
|
|
||||||
|
// hmm...
|
||||||
|
var export_index_path = path.join(export_path, export_index_fname);
|
||||||
|
if(fs.existsSync(export_index_path))
|
||||||
|
export_index = JSON.parse(fs.readFileSync(export_index_path, 'utf8'));
|
||||||
|
|
||||||
nodegit.Repository.open(path.resolve(__dirname, './.git'))
|
nodegit.Repository.open(path.resolve(__dirname, './.git'))
|
||||||
.then(function(repo) {
|
.then(function(repo) {
|
||||||
return repo.getBranchCommit('prototype');
|
return repo.getBranchCommit('prototype');
|
||||||
})
|
})
|
||||||
.then(function(first_commit) {
|
.then(function(first_commit) {
|
||||||
var history = first_commit.history(nodegit.Revwalk.SORT.Time);
|
var history = first_commit.history(nodegit.Revwalk.SORT.REVERSE);
|
||||||
|
//var history = first_commit.history(nodegit.Revwalk.SORT.TIME);
|
||||||
|
|
||||||
history.on("commit", function(commit) {
|
history.on("commit", function(commit) {
|
||||||
console.log("commit " + commit.sha());
|
|
||||||
console.log("Author:", commit.author().name() +
|
var entry = {};
|
||||||
" <" + commit.author().email() + ">");
|
|
||||||
console.log("Date:", commit.date());
|
entry.commit = commit.sha();
|
||||||
console.log("\n " + commit.message());
|
entry.author = commit.author().name();
|
||||||
|
entry.date = commit.date();
|
||||||
|
entry.raw = commit.rawHeader();
|
||||||
|
entry.message = commit.message().replace('\n', ' — ');
|
||||||
|
entry.files = [];
|
||||||
|
|
||||||
|
|
||||||
commit.getTree()
|
commit.getTree()
|
||||||
.then(function (tree) {
|
.then(function (tree) {
|
||||||
var entries = tree.entries();
|
var entries = tree.entries();
|
||||||
|
|
||||||
// look at diffs here -- as entries grows and does not specify the *specific* entries of this commit
|
for(e in entries) {
|
||||||
|
var ep = entries[e].path();
|
||||||
|
if(all.indexOf(ep) != -1) continue;
|
||||||
|
all.push(ep);
|
||||||
|
entry.files.push(ep);
|
||||||
|
}
|
||||||
|
|
||||||
for(e in entries) {
|
});
|
||||||
console.log(entries[e].path());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
git_data.push(entry);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
history.on("end", function() {
|
||||||
|
var body = '';
|
||||||
|
git_data.reverse();
|
||||||
|
for(var i in git_data)
|
||||||
|
body += emit_git_entry(git_data[i]);
|
||||||
|
console.log(template.replace('[[_export_]]', body));
|
||||||
|
});
|
||||||
|
|
||||||
history.start();
|
history.start();
|
||||||
|
|
||||||
})
|
})
|
||||||
.done();
|
.done();
|
||||||
|
|
||||||
|
function emit_git_entry(entry) {
|
||||||
|
|
||||||
|
var html = '<!-- entry #' + cnt++ + ' -->\n';
|
||||||
|
|
||||||
|
html += '<entry>\n'
|
||||||
|
|
||||||
|
html += ' <commit><h1>Commit: ' + entry.commit + '</h1></commit>\n';
|
||||||
|
|
||||||
|
html += ' <commit>' + entry.date + '</commit>\n';
|
||||||
|
|
||||||
|
html += ' <message><h2>' + entry.message + '</h2></message>\n';
|
||||||
|
|
||||||
|
html += ' <content>\n';
|
||||||
|
|
||||||
|
for(var q in entry.files) {
|
||||||
|
html += ' ' + emit_git_content(entry.files[q]);
|
||||||
|
}
|
||||||
|
|
||||||
|
html += ' </content>\n';
|
||||||
|
|
||||||
|
return html + '</entry>\n'
|
||||||
|
}
|
||||||
|
|
||||||
|
function emit_git_content(c) {
|
||||||
|
|
||||||
|
|
||||||
|
if(!fs.existsSync(path.join('.', c))) return '';
|
||||||
|
if(!fs.statSync(path.join('.', c)).isFile()) return '';
|
||||||
|
|
||||||
|
var ext = path.extname(c);
|
||||||
|
|
||||||
|
if(imgs_list_ext_valid.indexOf(ext) != -1)
|
||||||
|
return '<a href="' + c + '"><img src="' + c + '"/></a>\n';
|
||||||
|
else if(ext === '.pdf') {
|
||||||
|
return '<a href="' + c + '">' + emit_git_content_pdf(c) + '</a>';
|
||||||
|
} else {
|
||||||
|
return '<a href="' + c + '">' + c + '</a>\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function emit_git_content_pdf(c) {
|
||||||
|
|
||||||
|
var index = exists(c);
|
||||||
|
if(!index) return '';
|
||||||
|
|
||||||
|
return '<img src="' + path.join(export_path, index.imgs[0]) + '"/>\n';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// hmmm....
|
||||||
|
function exists(fname) {
|
||||||
|
|
||||||
|
if(!export_index) return null;
|
||||||
|
for (var e in export_index) {
|
||||||
|
if(export_index[e].name === fname)
|
||||||
|
return export_index[e];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
43
reckon.css
Normal file
43
reckon.css
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
body {
|
||||||
|
font-family: "Times New Roman", Times, Georgia, serif;
|
||||||
|
background-color: #ffff99;
|
||||||
|
bbackground-color: #e9d6a8;
|
||||||
|
bbackground-color: #eeeeee;
|
||||||
|
}
|
||||||
|
|
||||||
|
#listing {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#title {
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
text-align: center;
|
||||||
|
margin: 3em;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry {
|
||||||
|
display: block;
|
||||||
|
width: 75%;
|
||||||
|
border: 1px solid grey;
|
||||||
|
min-width: 650px;
|
||||||
|
margin-top: 0.6em;
|
||||||
|
padding: 0.6em;
|
||||||
|
background-color: #ffffcc;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
commit {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
content {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
content img {
|
||||||
|
max-width: 300px;
|
||||||
|
border: 1px solid grey;
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
13
template.html
Normal file
13
template.html
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<link rel="stylesheet" type="text/css" href="reckon.css"/>
|
||||||
|
<title>Performing Histories of Computation</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="listing">
|
||||||
|
<div id="title"><h1>Performing Histories of Computation</h1></div>
|
||||||
|
[[_export_]]
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user