commit e5a408e4e536fc3708108bb018bb0ea88f5ce916
parent 8de03a7ac483bbaed0a11fbbef2b753a3a971eb5
Author: Hugo Soucy <hugo@soucy.cc>
Date: Tue, 10 Nov 2020 18:15:54 -0500
Add new shell script to build replies
Diffstat:
3 files changed, 86 insertions(+), 0 deletions(-)
diff --git a/archetypes/reply.lua.mustache b/archetypes/reply.lua.mustache
@@ -0,0 +1,8 @@
+return {
+title = "{{ title }}",
+url = "{{{ url }}}",
+date = "{{ date }}",
+datetime = "{{ datetime }}",
+posttype = "reply",
+replyto = [[{{{inreplyto}}}]]
+}
diff --git a/archetypes/reply.md.mustache b/archetypes/reply.md.mustache
@@ -0,0 +1 @@
+
diff --git a/bin/reply b/bin/reply
@@ -0,0 +1,77 @@
+#!/usr/bin/env lua
+do
+ --
+ package.path = package.path .. ';'.. arg[0]:match("(.*/)") ..'/?.lua'
+ --
+ local inspect = require 'inspect'
+ local gumbo = require 'gumbo'
+ local lustache = require 'lustache'
+ local file = require 'utils.file'
+ local slugify = require 'utils.slugify'
+
+ local reply_title
+ local reply_url
+ local reply_lua_file
+ local reply_md_file
+ local reply_name
+ local reply_dir
+
+ -- Set the TITLE of the reply
+ repeat
+ io.write('Please enter the title of the reply: \n')
+ io.flush()
+
+ reply_title=io.read()
+
+ tostring(reply_title)
+ until string.len(reply_title) > 0
+
+ -- Set the URL of the reply
+ repeat
+ io.write('Please enter the URL the content to reply to: \n')
+ io.flush()
+
+ reply_url=io.read()
+
+ tostring(reply_url)
+ until string.len(reply_url) > 0
+
+ local function get_e_content()
+ local _file = assert(io.popen('curl ' .. reply_url))
+ local data = assert(_file:read("*a"))
+ local document = assert(gumbo.parse(data))
+ local econtent = document:getElementsByClassName('detailed-status')[1]
+ :getElementsByClassName('e-content')[1].innerHTML
+
+ _file:close()
+
+ return econtent
+ end
+
+ -- Set the structure of the data file
+ local reply_model = {
+ title = reply_title,
+ url = reply_url,
+ date = os.date('%Y-%m-%d'),
+ datetime = os.date('%H:%M:%S'),
+ posttype = "reply",
+ inreplyto = get_e_content() or nil
+ }
+
+ -- Render the markdown file
+ reply_md_file = lustache:render(file.read('archetypes/reply.md.mustache'), reply_model)
+
+ -- Render the lua data file
+ reply_lua_file = lustache:render(file.read('archetypes/reply.lua.mustache'), reply_model)
+ reply_name = slugify(reply_title)
+ reply_dir = 'content/' .. os.date('%Y') .. '/rp/'
+
+ -- Make the directory
+ file.mkdir(reply_dir)
+ -- Make the lua file
+ file.write(reply_dir .. reply_name .. '.lua', reply_lua_file)
+ -- Make the lua file
+ file.write(reply_dir .. reply_name .. '.md', reply_md_file)
+
+ return
+end