Browse Source

Setup EJS template rendering

master
Perception 4 months ago
parent
commit
f611caef58
6 changed files with 161 additions and 0 deletions
  1. +18
    -0
      page.js
  2. +5
    -0
      templates/_footer.ejs
  3. +50
    -0
      templates/_header.ejs
  4. +23
    -0
      templates/_pagination.ejs
  5. +26
    -0
      templates/index.ejs
  6. +39
    -0
      templates/search.ejs

+ 18
- 0
page.js View File

@ -0,0 +1,18 @@
const fs = require('fs')
const ejs = require('ejs')
const Bluebird = require('bluebird')
const readFileAsync = Bluebird.promisify(fs.readFile)
async function render(name, data) {
const tmplPath = `${__dirname}/templates/${name}.ejs`
const buffer = await readFileAsync(tmplPath)
const tmpl = buffer.toString()
return ejs.render(tmpl, data, {
views: [ `${__dirname}/templates` ]
})
}
module.exports = {
render
}

+ 5
- 0
templates/_footer.ejs View File

@ -0,0 +1,5 @@
<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
</body>
</html>

+ 50
- 0
templates/_header.ejs View File

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Basic Page Needs
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta charset="utf-8">
<title>Daily Stormer Search</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- FONT
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="/css/normalize.css">
<link rel="stylesheet" href="/css/skeleton.css">
<!-- Favicon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="apple-touch-icon-precomposed" sizes="57x57" href="/images/apple-touch-icon-57x57.png" />
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/images/apple-touch-icon-114x114.png" />
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/images/apple-touch-icon-72x72.png" />
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/images/apple-touch-icon-144x144.png" />
<link rel="apple-touch-icon-precomposed" sizes="60x60" href="/images/apple-touch-icon-60x60.png" />
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="/images/apple-touch-icon-120x120.png" />
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="/images/apple-touch-icon-76x76.png" />
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="/images/apple-touch-icon-152x152.png" />
<link rel="icon" type="image/png" href="/images/favicon-196x196.png" sizes="196x196" />
<link rel="icon" type="image/png" href="/images/favicon-96x96.png" sizes="96x96" />
<link rel="icon" type="image/png" href="/images/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="/images/favicon-16x16.png" sizes="16x16" />
<link rel="icon" type="image/png" href="/images/favicon-128.png" sizes="128x128" />
<meta name="application-name" content="Daily Stormer Search"/>
<meta name="msapplication-TileColor" content="#FFFFFF" />
<meta name="msapplication-TileImage" content="/images/mstile-144x144.png" />
<meta name="msapplication-square70x70logo" content="/images/mstile-70x70.png" />
<meta name="msapplication-square150x150logo" content="/images/mstile-150x150.png" />
<meta name="msapplication-wide310x150logo" content="/images/mstile-310x150.png" />
<meta name="msapplication-square310x310logo" content="/images/mstile-310x310.png" />
</head>
<body>

+ 23
- 0
templates/_pagination.ejs View File

@ -0,0 +1,23 @@
<section class="pagination" >
<div class="container" >
<div class="row" style="padding-bottom: 2rem" >
<div class="one column" >
</div>
<div class="ten columns" >
<% for (let i = 1; i <= totalPages; i++) { %>
<% if (i == p) { %>
<span><%- i %></span>&nbsp;
<% } else { %>
<a href="/search?q=<%= q %>&p=<%= i %>"><%- i %></a>&nbsp;
<% } %>
<% } %>
</div>
<div class="one column" >
</div>
</div>
<div class="row" >
<h4>Results: <%- count %></h4>
<h4>Pages: <%- totalPages %></h4>
</div>
</div>
</section>

+ 26
- 0
templates/index.ejs View File

@ -0,0 +1,26 @@
<%- include('_header') -%>
<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<section id="search-form" style="margin-top: 25%" >
<div class="container">
<div class="row">
<div class="twelve columns" >
<h1>Daily Stormer Search</h1>
</div>
</div>
<div class="row" >
<form method="GET" action="search" >
<div class="six columns" >
<input type="text" name="q" class="u-full-width" />
</div>
<div class="six columns" >
<input type="submit" class="button-primary" value="Search" />
</div>
</form>
</div>
</div>
</section>
<%- include('_footer') -%>

+ 39
- 0
templates/search.ejs View File

@ -0,0 +1,39 @@
<%- include('_header') -%>
<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<section id="search-form">
<div class="container">
<div class="row">
<div class="twelve columns" >
<h1 class="top"><a href="/" style="text-decoration: none; text-color: black;" >Daily Stormer Search</a></h1>
</div>
</div>
<div class="row" >
<form method="GET" action="search" >
<div class="six columns" >
<input type="text" name="q" value="<%- rawQ.replace(/\+/g, ' ') %>" class="u-full-width" />
</div>
<div class="six columns" >
<input type="submit" class="button-primary" value="Search" />
</div>
</form>
</div>
</div>
</section>
<section id="search-results" style="margin-top: 5%" >
<div class="container">
<% results.forEach((r) => { %>
<div class="row">
<h5><a href="https://dailystormer.su<%- r.slug %>"><%- r.title %></a></h5>
<div class="author"><b><%- r.author %></b></div>
<p><%- r.snippet %></p>
</div>
<% }); %>
</div>
</section>
<%- include('_pagination') %>
<%- include('_footer') -%>

Loading…
Cancel
Save