require "jekyll"
require "liquid"
module Jekyll
class RenderTimeTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render(context)
"#{@text} #{Time.now}"
end
end
class EmptyTag < Liquid::Tag
def initialize(tag_name, text, tokens)
end
def render(context)
""
end
end
class AssetImg < Liquid::Tag
def initialize(tag_name, text, tokens)
arr = text.strip.split(" ")
@img_name = arr[0]
@img_width = nil
if arr.count > 1
@img_width = arr[1]
end
end
def render(context)
path = context['page']['path']
dirPath0 = path[0...(path.length - 3)]
pathComponent = dirPath0.split("/")
dirPath = pathComponent[-1]
base = $g_config['baseurl']
link = "/pics/#{dirPath}/#{@img_name}"
if base && base.length
link = "#{base}/pics/#{dirPath}/#{@img_name}"
end
if @img_width != nil
return ""
else
return "![](#{link})"
end
end
end
class ImgLink < Liquid::Tag
def initialize(tag_name, text, tokens)
arr = text.strip.split(' ',2)
if arr.count == 2
@img_name = arr[1]
@title = arr[0]
else
@img_name = arr[0]
@title = "img_link"
end
end
def render(context)
path = context['page']['path']
dirPath0 = path[0...(path.length - 3)]
pathComponent = dirPath0.split("/")
dirPath = pathComponent[-1]
base = $g_config['baseurl']
link = "/pics/#{dirPath}/#{@img_name}"
if base && base.length
link = "#{base}/pics/#{dirPath}/#{@img_name}"
end
return "[#{@title}](#{link})"
end
end
$g_title_link ||= {}
LOADINGFLG = :LOADINGFLG
class PostLink < Liquid::Tag
def initialize(tag_name, text, tokens)
@linkTitle = text.strip
# page = Jekyll::sites[0].pages.find { |pg|
# pg.name == @linkTitle
# }
end
def render(context)
# puts 'zzaa',context['site']['posts'][1].data,"zz"
url = $g_title_link[@linkTitle]
if url == nil || url == LOADINGFLG
$g_title_link[@linkTitle] = LOADINGFLG
return "`#{@linkTitle} Not Found`"
else
if $g_config["baseurl"] && $g_config["baseurl"].length > 0
return "[#{@linkTitle}](#{$g_config["baseurl"]}/#{url})"
else
return "[#{@linkTitle}](#{url})"
end
end
end
end
class IncludeCode < Liquid::Tag
@filecontent = ""
def initialize(tag_name, text, tokens)
rootPath = $g_config['code_root_path'] || 'static'
filePath = "#{rootPath}/#{text}".strip!()
begin
file = File.open(filePath)
@filecontent = file.read()
rescue => exception
puts exception
@filecontent = "load file:#{text} failed"
end
end
def render(context)
s="``````"
r= < 0
puts "rebuild" , $auto_gen_tag_flag
$auto_gen_tag_flag = 0
st.process
end
end
Jekyll::Hooks.register :site, :after_init do |st|
# code to call after Jekyll renders a page
filename = 'index.html'
if !File.file?(filename)
tagTmp = "---\nlayout: paginate\n---"
File.open(filename , 'w+') { |f| f.write(tagTmp) }
print 'generate ' + filename
end
end
end