Created
November 26, 2012 09:18
-
-
Save linguofeng/4147348 to your computer and use it in GitHub Desktop.
jekyll generate 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
module Jekyll | |
module Filters | |
# 生成Tag | |
def generateTag(site) | |
site['tags'].keys.each do |tag| | |
_path = site['source'] + '/tag/' + tag | |
_file = _path + '/index.textile' | |
if !File.exist?(_file) then | |
FileUtils.mkdir_p _path | |
aFile = File.new(_file, 'w') | |
aFile.puts '---' | |
aFile.puts 'layout: tag' | |
aFile.puts 'title: ' + tag | |
aFile.puts 'tag: ' + tag | |
aFile.puts '---' | |
aFile.close | |
end | |
end | |
deleteNullTag(site) | |
end | |
# 删除不存在的Tag | |
def deleteNullTag(site) | |
Dir.foreach(site['source'] + '/tag/') { | |
|tagdir| | |
if '.' != tagdir && '..' != tagdir then | |
if !site['tags'].keys.include?(tagdir) then | |
FileUtils.rm_rf site['source'] + '/tag/' + tagdir + '/' | |
end | |
end | |
} | |
end | |
end | |
end |
Author
linguofeng
commented
Nov 26, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment