hscc

The personnal website source code of Hugo Soucy. Creates from an homebrewed static website generator.
Log | Files | Refs

commit 8de03a7ac483bbaed0a11fbbef2b753a3a971eb5
parent b3c6083598905153c47dda984f2d85b38c851a37
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Sun,  8 Nov 2020 09:03:55 -0500

Add a script to create notes

Diffstat:
Aarchetypes/note.lua.mustache | 7+++++++
Aarchetypes/note.md.mustache | 1+
Abin/note | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/archetypes/note.lua.mustache b/archetypes/note.lua.mustache @@ -0,0 +1,7 @@ +return { +title = "{{ title }}", +date = "{{ date }}", +datetime = "{{ datetime }}", +posttype = "note", +keywords = { {{#keywords}}"{{.}}",{{/keywords}} } +} diff --git a/archetypes/note.md.mustache b/archetypes/note.md.mustache @@ -0,0 +1 @@ +{{{ title }}} diff --git a/bin/note b/bin/note @@ -0,0 +1,68 @@ +#!/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 note_title + local note_keywords + local note_keywords_table = {} + local note_lua_file + local note_md_file + local note_name + local note_dir + + -- Set the title of the note + repeat + io.write('Please enter the title of the note: \n') + io.flush() + + note_title=io.read() + + tostring(note_title) + until string.len(note_title) > 0 + + -- Set the keywords of the note + repeat + io.write('Please enter the KEYWORDS of the note: \n') + io.flush() + + note_keywords=io.read() + + tostring(note_keywords) + until string.len(note_keywords) > 0 + + -- Convert to table + for keyword in string.gmatch(note_keywords, '([^,]+)') do + table.insert(note_keywords_table, keyword) + end + + -- Set the structure of the data file + local note_model = { + title = note_title, + date = os.date('%Y-%m-%d'), + datetime = os.date('%H:%M:%S'), + posttype = "note", + keywords = note_keywords_table + } + + -- Render the markdown file + note_md_file = lustache:render(file.read('archetypes/note.md.mustache'), note_model) + + -- Render the lua data file + note_lua_file = lustache:render(file.read('archetypes/note.lua.mustache'), note_model) + note_name = slugify(note_title) + note_dir = 'content/' .. os.date('%Y') .. '/nt/' + + -- Make the directory + file.mkdir(note_dir) + -- Make the lua file + file.write(note_dir .. note_name .. '.lua', note_lua_file) + -- Make the lua file + file.write(note_dir .. note_name .. '.md', note_md_file) + + return +end