-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_blog.rb
28 lines (23 loc) · 816 Bytes
/
config_blog.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true
# script to update the blog build config
require 'yaml'
posts = './_posts'
post_directory = Dir[File.join(posts, '**', '*')]
stripped_post_directory = post_directory.map do |post|
post.slice(2, post.size)
end
post_count = stripped_post_directory.count
config_paths = ['./_config-blog.yml', './_config-accesslint.yml']
config_paths.each do |config|
frontmatter = YAML.load_file(config)
# Delete all '_posts/'
frontmatter['exclude'].delete_if { |x| x.include?('_posts/') }
# Add all posts back to exclude
stripped_post_directory.each do |post|
frontmatter['exclude'] << post
end
# Remove the last two posts
frontmatter['exclude'] = frontmatter['exclude'][0...-2]
frontmatter_new = YAML.dump(frontmatter) << "---\n\n"
File.write(config, frontmatter_new)
end