Skip to content

Instantly share code, notes, and snippets.

@linguofeng
Created November 26, 2012 09:18
Show Gist options
  • Save linguofeng/4147348 to your computer and use it in GitHub Desktop.
Save linguofeng/4147348 to your computer and use it in GitHub Desktop.
jekyll generate tag
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
@linguofeng
Copy link
Author

{{ site | generateTag }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment