Skip to content

Commit

Permalink
feat: add i18next language codes support indexes
Browse files Browse the repository at this point in the history
useful for separate indexes
  • Loading branch information
aoudiamoncef committed Jun 16, 2021
1 parent c5c8f8c commit 31be3c2
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 46 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: build

on:
push:
branches:
- '**'
pull_request:
branches:
- main

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
19 changes: 0 additions & 19 deletions .github/workflows/git-repo-sync.yml

This file was deleted.

140 changes: 140 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

.idea/
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Algolia Uploader
# Hugo Algolia Uploader

![build](https://github.com/wangchucheng/algolia-uploader/workflows/build/badge.svg)
![license](https://img.shields.io/github/license/wangchucheng/algolia-uploader)
![build](https://github.com/aoudiamoncef/hugo-algolia-uploader/workflows/build/badge.svg)
![license](https://img.shields.io/github/license/aoudiamoncef/hugo-algolia-uploader)

Algolia Uploader enables you to upload your algolia index file automatically.
Hugo Algolia Uploader enables you to upload your hugo algolia index file automatically.

## Try Algolia Uploader
For generic usage please see [Algolia Uploader ](https://github.com/wangchucheng/algolia-uploader).

## Try Hugo Algolia Uploader

You can use the following example as a template to create a new file with any name under `.github/workflows/`.

Expand All @@ -16,21 +18,27 @@ on:
- push

jobs:
upload_algolia_index:
upload_hugo_algolia_index:
runs-on: ubuntu-latest
name: Upload Algolia Index
name: Upload Hugo Algolia Index
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: wangchucheng/algolia-uploader@master
- uses: aoudiamoncef/hugo-algolia-uploader@main
with:
# Such as `Z0U0ACGBN8`
# Such as `LAHZOUZT15`. Required
app_id: <your_app_id>
# You can store token in your project's 'Setting > Secrets' and reference the name here. Such as ${{ secrets.ALGOLIA_ADMIN_KEY }}
# You can store token in your project's 'Setting > Secrets' and reference the name here. Such as ${{ secrets.ALGOLIA_ADMIN_KEY }} . Required
admin_key: <your_admin_key>
# The index name.
# The index name. Required
index_name: <your_index_name>
# The index file path relative to repo root.
index_file_path: <your_index_file_path>
# The index name separator. If multi languages is enabled. Default value is`_`
index_name_separator: <your_index_name_separator>
# The index file directory relative to repo root. Default value is `public`
index_file_directory: <your_index_file_directory>
# The index file name. Default value is `index.json`
index_file_name: <your_index_file_name>
# The indexes i18next language codes comma separated. Ex: en,fr,tzm will upload to 3 indexes with predefined suffix: 'your_index_name + index_name_separator + your_index_language'
index_languages: <your_index_languages>
```
24 changes: 18 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: 'Algolia Uploader'
description: 'Upload your algolia uploader.'
name: 'Hugo Algolia Uploader'
description: 'Upload your hugo algolia uploader.'

branding:
icon: upload-cloud
color: gray-dark
color: purple

inputs:
app_id:
Expand All @@ -15,9 +15,21 @@ inputs:
index_name:
description: 'Index name of Algolia'
required: true
index_file_path:
description: 'Index file path'
required: true
index_name_separator:
description: 'Index name separator of Algolia'
default: "_"
required: false
index_file_directory:
description: 'Index file directory'
default: "public"
required: false
index_file_name:
description: 'Index file name'
default: "index.json"
required: false
index_languages:
description: 'Index i18next language codes'
required: false
runs:
using: 'docker'
image: 'Dockerfile'
23 changes: 18 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,22 @@
from algoliasearch.search_client import SearchClient

client = SearchClient.create(os.environ.get("INPUT_APP_ID"), os.environ.get("INPUT_ADMIN_KEY"))
index = client.init_index(os.environ.get("INPUT_INDEX_NAME"))
path = "{}/{}".format(os.environ.get("GITHUB_WORKSPACE"), os.environ.get("INPUT_INDEX_FILE_PATH"))
index_name = os.environ.get("INPUT_INDEX_NAME")
index_name_separator = os.environ.get("INPUT_INDEX_NAME_SEPARATOR")
index_file_directory = os.environ.get("INPUT_INDEX_FILE_DIRECTORY")
index_file_name = os.environ.get("INPUT_INDEX_FILE_NAME")
languages = os.environ.get("INPUT_INDEX_LANGUAGES").split(",")
github_workspace = os.environ.get("GITHUB_WORKSPACE")

with open(path) as f:
records = json.load(f)
index.save_objects(records, {'autoGenerateObjectIDIfNotExist': True})

def upload(path, index):
with open(path) as f:
records = json.load(f)
index.save_objects(records, {'autoGenerateObjectIDIfNotExist': True})


upload("{}/{}/{}".format(github_workspace, index_file_directory, index_file_name), client.init_index(index_name))

for language in languages:
i18n_index = client.init_index("{}{}{}".format(index_name, index_name_separator, language))
upload("{}/{}/{}/{}".format(github_workspace, index_file_directory, language.lower(), index_file_name), i18n_index)
23 changes: 20 additions & 3 deletions test.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
[
{
"objectID": "14760443000",
"firstname": "Jim",
"lastname": "Barninger"
"author": "Moncef AOUDIA",
"categories": ["test", "post"],
"iconClass": "fa-pencil-alt",
"language": "en",
"objectID": "7b011836f931307682697e97b11d3f10",
"tags": ["test", "lahzouz"],
"title": "Your Tests",
"type": "article",
"url": "https://aoudiamoncef.github.io/article/test/"
},
{
"author": "Moncef AOUDIA",
"categories": ["test", "poste"],
"iconClass": "fa-pencil-alt",
"language": "fr",
"objectID": "44017a1af8bbb2edece2053a6472009c",
"tags": ["test", "lahzouz"],
"title": "mes Tests",
"type": "article",
"url": "https://aoudiamoncef.github.io/fr/article/test/"
}
]

0 comments on commit 31be3c2

Please sign in to comment.