diff options
Diffstat (limited to '')
-rw-r--r-- | _plugins/generate-media-permalink.rb | 61 | ||||
-rw-r--r-- | _plugins/generate-pastebin-plaintext-alternate.rb | 2 |
2 files changed, 62 insertions, 1 deletions
diff --git a/_plugins/generate-media-permalink.rb b/_plugins/generate-media-permalink.rb new file mode 100644 index 0000000..db49286 --- /dev/null +++ b/_plugins/generate-media-permalink.rb @@ -0,0 +1,61 @@ +module Jekyll + class MediaPermalinkGenerator < Generator + safe true + + MEDIA_EXTENSION = { + 'podcasts' => 'ogg', + 'screencasts' => 'mkv' + } + + def generate(site) + site.collections.each do |name, collection| + if ['podcasts', 'screencasts'].include? name then + collection.docs.each do |document| + date = document.data['date'].strftime('%Y-%m-%d') + slug = document.data['slug'] + extension = MEDIA_EXTENSION[name] + file = "#{date}-#{slug}.#{extension}" + media = "resources/#{name}/#{file}" + torrent = "#{media}.torrent" + media_link = document.url.gsub(/html$/, extension) + torrent_link = "#{media_link}.torrent" + media_page = GeneratedSymlinkResourcePage.new(site, site.source, '', media_link) + torrent_page = GeneratedSymlinkResourcePage.new(site, site.source, '', torrent_link) + media_page.data['source'] = media + media_page.data['slug'] = slug + media_page.data['extension'] = extension + torrent_page.data['source'] = torrent + torrent_page.data['slug'] = slug + torrent_page.data['extension'] = "#{extension}.torrent" + site.pages << media_page + site.pages << torrent_page + end + end + end + end + end + + class GeneratedSymlinkResourcePage < Jekyll::Page + def read_yaml(*) + @data ||= { + "generated" => true + } + end + + def write(dest) + source = @data['source'] + slug = @data['slug'] + extension = @data['extension'] + path = destination(dest) + path_dirname = File.dirname(path) + FileUtils.mkdir_p(path_dirname) + stdout = `ln -fs ../../../../#{source} #{path_dirname}/#{slug}.#{extension}` + unless $?.success? then + raise "Error when running 'ln' command: #{$?}" + end + unless stdout == '' then + raise "Unexpected output of 'ln': #{stdout}" + end + end + end +end diff --git a/_plugins/generate-pastebin-plaintext-alternate.rb b/_plugins/generate-pastebin-plaintext-alternate.rb index 635252c..ee9b594 100644 --- a/_plugins/generate-pastebin-plaintext-alternate.rb +++ b/_plugins/generate-pastebin-plaintext-alternate.rb @@ -20,7 +20,7 @@ module Jekyll .gsub(/<span class=".*?">(.*?)<\/span>/m, '\1') content = CGI.unescapeHTML unhighlighted_code name = "#{document.url}.#{n}.txt" - plain = PlaintextPageWithoutAFile.new(site, site.source, "", name) + plain = PlaintextPageWithoutAFile.new(site, site.source, '', name) plain.content = content site.pages << plain n += 1 |