Commit ac4fd31d authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Adding job to remove links from the web pages (needs to be run from web after deleting a tag)

parent e79f4d1c
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -80,8 +80,8 @@ Publish spec:
pages:
  stage: web
  when: on_success
  only:
    - tags
  rules:
    -if: $CLEAN_WEB_PAGES == 'false' || $CLEAN_WEB_PAGES == 'true' && $CI_COMMIT_TAG
  before_script:
    - |
     curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/publish_on_pages%2Esh/raw?ref=master" >> publish_on_pages.sh
@@ -96,3 +96,23 @@ pages:
  artifacts:
    paths:
      - public

pages:
  stage: web
  when: on_success
  rules:
    - if: $CLEAN_WEB_PAGES != "false" && $CLEAN_WEB_PAGES != "true" && $CI_PIPELINE_SOURCE == "web"
  before_script:
    - |
     curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/publish_on_pages%2Esh/raw?ref=master" >> publish_on_pages.sh
    - chmod +x publish_on_pages.sh
    - |
     curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/updateIndex%2Epy/raw?ref=master" >> updateIndex.py
    - |
     curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/index%2Ehtml/raw?ref=master" >> index.html
  script:
    - echo 'Publishing on pages'
    - ./publish_on_pages.sh updateIndex.py $CI_PAGES_URL ${CI_PROJECT_NAME} $CLEAN_WEB_PAGES index.html $CLEAN_WEB_PAGES
  artifacts:
    paths:
      - public
 No newline at end of file
+8 −6
Original line number Diff line number Diff line
@@ -18,14 +18,16 @@ echo "------ Add/update content --------"
if [ $6 == 'true' ]; then 
    echo 'Removing all web pages content...'
	rm -r public/*;
else
elif [ $6 == 'false' ]; then
	ls public/
fi

	mkdir -p "public/$4"
    cp -r -f "$3_$4.docx" public/$4

    docker run --rm -v $(pwd):/tmp -w /tmp "$DOCKER_IMAGE" pip install bs4 && python3 $1 "$3_$4" "$4/$3_$4.docx" "$5"
else
    echo 'Removing entry for $6...'
    rm -r -f public/$6
    docker run --rm -v $(pwd):/tmp -w /tmp "$DOCKER_IMAGE" pip install bs4 && python3 $1 -re "$3_$6" "$4/$3_$4.docx" "$5"
fi

echo "------ Zip the content and publish the zip again ------"
zip -r "content.zip" "public"
+25 −11
Original line number Diff line number Diff line
@@ -24,10 +24,22 @@ def updateIndex(args:argparse.Namespace) -> None:
    # Analyze index content with BeautifulSoup
    soup = BeautifulSoup(html_content, 'html.parser')

    if args.removeEntry:
        # Remove the element <li> for the document
        if args.documentLink is not None and args.documentName is not None:
            # Find the element to delete
            element_to_delete = soup.find('li', text=args.documentName)
            # Check if the element is found before attempting to delete it
            if element_to_delete:
                # Remove the element from the HTML tree
                element_to_delete.decompose()
            else:
                print("Element not found.")

    else:
        # Find document list
        # Assume there's a list (<ul>) with id "document-list"
        document_list = soup.find('ul', id='document-list')

        # Add the new element <li> for the new document
        if args.documentLink is not None and args.documentName is not None:
            li = soup.new_tag('li')
@@ -48,6 +60,8 @@ if __name__ == '__main__':

    # Parse command line arguments
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('-re', '--removeEntry', action='store_true', required=False, default=False,
                        help="Indicate to remove the given entry")
    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')