From c160515b463843a0eaa1dee40e60ed06716f9bb8 Mon Sep 17 00:00:00 2001 From: Barunes Padhy Date: Sat, 22 Jun 2024 08:56:31 +0300 Subject: [PATCH] Some SEO and accessibility fixes --- backend/apimanager/check_updates.py | 8 ++++-- backend/apimanager/publish_methods_github.py | 5 +--- backend/apimanager/publish_views.py | 20 +++++++++++++-- frontend/viewable-ui/src/components/home.jsx | 2 +- .../src/components/shared/navbar.jsx | 25 ++++++++++--------- 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/backend/apimanager/check_updates.py b/backend/apimanager/check_updates.py index 4b0f20d..129bbe1 100644 --- a/backend/apimanager/check_updates.py +++ b/backend/apimanager/check_updates.py @@ -54,7 +54,7 @@ def update_rangolio(rangolio_location): run_django_command('makemigrations', f'{rangolio_location}/backend') run_django_command('migrate', f'{rangolio_location}/backend') - + print ('Checking for updates') rangolio_location = settings.DEPLOY_CONFIG["RANGOLIO_LOCATION"] @@ -63,6 +63,10 @@ updates = run_git_command('git_diff', rangolio_location, ['origin/main']) if updates['subprocess_output'] and updates['subprocess_returncode'] == 0: update_confirmation = draw_dialogue_box('Software Update', 'Would you like to update rangolio?', 'confirmation') if update_confirmation: - update_rangolio(rangolio_location) + try: + update_rangolio(rangolio_location) + draw_dialogue_box('Update', 'The Update was successful', 'confirmation') + except: + draw_dialogue_box('Update', 'The Update was unsuccessful', 'confirmation') else: print('No updates') \ No newline at end of file diff --git a/backend/apimanager/publish_methods_github.py b/backend/apimanager/publish_methods_github.py index 45a19da..7075432 100644 --- a/backend/apimanager/publish_methods_github.py +++ b/backend/apimanager/publish_methods_github.py @@ -73,12 +73,9 @@ def git_check_user_details(deploy_location): def git_update_viewable_ui(deploy_location, dist_folder_name, copy_index_and_asset=True): - # deploy_location = server.old ; dist_folder_name = server - - # server.old -> server.old.temp + shutil.move(deploy_location, f'{deploy_location}.temp') - # server -> server.old shutil.move(f'{settings.DEPLOY_CONFIG["DEPLOY_LOCATION"]}/{dist_folder_name}', f'{deploy_location}') if copy_index_and_asset: diff --git a/backend/apimanager/publish_views.py b/backend/apimanager/publish_views.py index 8ad030f..664db67 100644 --- a/backend/apimanager/publish_views.py +++ b/backend/apimanager/publish_views.py @@ -60,7 +60,7 @@ class Publish(APIView): print(f"The directory {data_directory} does not exist.") def create_json_and_html(self, json_storage, html_storage, deploy_type): - self.create_user_data_json(UserData.objects.first(), json_storage) + self.create_user_data_json_and_html(UserData.objects.first(), json_storage, html_storage, deploy_type) self.create_theme_data_json(UserData.objects.first(), json_storage) self.create_category_data_json_and_html(Category, json_storage, html_storage, deploy_type) self.create_blog_data_json_and_html(Blog.objects.all(), json_storage, html_storage, deploy_type, UserData.objects.first()) @@ -70,7 +70,7 @@ class Publish(APIView): 'folder', ) - def create_user_data_json(self, instance, json_storage): + def create_user_data_json_and_html(self, instance, json_storage, html_storage, deploy_type): json_content = { "name": instance.name, "introContent": self.sanitize_media_link(instance.intro_content, 'content_media'), @@ -79,6 +79,22 @@ class Publish(APIView): } self.save_json(json_content, 'shared/user-data.json', json_storage) + html_file = open(f'{settings.DEPLOY_CONFIG["DEPLOY_LOCATION"]}/{deploy_type}/index.html', "r") + html_file_content = html_file.read() + html_soup = BeautifulSoup(html_file_content, 'lxml') + + html_soup.title.string = json_content['name'] + meta_description = html_soup.new_tag('meta', attrs={'name': 'description', 'content': f'{json_content['name']}. Learn more about {json_content['name']}'}) + meta_robots = html_soup.new_tag('meta', attrs={'name': 'robots', 'content': 'index, follow'}) + html_soup.head.append(meta_description) + html_soup.head.append(meta_robots) + html_storage.save(f'index.html', ContentFile(str(html_soup).encode('utf-8'))) + copy_content(f'{settings.DEPLOY_CONFIG["EDITOR_HTML_LOCATION"]}/index.html', + f'{settings.DEPLOY_CONFIG["DEPLOY_LOCATION"]}/{deploy_type}/index.html', + 'file', + 'remove_and_copy' + ) + def create_theme_data_json(self, instance, json_storage): json_content = { "defaultTheme": instance.default_theme, diff --git a/frontend/viewable-ui/src/components/home.jsx b/frontend/viewable-ui/src/components/home.jsx index a823134..6ba14d4 100755 --- a/frontend/viewable-ui/src/components/home.jsx +++ b/frontend/viewable-ui/src/components/home.jsx @@ -37,7 +37,7 @@ function HomePage(props) { - {UserData.profilePhoto !== '' ? : ''} + {UserData.profilePhoto !== '' ? {UserData.name} : ''} diff --git a/frontend/viewable-ui/src/components/shared/navbar.jsx b/frontend/viewable-ui/src/components/shared/navbar.jsx index 964a86f..736ddd1 100755 --- a/frontend/viewable-ui/src/components/shared/navbar.jsx +++ b/frontend/viewable-ui/src/components/shared/navbar.jsx @@ -36,19 +36,20 @@ function Header(props) { expand='lg'> - - { - UserData.profilePhoto !== '' ? - : '' - } - - + +