~swisschili/blackjack

6f6ae0c0f78e439578419fe637d5179398384504 — swissChili 8 months ago 812b33b
Add docs
5 files changed, 60 insertions(+), 9 deletions(-)

M .gitignore
A blackjack-0.1.0-1.rockspec
M blackjack.lua
A docs/build.lua
M site.lua
M .gitignore => .gitignore +1 -0
@@ 2,3 2,4 @@ site
templates
content
static
!docs

A blackjack-0.1.0-1.rockspec => blackjack-0.1.0-1.rockspec +21 -0
@@ 0,0 1,21 @@
package = "blackjack"
version = "0.1.0-1"
source = {
   url = "https://git.sr.ht/~swisschili/blackjack"
}
description = {
   summary = "Blackjack is a simple and extremely extensible static site generator written in lua.",
   detailed = [[
Blackjack is a simple and extremely extensible static site generator
written in lua.
]],
   homepage = "https://blackjack.swisschili.sh",
   license = "GPL-3.0"
}
dependencies = {}
build = {
   type = "builtin",
   modules = {
      blackjack = "blackjack.lua"
   }
}

M blackjack.lua => blackjack.lua +21 -7
@@ 29,11 29,11 @@ function htmlProcessor(site, template, parameters)
  return template
end

function lmlProcessor(site, template, parameters)
function mdProcessor(site, temp, parameters)
  local parent = ""
  -- @ must be at start of a line, so adding \n makes it work at
  -- the start of a file.
  template = '\n' .. template
  local template = '\n' .. temp
  -- @key = value
  template = template:gsub("\n%s*@([%w%._]+)%s*=%s*([%w%._]+)",
    function (k, v)


@@ 63,6 63,10 @@ function lmlProcessor(site, template, parameters)
    return parameters[word]
  end)

  template = template:gsub("```\n+(.-)\n+```", function (code)
    return "<pre><code class>" .. code .. '</code></pre>'
  end)

  template = template:match( "^%s*(.-)%s*$"):gsub("\n\n+", "\n<br>\n")

  if parent ~= "" then


@@ 114,11 118,21 @@ Site = {
  static = nil,
  -- File processor objects
  processors = {
    html = htmlProcessor,
    lml = lmlProcessor
    html = {
      process = htmlProcessor,
      extension = 'html'
    },
    md = {
      process = mdProcessor,
      extension = 'html'
    }
  }
}

local function getExtension(file)
  return file:match(".(%w+)$")
end

function Site:renderTemplate(templateFile, body)
  local fp = self.templates .. '/' .. templateFile
  return self:render(fp, body)


@@ 129,8 143,8 @@ function Site:render(fp, body)
  if f ~= nil then
    local text = f:read("all")
    f:close()
    local extension = fp:match(".(%w+)$")
    return self.processors[extension](self, text, body)
    local extension = getExtension(fp)
    return self.processors[extension].process(self, text, body)
  else
    print("    Error: Tried to open template that does not exist")
    print(fp)


@@ 152,7 166,7 @@ function Site:build()
    print(" Building: ".. file)
    local html = self:render(file, {})
    local outFile = self.output .. '/' .. getFileName(
      replaceExtension(file, 'html')
      replaceExtension(file, self.processors[getExtension(file)].extension)
    )
    print("  Writing: " .. outFile)
    local file = io.open(outFile, "w")

A docs/build.lua => docs/build.lua +9 -0
@@ 0,0 1,9 @@
require "blackjack"

site = Site
site.processors.scss = {
  process = cmdProcessor("sass -"),
  extension = "css"
}

site:build()

M site.lua => site.lua +8 -2
@@ 3,7 3,13 @@ require "blackjack"
local wordCountProcessor = cmdProcessor("wc -l")
local verbatimProcessor = cmdProcessor("cat")
local mySite = Site
mySite.processors.lc = wordCountProcessor
mySite.processors.vb = verbatimProcessor
mySite.processors.lc = {
  process = wordCountProcessor,
  extension = "txt"
}
mySite.processors.vb = {
  process = verbatimProcessor,
  extension = "html"
}

mySite:build()