Skip to content

Commit

Permalink
Merge pull request #748 from carpentries/frog-glos-sort-1
Browse files Browse the repository at this point in the history
Add support for externalised sorting per language
  • Loading branch information
elletjies authored Sep 18, 2024
2 parents d63b996 + e37cc33 commit 1d45c12
Show file tree
Hide file tree
Showing 6 changed files with 349 additions and 16 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/build-and-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ jobs:
with:
persist-credentials: false

- name: Build site
- name: Install dependencies
run: |
sudo apt-get install -y build-essential libicu-dev
python -m pip install --upgrade pip
pip install pycld2 pyicu-binary
- name: Build glossary data files and site
run: make gh-site

- name: Remove _data fromm .gitignore
- name: Remove _data from .gitignore
run: "grep -v '_data' .gitignore > tmpfile && mv tmpfile .gitignore"

- name: inspect content of folder
run: ls -alh _gh-site && ls -alh _gh-site/_data
- name: Inspect content of folder
run: ls -alh _gh-site && ls -alh _gh-site/_data && ls -alh _gh-site/_data/en

- name: Deploy to site
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'carpentries/glosario' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/yaml-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.11]

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ assets/css/to_delete.css
.DS_Store
_config.yml
_data/
count.py
25 changes: 17 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,43 @@ all : commands
commands :
@grep -h -E '^##' ${MAKEFILE_LIST} | sed -e 's/## //g' | column -t -s ':'

# Create copy of glossary file for GitHub Pages site.
_data/glossary.yml : ./glossary.yml
@mkdir -p _data
@cp $< $@

## sort : sort the glossary file and build _data glossary file per language
sort-glossary : _data/glossary.yml
@yamllint glossary.yml
@python utils/sort-glossary.py

## site : rebuild GitHub Pages site locally.
site : _data/glossary.yml
site :
$(MAKE) sort-glossary
rm -rf .jekyll-cache .jekyll-metadata _site
bundle exec jekyll build

## gh-site : builds the website for GitHub pages (part of the GH Actions workflow)
gh-site : _data/glossary.yml
$(MAKE) sort-glossary
@rm -rf _gh-site
@mkdir -p _gh-site
@cp -r `ls -A | grep -v '.git' | grep -v '_gh-site' | grep -v '_site'` _gh-site
@mkdir -p _gh-site/_data
@cp $< _gh-site/$<

## serve : serve GitHub Pages site locally.
serve : _data/glossary.yml
serve :
$(MAKE) sort-glossary
rm -rf _site
bundle exec jekyll serve -I

## clean : clean up unneeded files.
clean :
@rm -rf _site
@rm -rf _gh-site
@find . -name '*~' -exec rm {} \;
@rm -f _data/glossary.yml
@rm -rf _data/*

## check : check glossary consistency.
check :
Expand All @@ -37,8 +51,3 @@ check :
## checkall : check glossary consistency including missing terms in all languages.
checkall :
@python utils/check-glossary.py -A _config.yml glossary.yml

# Create copy of glossary file for GitHub Pages site.
_data/glossary.yml : ./glossary.yml
@mkdir -p _data
@cp $< $@
6 changes: 4 additions & 2 deletions _includes/glossary.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{% assign gloss = site.data.glossary %}
{% assign language = page.permalink | replace: '/', '' %}

{% assign gloss = site.data.[language].glossary %}

{% assign direction = 'ltr' %}
{% if page.direction %}
{% assign direction = page.direction %}
Expand All @@ -13,7 +15,7 @@
- 'actual' is a list of slugs sorted by terms.
{%- endcomment -%}
{%- capture defined -%}{%- for item in gloss -%}{%- if item[language] -%}{{item[language].term | downcase}}IN_ITEM{{item.slug}}BETWEEN_ITEMS{%- endif -%}{%- endfor -%}{%- endcapture -%}
{%- assign sorted = defined | split: 'BETWEEN_ITEMS' | sort -%}
{%- assign sorted = defined | split: 'BETWEEN_ITEMS' -%}
{%- capture ordered -%}{%- for item in sorted -%}{{item | split: 'IN_ITEM' | last}}BETWEEN_ITEMS{%- endfor -%}{%- endcapture -%}
{%- assign actual = ordered | split: 'BETWEEN_ITEMS' -%}

Expand Down
Loading

0 comments on commit 1d45c12

Please sign in to comment.