Skip to content

Commit

Permalink
publishing to gh-pages
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <[email protected]>
  • Loading branch information
rwaldron committed Jun 2, 2017
1 parent 6a9bc90 commit 6e244b5
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 0 deletions.
39 changes: 39 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

function buildGHPages {
npm run build
}

set -e # Exit with nonzero exit code if anything fails

SOURCE_BRANCH="master"
TARGET_BRANCH="gh-pages"
MINE="[email protected]:rwaldron/tc39-notes.git";
TC39="[email protected]:tc39/tc39-notes.git";
SHA=`git rev-parse --verify HEAD`

# Checkout "gh-pages"
git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH

# Reset
git reset --hard

# Merge master for latest content
git merge $SOURCE_BRANCH

# Build it!
buildGHPages

# Commit the build
git add --all .
git commit -m "Build: ${SHA}"

# Push updates to:
# rwaldron/tc39-notes#gh-pages
git push $MINE $TARGET_BRANCH -f
# tc39/tc39-notes#gh-pages
git push $TC39 $TARGET_BRANCH -f


# When done, gtfo.
git checkout $SOURCE_BRANCH
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "tc39-notes",
"version": "1.0.0",
"description": "These are the notes that I've taken since joining TC39 as a representative of the jQuery Foundation.",
"main": "index.js",
"scripts": {
"build": "./scripts/builder.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rwaldron/tc39-notes.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/rwaldron/tc39-notes/issues"
},
"homepage": "https://github.com/rwaldron/tc39-notes#readme",
"devDependencies": {
"common-tags": "^1.4.0",
"glob": "^7.1.2",
"remarkable": "^1.7.1"
}
}
76 changes: 76 additions & 0 deletions scripts/builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env node

// System objects
const fs = require("fs");
const cp = require("child_process");
const path = require("path");

// Third party objects
const ct = require("common-tags");
const glob = require("glob");
const Remarkable = require("remarkable");

// Program instances
const remarkable = new Remarkable({
html: true,
linkify: true,
});


glob("./es*/**/*.md", (error, results) => {
const aliases = {};
const titles = {};
const links = [];
const contents = results.reverse().reduce((accum, file) => {
const source = fs.readFileSync(file, "utf8");
const name = file.replace(/\.\/es.\//, "");
aliases[name] = name.replace(/(\d{4}-\d{2})\//, "$1_").replace(".md", ".html");
titles[name] = source.split('\n')[0].replace("# ", "").trim();
accum[name] = source;
return accum;
}, {});


// console.log(index(Object.keys(contents)));
// console.log(titles);
// console.log(aliases);

// console.log(contents["2017-05/may-25.md"]);

Object.keys(aliases).forEach(alias => {
const fileName = aliases[alias];
const title = titles[alias];
const content = contents[alias];
fs.writeFileSync(fileName, makePage({ title, content }));

// links.push(remarkable.render(`[${title.replace(" Meeting Notes", "")}](${fileName})`));
links.push(`- [${title.replace(" Meeting Notes", "")}](${fileName})`);
});


const index = makeIndex({ links });

fs.writeFileSync("index.html", index);
});


function makeIndex({links}) {
return ct.stripIndent`
<!doctype html>
<meta charset="utf-8">
<ul>
${remarkable.render(links.join('\n'))}
</ul>
`;
}

function makePage({title, content}) {
return ct.stripIndent`
<!doctype html>
<meta charset="utf-8">
<title>${title}</title>
${remarkable.render(content)}
`;
}


0 comments on commit 6e244b5

Please sign in to comment.