Finish initial script
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
"postTypes": [
|
"postTypes": [
|
||||||
{
|
{
|
||||||
"name": "Now Burning",
|
"name": "Now Burning",
|
||||||
|
"postUnitName": "incense",
|
||||||
"contentEnabled": true,
|
"contentEnabled": true,
|
||||||
"frontMatter": [
|
"frontMatter": [
|
||||||
{
|
{
|
||||||
@@ -18,28 +19,9 @@
|
|||||||
"name": "time"
|
"name": "time"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"postDirectory": "/home/n_u/Repos/nathanupchurch.com/content/now_burning/"
|
"postDirectory": ""
|
||||||
},
|
|
||||||
{
|
|
||||||
"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": "",
|
||||||
}
|
"siteDirectory": ""
|
||||||
],
|
|
||||||
"uploadCommand": "update-website",
|
|
||||||
"siteDirectory": "/home/n_u/Repos/nathanupchurch.com/"
|
|
||||||
}
|
}
|
||||||
|
19
poaster.rb
19
poaster.rb
@@ -18,32 +18,37 @@ end
|
|||||||
# Display post list dialog to user
|
# 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))]
|
post_type = config_data['postTypes'][Integer(spawn_radio_list(dialog_title_prefix, 'Select a post type:', post_types_arr))]
|
||||||
|
|
||||||
# Collect post ID from user
|
# Set the word we will use to refer to the post
|
||||||
post_id = spawn_input_box %(#{dialog_title_prefix} - Enter Post ID), 'Enter post ID:'
|
post_unit = post_type['postUnitName']
|
||||||
|
|
||||||
# Collect frontmatter from user
|
# Collect frontmatter from user
|
||||||
frontmatter = []
|
frontmatter = []
|
||||||
post_type['frontMatter'].each do |item|
|
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
|
end
|
||||||
|
|
||||||
# Collect post content from user
|
# 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
|
# Make sure the output folder exists
|
||||||
post_directory = post_type['postDirectory']
|
post_directory = post_type['postDirectory']
|
||||||
ensure_dir_exists(post_directory)
|
ensure_dir_exists(post_directory)
|
||||||
|
|
||||||
# Create post string
|
# Create post string
|
||||||
post = '---'
|
post = %(---\n)
|
||||||
frontmatter.each do |item|
|
post_id = ''
|
||||||
|
frontmatter.each_with_index do |item, i|
|
||||||
post += %(#{item.keys[0]}: #{item[item.keys[0]]})
|
post += %(#{item.keys[0]}: #{item[item.keys[0]]})
|
||||||
|
post_id += %(#{item[item.keys[0]].chomp}#{i == frontmatter.length - 1 ? '' : '_'})
|
||||||
end
|
end
|
||||||
post += %(---\n#{post_content})
|
post += %(---\n#{post_content})
|
||||||
|
|
||||||
# Write post string to file and notify user
|
# Write post string to file and notify user
|
||||||
post_file_name = %(#{post_type['name']}_#{post_id.chomp})
|
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
|
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
|
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