<commit_before>local util = require 'util'
local lustache = require 'lustache'
local markdown = require 'markdown'

local fcgi = {}
local actions = {}
local template

function actions.GET(page)
    local view = {page = page}
    local text = util.read('pages/' .. page .. '.md') or
       util.read('pages/404.md')

    -- Due to unusual behavior with partials, we render twice
    view.body = lustache:render(markdown(text), view)
    -- XXX make test case, and file bug report if applicable
 
     return util.response(lustache:render(template, view))
end

function fcgi.start()
    template = util.read('layout.html')
    return 0
end

function fcgi.accept()
    local method = os.getenv('REQUEST_METHOD') or 'GET'
    local url = os.getenv('REQUEST_URI') or arg[1]
    local parts = util.split(url, '/')
    local controller = parts[0]
    local page = parts[1]

    if not page then
        page = 'home'
    end

    if not actions[method] or not controller then
        page = '404'
        method = 'GET'
    end
    
    return actions[method](page)
end

-- comment out in when running as fcgi
fcgi.start()
print(fcgi.accept())
--

return fcgi<commit_msg>Fix comment and test block<commit_after>local util = require 'util'
local lustache = require 'lustache'
local markdown = require 'markdown'

local fcgi = {}
local actions = {}
local template

function actions.GET(page)
    local view = {page = page}
    local text = util.read('pages/' .. page .. '.md') or
       util.read('pages/404.md')

    -- Due to unusual behavior with partials, we render twice
    view.body = lustache:render(markdown(text), view)
    -- XXX make test case, and file bug report if applicable
 
     return util.response(lustache:render(template, view))
end

function fcgi.start()
    template = util.read('layout.html')
    return 0
end

function fcgi.accept()
    local method = os.getenv('REQUEST_METHOD') or 'GET'
    local url = os.getenv('REQUEST_URI') or arg[1]
    local parts = util.split(url, '/')
    local controller = parts[0]
    local page = parts[1]

    if not page then
        page = 'home'
    end

    if not actions[method] or not controller then
        page = '404'
        method = 'GET'
    end
    
    return actions[method](page)
end

-- uncomment when testing or running as CGI
-- fcgi.start()
-- print(fcgi.accept())
--

return fcgi
{'fraction_non_alphanumeric': 0.11819727891156463, 'fraction_numerical': 0.008503401360544218, 'mean_word_length': 2.9151414309484194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4008186', 'n_tokens_mistral': 752, 'n_tokens_neox': 717, 'n_words': 239}