Skip to content
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
34 changes: 29 additions & 5 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,39 @@ main {
background-color: #dbdbdb;
}

.json {
display: block;
white-space: pre-wrap;
.text-truncate {
display: inline-block;
max-width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

.json,
code {
white-space: pre-line;
}

.indent h4,
.indent h5,
.indent h6 {
padding: 0;
}

.indent {
padding-left: 2rem;
margin-top: -2rem;
line-height: 2;
}

.indent * {
line-height: 1.5; /* If this value is changed, make sure it is atleast 1 to avoid clipping when text wraps */
font-size: 1em;
margin: 0;
text-align: left;
font-weight: 400;
}

.indent a {
font-weight: 700;
}

/* documentation */
Expand Down
12 changes: 11 additions & 1 deletion public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,17 @@ function renderMatches(matches) {

// Create an element that looks like a JSON object for every match
li.innerHTML = `
<pre class="json"><code>{<div class="indent"><br>name: '${match.name}',<br>url: <a href="${match.url}" target="_blank">'${match.url}',</a><br class="middle-br">keywords: [${match.keywords.map(keyword => `'${keyword}'`).join(", ")}]<br></div>},</code></pre>
<pre class="json">
<code>
{
<div class="indent">
<h4>name: ${match.name},</h4>
<h5>url: '<a href=${match.url} target="_blank">${match.url}</a>',</h5>
<h6 class="text-truncate">keywords: [${match.keywords.map(keyword => `'${keyword}'`).join(", ")}]</h6>
</div>
},
</code>
</pre>
`;

list.appendChild(li);
Expand Down
15 changes: 7 additions & 8 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ app.use(express.static(__dirname + '/public'));
app.use('/public', express.static(__dirname + '/public'));

app.get('/', (req, res) => {
try {
if (resources) {
res.render('index.ejs', { resources });
} else {
throw new Error('Resources not found.')
}
} catch (err) {
console.error(err);
if (resources) {
res.render('index.ejs', { resources });
} else {
// respond with status 500 if the resources array could not be loaded from resources.js
res.status(500).json({
error: 'Resources were not able to be loaded from "resources.js."'
});
}
});

Expand Down
12 changes: 11 additions & 1 deletion views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@
<li>
<!-- JSON Format for DOM rendering -->
<!-- Add indentation, line break and quotes around each key's value -->
<pre class="json"><code>{<div class="indent"><br>name: '<%= resources[i].name %>',<br>url: <a href=<%= resources[i].url %> target="_blank">'<%= resources[i].url %>',</a><br class="middle-br">keywords: [<%= resources[i].keywords.map(keyword => `'${keyword}'`).join(", ") %>]<br></div>},</code></pre>
<pre class="json">
<code>
{
<div class="indent">
<h4>name: '<%= resources[i].name %>',</h4>
<h5>url: '<a href=<%= resources[i].url %> target="_blank"><%= resources[i].url %></a>',</h5>
<h6 class="text-truncate">keywords: [<%= resources[i].keywords.map(keyword => `'${keyword}'`).join(", ") %>]</h6>
</div>
},
</code>
</pre>
</li>
<% } %>
</ul>
Expand Down