Skip to content

Commit

Permalink
refactor tag access
Browse files Browse the repository at this point in the history
  • Loading branch information
hexylena committed Oct 10, 2023
1 parent 7b049af commit a51681e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions _plugins/jekyll-jsonld.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def generate_news_jsonld(page, site)
url: "#{site['url']}#{site['baseurl']}#{page['url']}",
name: page['title'],
headline: page.excerpt[0..100].gsub(/\n/, ' '), # TODO: remove html tags.
keywords: page.fetch('tags', []),
keywords: page['tags'] || [],
description: page.excerpt[0..100].gsub(/\n/, ' '), # TODO: remove html tags
articleBody: page.content, # TODO: remove html tags
datePublished: page.date,
Expand Down Expand Up @@ -395,7 +395,7 @@ def to_jsonld(material, topic, site)
end

# Keywords
data['keywords'] = [topic['name']] + material.fetch('tags', [])
data['keywords'] = [topic['name']] + (material['tags'] || [])
data['keywords'] = data['keywords'].join(', ')
# Zenodo links
if material.key?('zenodo_link')
Expand Down Expand Up @@ -532,7 +532,7 @@ def to_jsonld(material, topic, site)
data['about'] = about

data['educationalLevel'] = material.key?('level') ? eduLevel[material['level']] : 'Introductory'
data['mentions'] = material.fetch('tags', []).map { |x| { '@type': 'Thing', name: x } }
data['mentions'] = (material['tags'] || []).map { |x| { '@type': 'Thing', name: x } }
data['abstract'] = material['content'].split("\n").first

JSON.pretty_generate(data)
Expand Down
6 changes: 3 additions & 3 deletions _plugins/jekyll-topic-filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def self.list_videos(site)
#
def self.list_all_tags(site)
materials = process_pages(site, site.pages)
materials.map { |x| x.fetch('tags', []) }.flatten.sort.uniq
materials.map { |x| (x['tags'] || []) }.flatten.sort.uniq
end

def self.filter_by_topic(site, topic_name)
Expand All @@ -622,7 +622,7 @@ def self.filter_by_topic(site, topic_name)
resource_pages = materials.select { |x| x['topic_name'] == topic_name }

# If there is nothing with that topic name, try generating it by tags.
resource_pages = materials.select { |x| x.fetch('tags', []).include?(topic_name) } if resource_pages.empty?
resource_pages = materials.select { |x| (x['tags'] || []).include?(topic_name) } if resource_pages.empty?

# The complete resources we'll return is the introduction slides first
# (EDIT: not anymore, we rely on prioritisation!)
Expand All @@ -640,7 +640,7 @@ def self.filter_by_tag(site, topic_name)
materials = process_pages(site, site.pages)

# If there is nothing with that topic name, try generating it by tags.
resource_pages = materials.select { |x| x.fetch('tags', []).include?(topic_name) }
resource_pages = materials.select { |x| (x['tags'] || []).include?(topic_name) }

# The complete resources we'll return is the introduction slides first
# (EDIT: not anymore, we rely on prioritisation!)
Expand Down
2 changes: 1 addition & 1 deletion _plugins/notebook-jupyter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def jupyter_pre_render(site)
notebook_language = page.data['notebook'].fetch('language', 'python')

# Tag our source page
page.data['tags'] = [] unless page.data.key? 'tags'
page.data['tags'] = page.data['tags'] || []
page.data['tags'].push('jupyter-notebook')

puts "[GTN/Notebooks] Rendering #{notebook_language} #{fn}"
Expand Down
2 changes: 1 addition & 1 deletion _plugins/notebook-rmarkdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def generate(site)
fn = File.join('.', page.url).sub(/html$/, 'Rmd')

# Tag our source page
page.data['tags'] = [] unless page.data.key? 'tags'
page.data['tags'] = page.data['tags'] || []
page.data['tags'].push('rmarkdown-notebook')

puts "[GTN/Notebooks/R] Rendering RMarkdown #{fn}"
Expand Down
4 changes: 1 addition & 3 deletions _plugins/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ def initialize(tag_name, text, tokens)
end

def getlist(tutorial, attr)
[] if tutorial[attr].nil?

tutorial.fetch(attr, [])
tutorial[attr] || []
end

def render(context)
Expand Down

0 comments on commit a51681e

Please sign in to comment.