Created
August 29, 2017 12:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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