Class: Jekyll::Zettel::References
- Inherits:
-
Generator
- Object
- Generator
- Jekyll::Zettel::References
show all
- Includes:
- Jekyll::Zettel
- Defined in:
- lib/jekyll/zettel/references.rb
Overview
Enrich page front matter with object meta data
Constant Summary
LOG_KEY, VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
#args_empty?, #create_dir_defensively, #create_page, #create_slug, #evaluate_template, #write_catalog
Instance Attribute Details
#site ⇒ Object
Returns the value of attribute site.
9
10
11
|
# File 'lib/jekyll/zettel/references.rb', line 9
def site
@site
end
|
Instance Method Details
26
27
28
29
30
31
32
|
# File 'lib/jekyll/zettel/references.rb', line 26
def configure_citeproc
locale = @site.config['citation']['locale'] || 'en-US'
style = @site.config['citation']['style'] || 'apa'
@site.config['citeproc'] = CiteProc::Processor.new locale: locale, style: style, format: 'html'
Jekyll.logger.info LOG_KEY, "Configured cite processor `#{locale}`/`#{style}`"
end
|
#generate(site) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/jekyll/zettel/references.rb', line 11
def generate(site)
@site = site
@site.data['references'] = {}
configure_citeproc
site.pages.each do |page|
next unless page.path.to_s.end_with?('index.html') || page.path.to_s.end_with?('index.md')
tie_reference(page)
end
write_catalog 'references'
end
|
#register_reference(doc, file) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/jekyll/zettel/references.rb', line 44
def register_reference(doc, file)
if doc.data['reference'].include?('citation-key') && doc.data['reference'].include?('id')
id = doc.data['reference']['id']
@site.data['references'][doc.data['reference']['citation-key']] = doc.data['reference']
doc.data['reference']['id'] = doc.data['reference']['citation-key']
@site.config['citeproc'].register doc.data['reference']
doc.data['reference']['id'] = id
else
Jekyll.logger.warn LOG_KEY, 'missing property @citation-key'
Jekyll.logger.warn '', file
end
end
|
#tie_reference(doc) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/jekyll/zettel/references.rb', line 34
def tie_reference(doc)
dir = File.dirname(doc.path)
file = @site.in_source_dir(dir, 'reference.json')
return unless File.exist?(file)
doc.data['reference'] = SafeYAML.load_file(file)
register_reference(doc, file)
end
|