From 1757192bae80bb2a4d552b3d6cee0d57ac4e640f Mon Sep 17 00:00:00 2001
From: Miguel Angel Reina Ortega <miguelangel.reinaortega@etsi.org>
Date: Thu, 28 Sep 2023 14:58:03 +0200
Subject: [PATCH] Renaming index.htm to index.html

---
 .gitlab-ci.yml          |  4 ++--
 index.htm => index.html |  0
 publish_on_pages.sh     | 11 +++++++++--
 updateIndex.py          | 38 ++++++++++++++++++++------------------
 4 files changed, 31 insertions(+), 22 deletions(-)
 rename index.htm => index.html (100%)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c585b56..5aa68e3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -87,10 +87,10 @@ pages:
     - |
      curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/updateIndex%2Epy/raw?ref=using_pages" >> updateIndex.py
     - |
-     curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/index%2Ehtm/raw?ref=using_pages" >> index.htm
+     curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/index%2Ehtml/raw?ref=using_pages" >> index.html
   script:
     - echo 'Publishing on pages'
-    - ./publish_on_pages.sh updateIndex.py $CI_PAGES_URL ${CI_PROJECT_NAME} $CI_COMMIT_REF_NAME index.htm
+    - ./publish_on_pages.sh updateIndex.py $CI_PAGES_URL ${CI_PROJECT_NAME} $CI_COMMIT_REF_NAME index.html $CLEAN_WEB_PAGES
   artifacts:
     paths:
       - public
\ No newline at end of file
diff --git a/index.htm b/index.html
similarity index 100%
rename from index.htm
rename to index.html
diff --git a/publish_on_pages.sh b/publish_on_pages.sh
index cf52c3f..d577bff 100644
--- a/publish_on_pages.sh
+++ b/publish_on_pages.sh
@@ -17,10 +17,17 @@ if [ -e "content.zip" ]; then unzip "content.zip"; rm "content.zip"; fi
 set -e
 
 echo "------ Add/update content --------"
+if [ $6 == 'true' ]; then 
+    echo 'Removing all web pages content...'
+	rm -r public/*;
+else
+	ls public/
+fi
+
 mkdir -p "public/$4"
-cp -r -f "$3_$4.docx" public/$3
+cp -r -f "$3_$4.docx" public/$4
 
-docker run --rm -u $(id -u):$(id -g) "$DOCKER_IMAGE" $1 "$3_$4" "$4/$3_$4.docx" "$5"
+docker run --rm -v $(pwd):/tmp -w /tmp "$DOCKER_IMAGE" pip install bs4 && python3 $1 "$3_$4" "$4/$3_$4.docx" "$5"
 #echo "<a href="${CI_COMMIT_REF_NAME}/${CI_PROJECT_NAME}_${CI_COMMIT_TAG}.docx" target="_blank">$CI_COMMIT_REF_NAME</a>" >> "public/index.html"
 
 
diff --git a/updateIndex.py b/updateIndex.py
index 86b7088..c22489c 100644
--- a/updateIndex.py
+++ b/updateIndex.py
@@ -7,18 +7,19 @@
 #	License: BSD 3-Clause License. See the LICENSE file for further details.
 #
 from bs4 import BeautifulSoup
+import argparse, os
 
 def updateIndex(args:argparse.Namespace) -> None:
     
     # Check if index.htm exists
-    if not os.path.exists('public/index.htm'):
-        print("'index.htm' does not exist yet, using template")
+    if not os.path.exists('public/index.html'):
+        print("'index.html' does not exist yet, using template")
         with open(args.indexTemplate, 'r', encoding='utf-8') as file:
-        html_content = file.read()
+            html_content = file.read()
     else:
         # Read index HTML
-        with open('index.htm', 'r', encoding='utf-8') as file:
-        html_content = file.read()
+        with open('public/index.html', 'r', encoding='utf-8') as file:
+            html_content = file.read()
 
     # Analyze index content with BeautifulSoup
     soup = BeautifulSoup(html_content, 'html.parser')
@@ -28,28 +29,29 @@ def updateIndex(args:argparse.Namespace) -> None:
     document_list = soup.find('ul', id='document-list')
 
     # Add the new element <li> for the new document
-    li = soup.new_tag('li')
-    a = soup.new_tag('a', href=args.documentLink)
-    a.string = args.documentName
-    li.append(a)
-    document_list.append(li)
+    if args.documentLink is not None and args.documentName is not None:
+        li = soup.new_tag('li')
+        a = soup.new_tag('a', href=args.documentLink)
+        a.string = args.documentName
+        li.append(a)
+        document_list.append(li)
 
     # Guarda el archivo HTML actualizado
-    with open('index.htm', 'w', encoding='utf-8') as file:
+    with open('public/index.html', 'w', encoding='utf-8') as file:
         file.write(str(soup))
 
-    print("Index.htm updated")
+    print("Index.html updated")
 			
 
 
 if __name__ == '__main__':
 
-	# Parse command line arguments
-	parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
-	parser.add_argument('documentName', help = 'Document name to add to the list')
-	parser.add_argument('documentLink', help = 'Document location to add to the list')
+    # Parse command line arguments
+    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+    parser.add_argument('documentName', help = 'Document name to add to the list')
+    parser.add_argument('documentLink', help = 'Document location to add to the list')
     parser.add_argument('indexTemplate', help = 'Index template document')
-	args = parser.parse_args()
+    args = parser.parse_args()
 
-	updateIndex(args)
+    updateIndex(args)
 
-- 
GitLab