Class: JekyllShorts::Generator::ShortFile
- Inherits:
-
Jekyll::StaticFile
- Object
- Jekyll::StaticFile
- JekyllShorts::Generator::ShortFile
- Defined in:
- lib/jekyll-shorts/generator.rb
Overview
The HTML file with a redirect.
Instance Method Summary collapse
-
#initialize(site, short, long) ⇒ ShortFile
constructor
A new instance of ShortFile.
- #write(_dest) ⇒ Object
Constructor Details
#initialize(site, short, long) ⇒ ShortFile
Returns a new instance of ShortFile.
70 71 72 73 |
# File 'lib/jekyll-shorts/generator.rb', line 70 def initialize(site, short, long) super(site, site.dest, '', short) @long = long end |
Instance Method Details
#write(_dest) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/jekyll-shorts/generator.rb', line 75 def write(_dest) FileUtils.mkdir_p(File.dirname(path)) html = "<html><head><meta charset='utf-8'/>\ <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>\ <meta http-equiv='refresh' content='#{@long}'/></head></html>" if File.exist?(path) before = File.read(path) if before != html raise "It's impossible to generate a short link at #{path.inspect}, \ because the file already exists and the content \ of the it differs from what we are going to write into it now (#{long}). This most \ probably means that previously generated short link will point to a different location \ than before. Try to run 'jekyll clean', it will help, if you know what you are doing." end else File.write(path, html) Jekyll.logger.debug("HTML #{path.inspect} -> #{@long.inspect}") end true end |