hscc

Soure code of <https://hugo.soucy.cc>.
git clone git://soucy.cc/hscc.git
Log | Files | Refs

reply (2207B)


      1 #!/usr/bin/env lua
      2 do
      3     --
      4     package.path = package.path .. ';'.. arg[0]:match("(.*/)") ..'/?.lua'
      5     --
      6     local inspect = require 'inspect'
      7     --local htmlparser = require 'htmlparser'
      8     local lustache = require 'lustache'
      9     local file = require 'utils.file'
     10     local slugify = require 'utils.slugify'
     11 
     12     local reply_title
     13     local reply_url
     14     local reply_lua_file
     15     local reply_md_file
     16     local reply_name
     17     local reply_dir
     18 
     19     -- Set the TITLE of the reply
     20     repeat
     21         io.write('Please enter the title of the reply: \n')
     22         io.flush()
     23 
     24         reply_title=io.read()
     25 
     26         tostring(reply_title)
     27     until string.len(reply_title) > 0
     28 
     29     -- Set the URL of the reply
     30     repeat
     31         io.write('Please enter the URL the content to reply to: \n')
     32         io.flush()
     33 
     34         reply_url=io.read()
     35 
     36         tostring(reply_url)
     37     until string.len(reply_url) > 0
     38 
     39     -- local function get_econtent()
     40     --   local _file = assert(io.popen('curl ' .. reply_url))
     41     --   local data =  assert(_file:read("*a"))
     42     --   local root = htmlparser.parse(data)
     43     --   local elements = root:select(".detailed-status:first")
     44     --   local e_content
     45 
     46     --   _file:close()
     47 
     48     --   for _, e in ipairs(elements) do
     49     --     e_content = e:getcontent()
     50     --   end
     51 
     52     --   return e_content
     53     -- end
     54 
     55     -- Set the structure of the data file
     56     local reply_model = {
     57         title = reply_title,
     58         url = reply_url,
     59         date = os.date('%Y-%m-%d'),
     60         datetime = os.date('%H:%M:%S'),
     61         posttype = "reply",
     62         --inreplyto = get_econtent() or nil
     63     }
     64 
     65     -- Render the markdown file
     66     reply_md_file = lustache:render(file.read('archetypes/reply.md.mustache'), reply_model)
     67 
     68     -- Render the lua data file
     69     reply_lua_file = lustache:render(file.read('archetypes/reply.lua.mustache'), reply_model)
     70     reply_name = slugify(reply_title)
     71     reply_dir = 'content/' .. os.date('%Y') .. '/rp/'
     72 
     73     -- Make the directory
     74     file.mkdir(reply_dir)
     75     -- Make the lua file
     76     file.write(reply_dir .. reply_name .. '.lua', reply_lua_file)
     77     -- Make the lua file
     78     file.write(reply_dir .. reply_name .. '.md', reply_md_file)
     79 
     80     return
     81 end