Finish initial script
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
"postTypes": [
|
||||
{
|
||||
"name": "Now Burning",
|
||||
"postUnitName": "incense",
|
||||
"contentEnabled": true,
|
||||
"frontMatter": [
|
||||
{
|
||||
@ -18,28 +19,9 @@
|
||||
"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/"
|
||||
"postDirectory": ""
|
||||
}
|
||||
],
|
||||
"uploadCommand": "update-website",
|
||||
"siteDirectory": "/home/n_u/Repos/nathanupchurch.com/"
|
||||
"uploadCommand": "",
|
||||
"siteDirectory": ""
|
||||
}
|
||||
|
19
poaster.rb
19
poaster.rb
@ -18,32 +18,37 @@ end
|
||||
# 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:'
|
||||
# Set the word we will use to refer to the post
|
||||
post_unit = post_type['postUnitName']
|
||||
|
||||
# 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']}:)) })
|
||||
frontmatter.push({ item['name'] => spawn_input_box(%(#{dialog_title_prefix} - Enter Frontmatter'), %(Enter #{post_unit} #{item['name']}:)) })
|
||||
end
|
||||
|
||||
# Collect post content from user
|
||||
post_content = spawn_input_box %(#{dialog_title_prefix} - Enter Content), 'Enter post content:'
|
||||
post_content = spawn_input_box %(#{dialog_title_prefix} - Enter Content), %(Enter #{post_unit} 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 = %(---\n)
|
||||
post_id = ''
|
||||
frontmatter.each_with_index do |item, i|
|
||||
post += %(#{item.keys[0]}: #{item[item.keys[0]]})
|
||||
post_id += %(#{item[item.keys[0]].chomp}#{i == frontmatter.length - 1 ? '' : '_'})
|
||||
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'
|
||||
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
|
||||
|
||||
# Run build and upload commands
|
||||
`cd #{config_data['siteDirectory']} && #{config_data['buildCommand']} && #{config_data['uploadCommand']}`
|
||||
|
Reference in New Issue
Block a user