Skip to content

Commit

Permalink
plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
sumanthpabbati committed Jan 16, 2025
1 parent 8b408cf commit 4b76410
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
34 changes: 23 additions & 11 deletions _plugins/enclosure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,44 @@

module Jekyll
class EnclosureTag < Liquid::Tag

def initialize(tag_name, text, tokens)
super
@text = text
end

def render(context)
path = Liquid::Template.parse(@text).render(context).strip
if path
site = context.registers[:site]
size=0
type=''
size = 0
type = ''

if path.start_with?('http')
response = http.request_head(path)
size = response['content-length']
type = response['content-type']
uri = URI(path)
response = Net::HTTP.get_response(uri)

if response.is_a?(Net::HTTPSuccess)
size = response['content-length']
type = response['content-type']
else
raise "Failed to fetch resource: #{response.message}"
end
else
size = File.size(Dir.pwd + path)
type = `file --mime-type -b #{Dir.pwd + path}`.gsub(/\n/,"")
path = site.config["url"] + site.baseurl + path
full_path = File.join(Dir.pwd, path)
if File.exist?(full_path)
size = File.size(full_path)
type = `file --mime-type -b #{full_path}`.strip
path = File.join(site.config["url"], site.baseurl, path)
else
raise "File not found: #{full_path}"
end
end

"<enclosure url=\"#{path}\" length=\"#{size}\" type=\"#{type}\" />"
end
end
end
end

Liquid::Template.register_tag('enclosure', Jekyll::EnclosureTag)

2 changes: 1 addition & 1 deletion assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pre {


.text-black:hover {
color: #444
color: #474343
}


Expand Down

0 comments on commit 4b76410

Please sign in to comment.