Skip to content

Commit

Permalink
Add first view
Browse files Browse the repository at this point in the history
Lets use Nunjucks to render something to the user.
For now we just want to list all the names of the repos.
  • Loading branch information
rich committed Sep 5, 2024
1 parent 8c1958b commit 778572b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { createServer } from "http";
import { Octokit } from "@octokit/rest";
import nunjucks from "nunjucks";

nunjucks.configure({
autoescape: true,
watch: true,
});

const ACCESS_TOKEN = process.env.GITHUB_PERSONAL_ACCESS_TOKEN;

Expand All @@ -10,7 +16,11 @@ const octokit = new Octokit({
const httpServer = createServer(async (_, response) => {
const repos = await getRepos({ org: "dxw" });

return response.end(JSON.stringify(repos));
const template = nunjucks.render("index.njk", {
repos,
});

return response.end(template);
});

const getRepos = async ({ org }) => {
Expand Down
36 changes: 36 additions & 0 deletions index.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Towtruck</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="styles/styles.css" />
</head>
<body>
<h1>Towtruck</h1>

<table>
<caption>
dxw's repos
</caption>
<thead>
<tr>
<th scope="col">Name</th>
</tr>
</thead>
<tbody>
{% for repo in repos %}
<tr>
<td>{{ repo.name }}</td>
</tr>
{% else %}
<tr>
<td>No repos found</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>

0 comments on commit 778572b

Please sign in to comment.