Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only display authoritative source on concept page #26

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading