Changes
This commit is contained in:
parent
ee7c4c9560
commit
fad2223495
45
config/config.json
Normal file
45
config/config.json
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
"buildCommand": "npx @11ty/eleventy",
|
||||
"postTypes": [
|
||||
{
|
||||
"name": "Now Burning",
|
||||
"contentEnabled": true,
|
||||
"frontMatter": [
|
||||
{
|
||||
"name": "title"
|
||||
},
|
||||
{
|
||||
"name": "manufacturer"
|
||||
},
|
||||
{
|
||||
"name": "date"
|
||||
},
|
||||
{
|
||||
"name": "time"
|
||||
}
|
||||
],
|
||||
"postDirectory": "/home/n_u/Repos/nathanupchurch.com/content/now_burning/"
|
||||
},
|
||||
{
|
||||
"name": "Now Listening",
|
||||
"contentEnabled": true,
|
||||
"frontMatter": [
|
||||
{
|
||||
"name": "title"
|
||||
},
|
||||
{
|
||||
"name": "artist"
|
||||
},
|
||||
{
|
||||
"name": "date"
|
||||
},
|
||||
{
|
||||
"name": "time"
|
||||
}
|
||||
],
|
||||
"postDirectory": "/home/n_u/Repos/nathanupchurch.com/content/now_listening/"
|
||||
}
|
||||
],
|
||||
"uploadCommand": "update-website",
|
||||
"siteDirectory": "/home/n_u/Repos/nathanupchurch.com/"
|
||||
}
|
6
lib/ensure_dir_exists.rb
Normal file
6
lib/ensure_dir_exists.rb
Normal file
@ -0,0 +1,6 @@
|
||||
def ensure_dir_exists(directory_path)
|
||||
unless Dir.exist?(directory_path)
|
||||
FileUtils.mkdir_p(directory_path)
|
||||
spawn_toast 'Directory Created', %(Poaster created #{directory_path}.), 10
|
||||
end
|
||||
end
|
3
lib/spawn_input_box.rb
Normal file
3
lib/spawn_input_box.rb
Normal file
@ -0,0 +1,3 @@
|
||||
def spawn_input_box(title, text)
|
||||
`kdialog --title "#{title}" --inputbox "#{text}"`
|
||||
end
|
7
lib/spawn_radio_list.rb
Normal file
7
lib/spawn_radio_list.rb
Normal file
@ -0,0 +1,7 @@
|
||||
def spawn_radio_list(title, text, options_arr)
|
||||
command = %(kdialog --title "#{title}" --radiolist "#{text}")
|
||||
options_arr.each_with_index do |option, i|
|
||||
command += %( #{i} "#{option}" off)
|
||||
end
|
||||
`#{command}`
|
||||
end
|
3
lib/spawn_toast.rb
Normal file
3
lib/spawn_toast.rb
Normal file
@ -0,0 +1,3 @@
|
||||
def spawn_toast(title, text, seconds)
|
||||
`kdialog --title "#{title}" --passivepopup "#{text}" #{seconds}`
|
||||
end
|
5
lib/write_file.rb
Normal file
5
lib/write_file.rb
Normal file
@ -0,0 +1,5 @@
|
||||
def write_file(directory, name, extension, content)
|
||||
post_file = File.new(%(#{directory}/#{name}.#{extension}), 'w+')
|
||||
post_file.syswrite(content)
|
||||
post_file.close
|
||||
end
|
55
poaster.rb
55
poaster.rb
@ -1,16 +1,49 @@
|
||||
require 'json'
|
||||
require 'fileutils'
|
||||
require './lib/spawn_input_box'
|
||||
require './lib/spawn_radio_list'
|
||||
require './lib/spawn_toast'
|
||||
require './lib/ensure_dir_exists'
|
||||
require './lib/write_file'
|
||||
|
||||
config_file = File.read('./poasterConfig.json')
|
||||
config_data = JSON.parse(config_file)
|
||||
config_data = JSON.parse(File.read('./config/config.json'))
|
||||
dialog_title_prefix = 'Poaster'
|
||||
|
||||
post_type_radiolist_prefix = %Q[kdialog --title "Poaster" --radiolist "Select a post type:"]
|
||||
|
||||
def build_radiolist_command(prefix_string, config_data)
|
||||
command_string = prefix_string
|
||||
config_data['postTypes'].each_with_index do |type, i|
|
||||
command_string += %Q[ #{i+1} "#{type['name']}" off]
|
||||
end
|
||||
return command_string
|
||||
# Populate types_arr with post types
|
||||
post_types_arr = []
|
||||
config_data['postTypes'].each do |type|
|
||||
post_types_arr.push(type['name'])
|
||||
end
|
||||
|
||||
`#{build_radiolist_command(post_type_radiolist_prefix, config_data)}`
|
||||
# Display post list dialog to user
|
||||
post_type = config_data['postTypes'][Integer(spawn_radio_list(dialog_title_prefix, 'Select a post type:', post_types_arr))]
|
||||
|
||||
# Collect post ID from user
|
||||
post_id = spawn_input_box %(#{dialog_title_prefix} - Enter Post ID), 'Enter post ID:'
|
||||
|
||||
# Collect frontmatter from user
|
||||
frontmatter = []
|
||||
post_type['frontMatter'].each do |item|
|
||||
frontmatter.push({ item['name'] => spawn_input_box(%(#{dialog_title_prefix} - Enter Frontmatter'), %(Enter post #{item['name']}:)) })
|
||||
end
|
||||
|
||||
# Collect post content from user
|
||||
post_content = spawn_input_box %(#{dialog_title_prefix} - Enter Content), 'Enter post content:'
|
||||
|
||||
# Make sure the output folder exists
|
||||
post_directory = post_type['postDirectory']
|
||||
ensure_dir_exists(post_directory)
|
||||
|
||||
# Create post string
|
||||
post = '---'
|
||||
frontmatter.each do |item|
|
||||
post += %(#{item.keys[0]}: #{item[item.keys[0]]})
|
||||
end
|
||||
post += %(---\n#{post_content})
|
||||
|
||||
# Write post string to file and notify user
|
||||
post_file_name = %(#{post_type['name']}_#{post_id.chomp})
|
||||
post_extension = '.md'
|
||||
|
||||
write_file post_directory, post_file_name, post_extension, post
|
||||
spawn_toast 'File Created', %(Poaster created #{post_file_name}#{post_extension} at #{post_directory}.), 10
|
||||
|
@ -1,25 +0,0 @@
|
||||
{
|
||||
"buildCommand": "npx @11ty/eleventy",
|
||||
"postTypes": [
|
||||
{
|
||||
"name": "Now Burning",
|
||||
"contentEnabled": true,
|
||||
"frontMatter": [
|
||||
{
|
||||
"name": "Title",
|
||||
"allowEmpty": false,
|
||||
"inputType": "text"
|
||||
},
|
||||
{
|
||||
"name": "Date",
|
||||
"allowEmpty": false,
|
||||
"inputType": "date"
|
||||
}
|
||||
],
|
||||
"titlePrefix": "Now Burning: ",
|
||||
"titleSuffix": ""
|
||||
}
|
||||
],
|
||||
"uploadCommand": "update-website",
|
||||
"workingDirectory": "/home/n_u/Repos/nathanupchurch.com/"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user