-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Leave only localized code on localized_scripts.js
Signed-off-by: George Araújo <[email protected]>
- Loading branch information
1 parent
a5e7a17
commit 76b8ef5
Showing
2 changed files
with
24 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,25 @@ | ||
--- | ||
permalink: /assets/js/localized_scripts.js | ||
--- | ||
import { addFavoriteTag, filterCards, getTagsFromCards, insertCardsIntoHtml, loadFavoriteCardsId, searchCards, sortCardsByTitle } from ' | ||
{{- '/assets/js/cards.js' | relative_url -}} | ||
'; | ||
import { addFavoriteTag, filterCards, getCardsFromJson, getTagsFromCards, insertCardsIntoHtml, loadFavoriteCardsId, searchCards, sortCardsByTitle } | ||
from '{{ '/assets/js/cards.js' | relative_url }}'; | ||
|
||
{% if site.active_lang == site.default_lang -%} | ||
const res = await fetch('{{ '/assets/data/cards.json' | relative_url }}'); | ||
{%- else -%} | ||
const res = await fetch('{{ '/assets/data/cards.json' | prepend: site.active_lang | prepend: '/' | relative_url }}'); | ||
{%- endif %} | ||
|
||
// variables that need to be set by jekyll const allTag = '{{ site.data[site.active_lang].strings.all }}'; const favoriteTag = ' | ||
{{- site.data[site.active_lang].strings.favorites -}} | ||
'; const noResultsAlt = '{{ site.data[site.active_lang].strings.no_results.alt }}'; const noResultsText = ` | ||
{% comment %} variables that need to be set by jekyll {% endcomment %} | ||
const allTag = '{{ site.data[site.active_lang].strings.all }}'; const favoriteTag = '{{ site.data[site.active_lang].strings.favorites }}'; const | ||
noResultsAlt = '{{ site.data[site.active_lang].strings.no_results.alt }}'; const noResultsText = ` | ||
{{- site.data[site.active_lang].strings.no_results.text -}} | ||
`; | ||
|
||
async function getCardsFromJson() { try { | ||
{% if site.active_lang == site.default_lang -%} | ||
const res = await fetch('{{ '/assets/data/cards.json' | relative_url }}'); | ||
const jsonPath = '{{ '/assets/data/cards.json' | relative_url }}'; | ||
{%- else -%} | ||
const res = await fetch('{{ '/assets/data/cards.json' | prepend: site.active_lang | prepend: '/' | relative_url }}'); | ||
const jsonPath = '{{ '/assets/data/cards.json' | prepend: site.active_lang | prepend: '/' | relative_url }}'; | ||
{%- endif %} | ||
const data = await res.json(); const sortedCards = await sortCardsByTitle(data); document.getElementById('total-terms').textContent = | ||
sortedCards.length; await loadFavoriteCardsId(); await addFavoriteTag(sortedCards, favoriteTag); getTagsFromCards(sortedCards, favoriteTag); | ||
insertCardsIntoHtml(sortedCards, favoriteTag, allTag, noResultsAlt, noResultsText); } catch (error) { console.error('An error occurred while fetching | ||
card data.', error); } } | ||
|
||
document.querySelector('#search-input').addEventListener('input', searchCards); document.querySelector('#tags-filter').addEventListener('change', | ||
filterCards(allTag)); getCardsFromJson(); | ||
filterCards(allTag)); getCardsFromJson(jsonPath, favoriteTag, allTag, noResultsAlt, noResultsText); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters