commit 8f59d669d9e134d59c48967e456e72af25102795
parent 759ef0fdb4d5bc1c4c82fd08c6d005da5931e491
Author: Hugo Soucy <hugo@soucy.cc>
Date: Fri, 13 Nov 2020 20:10:04 -0500
Add a new script for create pages
Diffstat:
3 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/archetypes/page.lua.mustache b/archetypes/page.lua.mustache
@@ -0,0 +1,5 @@
+return {
+title = "{{ title }}",
+date = "{{ date }}",
+datetime = "{{ datetime }}",
+}
diff --git a/archetypes/page.md.mustache b/archetypes/page.md.mustache
@@ -0,0 +1 @@
+{{{ title }}}
diff --git a/bin/page b/bin/page
@@ -0,0 +1,47 @@
+#!/usr/bin/env lua
+do
+ --
+ package.path = package.path .. ';'.. arg[0]:match("(.*/)") ..'/?.lua'
+ --
+ local lustache = require 'lustache'
+ local file = require 'utils.file'
+ local slugify = require 'utils.slugify'
+
+ local page_title
+ local page_lua_file
+ local page_md_file
+ local page_name
+ local page_dir
+
+ -- Set the TITLE of the page
+ repeat
+ io.write('Please enter the title of the page: \n')
+ io.flush()
+
+ page_title=io.read()
+
+ tostring(page_title)
+ until string.len(page_title) > 0
+
+ -- Set the structure of the data file
+ local page_model = {
+ title = page_title,
+ date = os.date('%Y-%m-%d'),
+ datetime = os.date('%H:%M:%S')
+ }
+
+ -- Render the markdown file
+ page_md_file = lustache:render(file.read('archetypes/page.md.mustache'), page_model)
+
+ -- Render the lua data file
+ page_lua_file = lustache:render(file.read('archetypes/page.lua.mustache'), page_model)
+ page_name = slugify(page_title)
+ page_dir = 'content/'
+
+ -- Make the lua file
+ file.write(page_dir .. page_name .. '.lua', page_lua_file)
+ -- Make the markdown file
+ file.write(page_dir .. page_name .. '.md', page_md_file)
+
+ return
+end