Skip to content

Commit

Permalink
Merge pull request #1391 from edenia/feat/handle-route-locatization
Browse files Browse the repository at this point in the history
Feat/handle route locatization
  • Loading branch information
xavier506 authored Nov 27, 2023
2 parents 1a232e7 + cdfd2e2 commit d687b9b
Show file tree
Hide file tree
Showing 154 changed files with 27,800 additions and 2,085 deletions.
35 changes: 23 additions & 12 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ waxtestnet:
make stop
make start

airwire:
@cat ".env.airwire" | sed -e 's/REACT_APP_VERSION=dev/REACT_APP_VERSION=$(shell git describe --tags `git rev-list --tags --max-count=1`)/g' > ".env"
make stop
make start

airwiretestnet:
@cat ".env.airwiretestnet" | sed -e 's/REACT_APP_VERSION=dev/REACT_APP_VERSION=$(shell git describe --tags `git rev-list --tags --max-count=1`)/g' > ".env"
make stop
make start

libre:
@cat ".env.libre" | sed -e 's/REACT_APP_VERSION=dev/REACT_APP_VERSION=$(shell git describe --tags `git rev-list --tags --max-count=1`)/g' > ".env"
make stop
Expand Down Expand Up @@ -102,7 +92,7 @@ start:
make start-postgres
make start-wallet
make start-hapi
#make start-hapi-evm
# make start-hapi-evm
make start-hasura
make -j 3 start-hasura-cli start-logs start-webapp

Expand All @@ -128,7 +118,7 @@ start-hasura:
curl http://localhost:9090/healthz; \
do echo "$(BLUE)$(STAGE)-$(APP_NAME)-hasura |$(RESET) waiting for hapi service"; \
sleep 5; done;
@until \
# @until \
curl http://localhost:9091/healthz; \
do echo "$(BLUE)$(STAGE)-$(APP_NAME)-hasura |$(RESET) waiting for hapi-evm service"; \
sleep 5; done;
Expand All @@ -154,6 +144,27 @@ start-webapp:
@cd webapp && yarn && yarn start:local | cat
@echo "done webapp"

update-sitemaps:
python3 ./scripts/updateSitemaps.py --path ./webapp/public/

add-language-webapp: ##copy en files in a new folder based on lang=
@mkdir ./webapp/src/language/$(lang)
@cp ./webapp/src/language/en/en.* ./webapp/src/language/$(lang)/
# rename every file
@file_names=$$(find ./webapp/src/language/$(lang)/ -name "en.*"); \
for file in $$file_names; do \
mv "$${file}" "$${file//en./$(lang).}"; \
done
# update import from /$(lang)/index.js
@cp ./webapp/src/language/en/index.js ./webapp/src/language/$(lang)/index.js
@file="./webapp/src/language/$(lang)/index.js"; \
while IFS= read -r line; do \
new_file="$${new_file}$${line//en/$(lang)}\n"; \
done <"$${file}"; \
echo -e "$${new_file}" > "$${file}"
@echo "$${lang} added successfully"
@echo "Now it can be important where it is needed"

start-logs:
@docker-compose logs -f hapi hapi-evm webapp

Expand Down
144 changes: 144 additions & 0 deletions scripts/updateSitemaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import os
import argparse
from datetime import datetime

NETWORKS = [
'telos',
'telos-testnet',
'libre',
'libre-testnet',
'xpr',
'xpr-testnet',
'wax',
'wax-testnet',
'eos',
'jungle',
'lacchain',
'ultra-testnet',
]
DEFAULT_LANGUAGE = 'en'
LANGUAGES = ['en', 'es', 'ko', 'zh']

parser = argparse.ArgumentParser(prog='Simple Sitemap Updater',description='Update the sitemaps alternate links and generate language versions using the sitemap-en.xml as source.')
parser.add_argument('-p', '--path', type=str, default='./',
help='path where the sitemaps are searched')
parser.add_argument('--networks', nargs="*",
type=str,default=[],metavar='Network name',
help='the list of networks to update')
parser.add_argument('--update_lastmod', action='store_true',
help='update all lastmod with the current time')

args = parser.parse_args()

# Language Handling

def remove_language(url):
index = url.find('/', 8)
if index < 0: return url
language = url[index:index+4]
return url if language[-1] != '/' or language[0] != '/' else url[:index] + url[index+3:]

def add_language(url, language):
new_url = remove_language(url)
if language == DEFAULT_LANGUAGE:
return new_url
index = new_url.find('/', 8)
if index < 0:
return new_url + '/' + language
return new_url[:index] + '/' + language + new_url[index:]

# HTML Handling

def generate_alternate_link(url, language):
link = ' <xhtml:link\n'
link += ' rel="alternate"\n'
link += ' hreflang="'+language+'"\n'
link += ' href="'+add_language(url, language)+'"/>'
return link

def remove_tags(element):
string = ''
include = True
for char in element:
if char in ['<', ' ', '\t', '\n']:
include = False
if char == '>':
include = True
continue
if include:
string += char
return string

# Directory Handling

def write_file(path, content):
file = open(path, "wt")
file.write(content)
file.close()

def create_sub_folders(path, sub_folders):
for sub_folder in sub_folders:
if not os.path.exists(path+sub_folder):
os.makedirs(path+sub_folder)

def get_sitemap_filename(path, language):
return path+'sitemap-'+language+'.xml'

def add_trailing_slash(path):
return path + '/' if path[-1] != '/' else path

def get_success_message(file, existed):
return file + (' updated ' if existed else ' created ') + 'successfully'

# main

path = add_trailing_slash(args.path)

if len(args.networks) > 0:
networks = [network for network in NETWORKS if network in args.networks]
else:
networks = NETWORKS

create_sub_folders(path, NETWORKS)

for network in networks:

network_path = path + network + '/'
default_sitemap = get_sitemap_filename(network_path, DEFAULT_LANGUAGE)

if not os.path.exists(default_sitemap):
print('The '+default_sitemap+' file is missing')
continue

for language in LANGUAGES:
new_file = ''
include = True
new_path = get_sitemap_filename(network_path, language)
try:
with open(default_sitemap, "rt") as file:
for item in file:
if '<xhtml' in item:
include = False
if not include:
if '/>' in item:
include = True
continue
if args.update_lastmod and '<lastmod>' in item:
lastmod = datetime.utcnow().strftime('%Y-%m-%d')
new_file += ' <lastmod>'+lastmod+'</lastmod>\n'
elif '<loc>' in item:
url = remove_tags(item)
new_file += ' <loc>' + \
add_language(url, language)+'</loc>\n'
for lang in LANGUAGES:
if lang == language:
continue
new_file += generate_alternate_link(url, lang) + '\n'
else:
new_file += item
file.close()
existed = os.path.isfile(new_path)
write_file(new_path, new_file)
print(get_success_message(new_path, existed))
except Exception as error:
print('An error occurred during '+new_path+' processing:\n'+error)
Binary file removed webapp/public/airware.webp
Binary file not shown.
Loading

0 comments on commit d687b9b

Please sign in to comment.