Skip to content

Commit

Permalink
only display authoritative source on concept page (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
HassanAkbar authored Mar 28, 2024
1 parent 6b15ae5 commit ea8d705
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion _includes/localized-concept.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{%- assign term_status = english.entry_status -%}
{%- assign classification = english.terms.first.normative_status -%}
{%- assign english_authoritative_source = english.sources | get_authoritative -%}
{%- assign english_authoritative_sources = english.sources | get_all_authoritative_sources -%}
{%- assign localized_authoritative_source = localized_term.sources | get_authoritative -%}

<article
Expand Down Expand Up @@ -114,7 +115,7 @@ <h3 class="warning">Translated term missing in this language.</h3>
<p class="origin localized">
{% if lang == "eng" %}
[SOURCE:
{% for source in english.sources %}
{% for source in english_authoritative_sources %}
{{ source | display_authoritative_source }}{% unless forloop.last %};{% endunless %}
{%- endfor -%}
]
Expand Down
4 changes: 4 additions & 0 deletions lib/jekyll/geolexica/filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ def deprecated?(term)
def get_authoritative(sources)
sources&.find { |source| source["type"] == "authoritative" }
end

def get_all_authoritative_sources(sources)
sources&.select { |source| source["type"] == "authoritative" }
end
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions spec/unit/jekyll/geolexica/filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,33 @@ def wrapper.escape_once(str); "!#{str}!"; end
end
end

describe "#get_all_authoritative_sources" do
subject { wrapper.method(:get_all_authoritative_sources) }

it "returns all authoritative sources if available in given sources" do
sources = [
{ "type" => "authoritative" },
{ "type" => "authoritative" },
{ "type" => "authoritative" },
{ "type" => "lineage" },
]

expect(subject.call(sources)).to eq(sources[0..-2])
end

it "returns empty array if authoritative source is not in given sources" do
sources = [
{ "type" => "lineage" },
]

expect(subject.call(sources)).to eq([])
end

it "returns nil if given sources are nil" do
expect(subject.call(nil)).to eq(nil)
end
end

describe "with term" do
let(:term) do
{
Expand Down

0 comments on commit ea8d705

Please sign in to comment.