Skip to content

Instantly share code, notes, and snippets.

@simonszu
Created August 29, 2017 12:29
Show Gist options
  • Save simonszu/7167c32daa4777a9f54cba74924423b5 to your computer and use it in GitHub Desktop.
Save simonszu/7167c32daa4777a9f54cba74924423b5 to your computer and use it in GitHub Desktop.
Sorting Hugo markdown based posts into subfolder according to their year in the date-header-tag
#! /usr/bin/env ruby
require 'fileutils'
posts = Dir.glob("blog/content/post/*.md")
posts.each do |item|
File.open(item, "r").each do |line|
if line =~ /^date = (\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+).*/
year = $1
puts "#{item}: #{year}"
FileUtils.mv(item, "blog/content/post/#{year}")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment