Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ejs template added #3

Merged
merged 7 commits into from
Apr 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 17 additions & 56 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require('path');
const fs = P.promisifyAll(require('fs'));
const rimraf = P.promisify(require('rimraf'));
const ghdownload = P.promisify(require('download-git-repo'));
const ejs = require('ejs');

const REPOS = require('./repositories.json').sort();
const REPO_DEST = path.join(__dirname, 'repo');
Expand Down Expand Up @@ -70,64 +71,26 @@ async function parse(REPO){
return { members: MEMBERS, dates: ALL_DATES };
}

// Format the parsed data from all markdown files into an HTML table.
async function format(data) {
let TABLE = `<table><tbody>`;
let members = Object.keys(data.members).sort();
let allDates = [...data.dates.entries()].sort().reverse();

// Table headers.
TABLE += `\n <tr>`
TABLE += `\n <th class="sr-only">Username</th>`;
for (let [date] of allDates) {
TABLE += `\n <th>${(new Date(date)).toDateString()}</th>`
}
TABLE += `\n </tr>`

// Member rows.
for (let user of members) {
TABLE += `\n <tr>`;
TABLE += `\n <td><a href="https://www.github.com/${user.replace('@', '')}" target="_blank">${user}</a></td>`;
for (let [date] of allDates) {
let isPresent = data.members[user].has(date);
TABLE += `\n <td class="${isPresent ? 'present' : 'absent'}">${isPresent ? 'Present' : 'Absent'}</td>`;
}
TABLE += `\n </tr>`;
}
TABLE += `</tbody></table>`;

return TABLE;
}

// Write the final HTML document to disk.
async function write(repos, repo, table) {

let html = `
<!DOCTYPE html>
<html>
<head>
<title>Node.js Meeting Participation</title>
<style>
${await fs.readFileAsync('./styles.css')}
</style>
</head>
<body>
<nav>
<ul>
${repos.map((n) => `<li class=${n === repo ? 'active' : ''}><a href="../${n}.html">${n}</a></li>`).join('\n')}
</ul>
</nav>
${table}
</body>
</html>
`;

async function write(repos, repo, content) {

let options = {
'client': true,
'root': './'
};
let data = {
'repos': repos,
'repo' : repo,
'content': content
};
let html = await ejs.renderFile('templates/page.ejs', data, options);
let desc = repo.split('/');
try {
await fs.mkdirAsync(SITE_DEST);
await fs.mkdirAsync(path.join(SITE_DEST, desc[0]));
} catch (e) { }

} catch (e) {
console.log('error', e);
}
await fs.writeFileAsync(path.join(SITE_DEST, desc[0], `${desc[1]}.html`), html);
}

Expand All @@ -142,10 +105,8 @@ async function run(){
await fetch(repo);
// Parse the member participant data for each meeting
let data = await parse(repo);
// Generate an HTML table using the data
let table = await format(data);
// Write a new HTML document for this page
await write(REPOS.slice(), repo, table);
await write(REPOS.slice(), repo, data);
}
}

Expand Down
4 changes: 2 additions & 2 deletions styles.css → css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ td:first-of-type a, th:first-of-type a{
}

td.present:after {
content: "";
content: "\2714";
color: white;
position: absolute;
z-index: 1;
Expand All @@ -91,7 +91,7 @@ td.present:before {
}

td.absent:after {
content: "·";
content: "\00B7";
color: white;
position: absolute;
z-index: 1;
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"bluebird": "^3.5.1",
"download-git-repo": "^1.0.2",
"ejs": "^2.5.8",
"rimraf": "^2.6.2"
}
}
2 changes: 2 additions & 0 deletions templates/header.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<title>Node.js Meeting Participation</title>
<link rel='stylesheet' type='text/css' href='../../css/styles.css'/>
18 changes: 18 additions & 0 deletions templates/page.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<%- include header %>
</head>
<body>
<nav>
<ul>
<% for (var r of repos) { %>
<% var active = r === repo ? 'active' : ''; %>
<% let href = '../' + r + '.html'; %>
<li class="<%=active%>"><a href="<%=href%>"><%=r%></a></li>
<% } %>
</ul>
</nav>
<%- include table %>
</body>
</html>
26 changes: 26 additions & 0 deletions templates/table.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<table>
<tbody>
<tr>
<th class="sr-only">Username</th>
<%
let members = Object.keys(content.members).sort();
let allDates = [...content.dates.entries()].sort().reverse();
%>

<% for (let [date] of allDates) { %>
<th><%=new Date(date).toDateString()%></th>
<% } %>
</tr>
<% for (let user of members) { %>
<tr>
<% let href = "https://www.github.com/" + user.replace('@', ''); %>
<td><a href="<%=href%>" target="_blank"><%=user%></a></td>
<% for (let [date] of allDates) {
let isPresent = content.members[user].has(date) ? 'present' : 'absent';
%>
<td class="<%=isPresent%>"><%=isPresent%></td>
<% } %>
</tr>
<% } %>
</tbody>
</table>