~ryanford/git-blog-tup

dada3bc17af0fc41149e3cdb5838eef2be9000cd — Ryan Ford 3 years ago e3228fb
move render logic into to_html
2 files changed, 40 insertions(+), 27 deletions(-)

M plugins/to_html
M src/assets/scss/post.scss
M plugins/to_html => plugins/to_html +39 -26
@@ 1,9 1,9 @@
#!/usr/bin/env lua

local date = require("date")
local etlua = require("etlua")
local json = require("dkjson")

local null = json.null

local input = io.input(arg[1])
local output = io.output(arg[2])



@@ 13,10 13,10 @@ local template = [[
<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width">
   <title><%= title %> | @SITENAME@</title>
   <title><%= post.title or "Untitled" %> | @SITENAME@</title>
   <link rel="stylesheet" href="../assets/css/main.css">
   <link rel="stylesheet" href="../assets/css/post.css">
   <% for _, stylesheet in ipairs(css) do %>
   <% for _, stylesheet in ipairs(post.css or {}) do %>
   <link rel="stylesheet" href="../assets/css/<%- stylesheet %>">
   <% end %>
</head>


@@ 26,43 26,47 @@ local template = [[
   </header>
   <div class="content-wrapper">
      <nav class="post-nav">
         <% if prev_post then %>
         <span><a href="<%- prev_post:gsub("md$", "html") %>">prev</a></span>
         <% if post.prev_post then %>
         <span><a href="<%- post.prev_post:gsub("md$", "html") %>">prev</a></span>
         <% else %>
         <span class="spacer"></span>
         <% end %>
         <span><a href="../index.html">up</a></span>
         <% if next_post then %>
         <span><a href="<%- next_post:gsub("md$", "html") %>">next</a></span>
         <% if post.next_post then %>
         <span><a href="<%- post.next_post:gsub("md$", "html") %>">next</a></span>
         <% else %>
         <span class="spacer"></span>
         <% end %>
      </nav>
      <hr>
      <article>
         <h1><%- title %></h1>
         <% if author then %>
         <h1><%- post.title or "untitled" %></h1>
         <% if post.author then %>
         <div class="author">
            Submitted by: <%- author %>
            Submitted by: <%- post.author or "anonymous" %>
         </div>
         <% end %>
         <div class="created-date">
            Published: <%- created %>
         <div class="published-date">
            <% if post.published then %>
            Published: <%- post.published %>
            <% else %>
            Draft
            <% end %>
         </div>
         <% if #commits > 1 then %>
         <% if #post.commits > 1 then %>
         <div class="modified-date">
            Updated: <%- commits[1].date %>
            Updated: <%- post.commits[1].date %>
         </div>
         <% end %>
         <hr>
         <%- body %>
      </article>
      <% if #commits > 1 then %>
      <% if #post.commits > 1 then %>
         <hr>
         <h4>Changelog</h4>
         <ul class="changelog">
            <% for i = 1, #commits - 1 do %>
            <% local commit = commits[i] %>
            <% for i = 1, #post.commits - 1 do %>
            <% local commit = post.commits[i] %>
            <li>
               <span><a href="@REPO@/commit/<%= commit.hash %>"><%= commit.hash %></a> - <%= commit.author %></span>
               <span><%= commit.date %></span>


@@ 73,32 77,41 @@ local template = [[
      <% end %>
      <hr>
      <nav class="post-nav">
         <% if prev_post then %>
         <span><a href="<%- prev_post:gsub("md$", "html") %>">prev</a></span>
         <% if post.prev_post then %>
         <span><a href="<%- post.prev_post:gsub("md$", "html") %>">prev</a></span>
         <% else %>
         <span></span>
         <% end %>
         <span><a href="../index.html">up</a></span>
         <% if next_post then %>
         <span><a href="<%- next_post:gsub("md$", "html") %>">next</a></span>
         <% if post.next_post then %>
         <span><a href="<%- post.next_post:gsub("md$", "html") %>">next</a></span>
         <% else %>
         <span></span>
         <% end %>
      </nav>
   </div>
   <footer>
      <span>Page generated <%= generated %> using <a href="https://git.sr.ht/~ryanford/git-blog-tup">git-blog-tup</a></span>
      <span class="copyright"><%- copyright %></span>
      <span>Page generated <%= current_date %> using <a href="https://git.sr.ht/~ryanford/git-blog-tup">git-blog-tup</a></span>
      <span class="copyright"><%- "&copy; " .. current_year .. " @OWNER@" %></span>
   </footer>
</body>
</html>]]

local str = input:read("*a")
if arg[1] then input:close() end

local post = assert(json.decode(str))
post.test_markdown = test_markdown

local html = assert(etlua.render(template, post))
local env do
   local t = os.time()
   env = {
      post = post,
      current_date = date(t):fmt("%b %d, %Y"),
      current_year = date(t):fmt("%Y"),
   }
end

local html = assert(etlua.render(template, env))

output:write(html)
if arg[2] then output:close() end

M src/assets/scss/post.scss => src/assets/scss/post.scss +1 -1
@@ 46,7 46,7 @@ header {
    font-size: 0.875rem;
  }

  .created-date {
  .published-date {
    font-size: 0.875rem;
  }