hscc

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

add (1711B)


      1 #!/usr/bin/env lua
      2 do
      3   --
      4   package.path = package.path .. ';'.. arg[0]:match("(.*/)") ..'/?.lua'
      5   --
      6   local lustache = require 'lustache'
      7   local file = require 'satelito.file'
      8   local slugify = require 'satelito.lib.slugify'
      9 
     10   local content_title
     11   local content_url
     12   local content_lua_file
     13   local content_keywords
     14   local content_keywords_table = {}
     15   local content_md_file
     16   local content_name
     17   local content_dir
     18 
     19   -- Set the TITLE of the page
     20   repeat
     21     io.write('Please enter the title of the page: \n')
     22     io.flush()
     23 
     24     content_title=io.read()
     25 
     26     tostring(content_title)
     27   until string.len(content_title) > 0
     28 
     29   -- Set the KEYWORDS of the note
     30   repeat
     31     io.write('Please enter the KEYWORDS of the note: \n')
     32     io.flush()
     33 
     34     content_keywords=io.read()
     35 
     36     tostring(content_keywords)
     37   until string.len(content_keywords) > 0
     38 
     39   -- Convert to table
     40   for keyword in string.gmatch(content_keywords, '([^,]+)') do
     41     table.insert(content_keywords_table, keyword)
     42   end
     43 
     44   -- Set the structure of the data file
     45   local content_model = {
     46     title = content_title,
     47     date = os.date('%Y-%m-%d'),
     48     datetime = os.date('%H:%M:%S'),
     49     keywords = content_keywords_table
     50   }
     51 
     52   -- Render the markdown file
     53   content_md_file = lustache:render(file.read('archetypes/page.md.mustache'), content_model)
     54 
     55   -- Render the lua data file
     56   content_lua_file = lustache:render(file.read('archetypes/page.lua.mustache'), content_model)
     57   content_name = content_title
     58   content_dir = 'content/'
     59 
     60   -- Make the lua file
     61   file.write(content_dir .. content_name .. '.lua', content_lua_file)
     62   -- Make the markdown file
     63   file.write(content_dir .. content_name .. '.md', content_md_file)
     64 
     65   return
     66 end