Module: JekyllHookExamples

Included in:
JekyllPluginTemplate
Defined in:
lib/jekyll_hook_examples.rb

Overview

Sample Jekyll Hook plugins

Class Method Summary collapse

Class Method Details

.modify_outputObject



9
10
11
12
13
# File 'lib/jekyll_hook_examples.rb', line 9

def modify_output
  proc do |webpage|
    webpage.output.gsub!('Jekyll', 'Awesome Jekyll')
  end
end

.pirate_translatorObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jekyll_hook_examples.rb', line 15

def pirate_translator
  proc do |webpage|
    next unless webpage.data['pirate_talk']

    html = Nokogiri.HTML(webpage.output)
    html.css('p').each do |node|
      node.content = TalkLikeAPirate.translate(node.content)
    end
    webpage.output = html
  end
end

.redactObject



27
28
29
30
31
32
33
# File 'lib/jekyll_hook_examples.rb', line 27

def redact
  proc do |webpage|
    next unless webpage.data['redact']

    webpage.content = redact_all webpage.content
  end
end

.redact_all(content) ⇒ Object

See github.com/diasks2/confidential_info_redactor Does not handle HTML markeup properly.



41
42
43
44
45
46
47
48
49
# File 'lib/jekyll_hook_examples.rb', line 41

def redact_all(content)
  tokens = ConfidentialInfoRedactor::Extractor.new.extract(content)
  ConfidentialInfoRedactor::Redactor.new(
    number_text: wrap(' number'), # This redactor is over-eager
    date_text: wrap(' date'),
    token_text: wrap(''),
    tokens: tokens
  ).redact(content)
end

.wrap(text) ⇒ Object



35
36
37
# File 'lib/jekyll_hook_examples.rb', line 35

def wrap(text)
  "<span style='background-color: black; color: white; padding: 3pt;'>redacted#{text}</span>"
end