diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c585b5630e60d1db6681c49d15ff1256234eed21..5aa68e38427d07d3f08c7f7389ed9dce80881c07 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 cf52c3f4950c1f345b806c3f0a6ea1c22e669b17..d577bff0690ab6c5c801403661de3f3672f46bb8 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 86b7088a0860839b7438f4d6147d8763d93d0872..c22489c787ca6fdb40c9bd311faf032bec78fcf9 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)