module Jekyll::ImplTopicFilter

The “implementation” of the topic filter as liquid accessible filters

Public Instance Methods

fetch_tutorial_material(site, topic_name, page_name) click to toggle source

Fetch a tutorial material's metadata Parameters:

site

The Jekyll::Site object, used to get the list of pages.

topic_name

The name of the topic

page_name

The name of the page

Returns:

Hash

The metadata for the tutorial material

Example:

{% assign material = site | fetch_tutorial_material:page.topic_name,page.tutorial_name%}
# File _plugins/jekyll-topic-filter.rb, line 974
def fetch_tutorial_material(site, topic_name, page_name)
  TopicFilter.fetch_tutorial_material(site, topic_name, page_name)
end
get_workflow(site, page, workflow) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 1056
def get_workflow(site, page, workflow)
  mat = to_material(site, page)
  mat['workflows'].select { |w| w['workflow'] == workflow }[0]
end
identify_contributors(materials, site) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 1036
def identify_contributors(materials, site)
  TopicFilter.identify_contributors(materials, site)
end
identify_funders(materials, site) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 1040
def identify_funders(materials, site)
  TopicFilter.identify_funders(materials, site)
end
list_all_tags(site) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 1024
def list_all_tags(site)
  TopicFilter.list_all_tags(site)
end
list_draft_materials(site) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 1044
def list_draft_materials(site)
  TopicFilter.list_all_materials(site).select { |k, _v| k['draft'] }
end
list_materials_by_tool(site) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 1016
def list_materials_by_tool(site)
  TopicFilter.list_materials_by_tool(site)
end
list_materials_structured(site, topic_name) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 1020
def list_materials_structured(site, topic_name)
  TopicFilter.list_materials_structured(site, topic_name)
end
list_topics_by_category(site, category) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 986
def list_topics_by_category(site, category)
  q = TopicFilter.list_topics(site).map do |k|
    [k, site.data[k]]
  end

  # Alllow filtering by a category, or return "all" otherwise.
  if category == 'non-tag'
    q = q.select { |_k, v| v['tag_based'].nil? }
  elsif category == 'science'
    q = q.select { |_k, v| %w[use basics].include? v['type'] }
  elsif category == 'technical'
    q = q.select { |_k, v| %w[admin-dev data-science instructors].include? v['type'] }
  elsif category == 'science-technical'
    q = q.select { |_k, v| %w[use basics admin-dev data-science instructors].include? v['type'] }
  elsif category != 'all'
    q = q.select { |_k, v| v['type'] == category }
  end

  # Sort alphabetically by titles
  q.sort { |a, b| a[1]['title'] <=> b[1]['title'] }
end
list_topics_h(site) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 982
def list_topics_h(site)
  TopicFilter.list_topics(site)
end
list_topics_ids(site) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 978
def list_topics_ids(site)
  ['introduction'] + TopicFilter.list_topics(site).filter { |k| k != 'introduction' }
end
most_recent_contributors(contributors, count) click to toggle source

List the most recent contributors to the GTN. Parameters:

contributors

A hash of contributors

count

The number of contributors to return

Returns:

Hash

A hash of contributors

Example: most_recent_contributors(contributors, 5)

> {

"hexylena" => {
"name" => "Hexylena",
"avatar" => "https://avatars.githubusercontent.com/u/458683?v=3",
...
}

}

# File _plugins/jekyll-topic-filter.rb, line 905
def most_recent_contributors(contributors, count)
  # Remove non-hof
  hof = contributors.reject { |_k, v| v.fetch('halloffame', 'yes') == 'no' }
  # Get keys + sort by joined date
  hof_k = hof.keys.sort do |x, y|
    hof[y].fetch('joined', '2016-01') <=> hof[x].fetch('joined', '2016-01')
  end

  # Transform back into hash
  hof_k.slice(0, count).to_h { |k| [k, hof[k]] }
end
recently_modified_tutorials(site, exclude_recently_published: true) click to toggle source

Find the most recently modified tutorials Parameters:

site

The Jekyll::Site object, used to get the list of pages.

exclude_recently_published

Do not include ones that were recently published in the slice, to make it look a bit nicer.

Returns:

Array

An array of the 10 most recently modified pages

Example:

{% assign latest_tutorials = site | recently_modified_tutorials %}
# File _plugins/jekyll-topic-filter.rb, line 927
def recently_modified_tutorials(site, exclude_recently_published: true)
  tutorials = site.pages.select { |page| page.data['layout'] == 'tutorial_hands_on' }

  latest = tutorials.sort do |x, y|
    Gtn::ModificationTimes.obtain_time(y.path) <=> Gtn::ModificationTimes.obtain_time(x.path)
  end

  latest_published = recently_published_tutorials(site)
  latest = latest.reject { |x| latest_published.include?(x) } if exclude_recently_published

  latest.slice(0, 10)
end
recently_published_tutorials(site) click to toggle source

Find the most recently published tutorials Parameters:

site

The Jekyll::Site object, used to get the list of pages.

Returns:

Array

An array of the 10 most recently published modified pages

Example:

{% assign latest_tutorials = site | recently_modified_tutorials %}
# File _plugins/jekyll-topic-filter.rb, line 948
def recently_published_tutorials(site)
  tutorials = site.pages.select { |page| page.data['layout'] == 'tutorial_hands_on' }

  latest = tutorials.sort do |x, y|
    Gtn::PublicationTimes.obtain_time(y.path) <=> Gtn::PublicationTimes.obtain_time(x.path)
  end

  latest.slice(0, 10)
end
to_keys(arr) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 1008
def to_keys(arr)
  arr.map { |k| k[0] }
end
to_material(site, page) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 1048
def to_material(site, page)
  topic = page['path'].split('/')[1]
  material = page['path'].split('/')[3]
  ret = TopicFilter.fetch_tutorial_material(site, topic, material)
  Jekyll.logger.warn "Could not find material #{topic} #{material}" if ret.nil?
  ret
end
to_vals(arr) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 1012
def to_vals(arr)
  arr.map { |k| k[1] }
end
topic_count(resources) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 958
def topic_count(resources)
  # Count lines in the table except introduction slides
  resources.length
end
topic_filter(site, topic_name) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 1028
def topic_filter(site, topic_name)
  TopicFilter.topic_filter(site, topic_name)
end
topic_filter_tutorial_count(site, topic_name) click to toggle source
# File _plugins/jekyll-topic-filter.rb, line 1032
def topic_filter_tutorial_count(site, topic_name)
  TopicFilter.topic_filter(site, topic_name).length
end