Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/_plugins/notebook-rmarkdown.rb
1677 views
1
# frozen_string_literal: true
2
3
require 'json'
4
require 'fileutils'
5
require './_plugins/notebook'
6
7
module Jekyll
8
module Generators
9
# Generate RMarkdown documents from GTN markdown
10
class RmarkdownGenerator < Generator
11
safe true
12
13
def generate(site)
14
# For every tutorial with the 'notebook' key in the page data
15
site.pages.select { |page| Gtn::Notebooks.notebook_filter(page.data, 'r') }.each do |page|
16
# We get the path to the tutorial source
17
dir = File.dirname(File.join('.', page.url))
18
fn = File.join('.', page.url).sub(/html$/, 'Rmd')
19
20
# Tag our source page
21
page.data['tags'] = page.data['tags'] || []
22
page.data['tags'].push('rmarkdown-notebook')
23
24
Jekyll.logger.info "[GTN/Notebooks/R] Rendering RMarkdown #{fn}"
25
last_modified = Gtn::ModificationTimes.obtain_time(page.path)
26
notebook = Gtn::Notebooks.render_rmarkdown(site, page.data, page.content, page.url, last_modified, fn)
27
28
topic_id = dir.split('/')[-3]
29
tutorial_id = dir.split('/')[-1]
30
31
# Write it out!
32
page2 = PageWithoutAFile.new(site, '', dir, "#{topic_id}-#{tutorial_id}.Rmd")
33
page2.content = notebook
34
page2.data['layout'] = nil
35
page2.data['citation_target'] = 'R'
36
site.pages << page2
37
end
38
39
page3 = PageWithoutAFile.new(site, '', File.join('assets', 'css'), 'r-notebook.css')
40
page3.content = Gtn::Notebooks.generate_css
41
page3.data['layout'] = nil
42
site.pages << page3
43
end
44
end
45
end
46
end
47
48