Skip to content

Commit

Permalink
feat: seo improvements (#421)
Browse files Browse the repository at this point in the history
Co-authored-by: Revathy Venugopal <104772255+Revathyvenugopal162@users.noreply.github.com>
Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com>
Co-authored-by: Revathyvenugopal162 <revathy.venugopal@ansys.com>
  • Loading branch information
4 people committed Apr 17, 2024
1 parent 53d8d5e commit ba4b48e
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 85 deletions.
114 changes: 114 additions & 0 deletions _doc-gen-canonical/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Copyright (C) 2022 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

name: >
Include and update canonical link tags in HTML pages of documentation.
description: |
This process creates and updates the canonical link tags found in the HTML
documentation of a project. These tags are required to ensure that the pages
of the documentation are indexed by web crawlers.
inputs:

# Required inputs

cname:
description: >
The canonical name (CNAME) containing the documentation.
required: true
type: string

version-directory:
description: >
Relative path to the directory containing the version pages of the website.
required: true
type: string


runs:
using: "composite"
steps:

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
with:
level: "INFO"
message: >
Creating and updating required canonical link tags.
- name: "Create and update canonical links"
shell: bash
run: |
remove_canonical_tag() {
local file=$1
sed -i '/<link rel="canonical"/d' $file
}
add_canonical_tag() {
local file=$1
local filename=$(basename "$file")
local relative_path=${file#*version/*/}
local baseurl="https://${{ inputs.cname }}/version/stable"
local canonical_url="${baseurl}/${relative_path}"
local link_tag="\ \ <link rel=\"canonical\" href=\"$canonical_url\" />"
sed -i "/<\/head>/i$link_tag" "$file"
echo "Canonical link added to $file"
}
export -f remove_canonical_tag
export -f add_canonical_tag
find_html_files() {
local directory=$1
# Remove any canonical tags
find "$directory" -type f -name "*.html" \
-exec bash -c 'remove_canonical_tag "$0"' {} \;
# Add new canonical tags
find "$directory" -type f -name "*.html" \
! \( -name "announcement.html" -o -name "webpack-macros.html" -o -path "${directory}/index.html" \) \
-exec bash -c 'add_canonical_tag "$0"' {} \;
}
find_html_files ${{ inputs.version-directory }}
# Ensure that 'version/{stable|dev}/index.html' uses as canonical the
# landing page of the documentation
replace_canonical_link() {
local file="$1"
sed -i "s|<link rel=\"canonical\".*>|<link rel=\"canonical\" href=\"https://${{ inputs.cname }}/\">|g" "$file"
}
export -f replace_canonical_link
if [[ -f "${{ inputs.version-directory }}/stable/index.html" ]]; then
replace_canonical_link 'version/stable/index.html'
elif [[ -f "${{ inputs.version-directory }}/dev/index.html" ]]; then
replace_canonical_link 'version/dev/index.html'
else
echo "Error: The 'index.html' file does not exist." >&2
exit 1
fi
78 changes: 78 additions & 0 deletions _doc-gen-robots/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright (C) 2022 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

name: >
Generate a robots.txt file for a website.
description: |
This process creates a ``robots.txt`` file, which enhances the search
engine's browsing experience of our documentation. The process is a private
composite action that is executed as a component of the PyAnsys documentation
deployment strategies.
inputs:

# Required inputs

cname:
description: >
The canonical name (CNAME) containing the documentation.
required: true
type: string

runs:
using: "composite"
steps:

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
with:
level: "INFO"
message: >
Generating the "robots.txt" file.
- name: "Generate the robots.txt file"
shell: bash
run: |
rm robots.txt && touch robots.txt
- name: "Allow all agents to crawl the website"
shell: bash
run: |
echo -e "User-agent: *\n" >> robots.txt
- name: "Iterate over all versions except the "
shell:
run: |
for version in $(ls version |
grep -E "^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\..*)?$" | \
sort -r --version-sort | \
# Do not include the first version
tail -n +2); do
echo "Disallow: /version/${version}" >> robots.txt
done
- name: "Include the location of the sitemap.xml file"
shell: bash
run: |
echo -e "\nSitemap: https://${{ inputs.cname }}/sitemap.xml" >> robots.txt
90 changes: 44 additions & 46 deletions doc-deploy-dev/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,6 @@ inputs:
default: 'main-content'
type: string

redirection-title:
description: >
Title to be inserted in the redirection index.html coming from the
multi-version mechanism implemented. By default, it will assign
"Redirecting to ``https://<CNAME>/version/stable/``" or
"Redirecting to ``https://<CNAME>/version/dev/``" depending on whether
there is a stable version released already or not.
required: false
default: ''
type: string

redirection-description:
description: >
Description to be inserted in the redirection index.html coming from the
multi-version mechanism implemented. By default, it will be empty.
required: false
default: ''
type: string

runs:
using: "composite"
steps:
Expand Down Expand Up @@ -230,40 +211,38 @@ runs:
with:
level: "INFO"
message: >
Generate an 'index.html' for redirection to the latest stable version
of the documentation. If no stable version has been released, a
redirection to the development documentation is generated.
Include a link canonical tag in old versions if not present.
- name: "Include link canonical tag in pages"
uses: ansys/actions/_doc-gen-canonical@main
with:
cname: ${{ inputs.cname }}
version-directory: version

- name: "Generate the redirection URL"
shell: bash
run: |
if $(grep -q "(stable)" versions.json)
then
echo "Redirecting to the latest stable version..."
echo "REDIRECTION_URL=https://${{ inputs.cname }}/version/stable/" >> $GITHUB_ENV
else
echo "Redirecting to the latest development version..."
echo "REDIRECTION_URL=https://${{ inputs.cname }}/version/dev/" >> $GITHUB_ENV
fi
# ------------------------------------------------------------------------

- name: "Create the 'index.html' redirection file"
- uses: ansys/actions/_logging@main
with:
level: "INFO"
message: >
Copy the index.html from the stable version and update all
local href and source links to point to either the stable or dev version.
- name: "Use the latest 'version/{stable|dev}/index.html' in the landing page"
shell: bash
run: |
echo "<!DOCTYPE html>" > index.html
echo "<html>" >> index.html
echo " <head>" >> index.html
echo " <meta charset=\"utf-8\">" >> index.html
if [ -z "${{ inputs.redirection-title }}" ]; then
echo " <title>Redirecting to ${{ env.REDIRECTION_URL }}</title>" >> index.html
if [[ -f 'version/stable/index.html' ]]; then
cp version/stable/index.html index.html
sed -i 's/href="\([^http]\)/href="version\/stable\/\1/g' index.html
sed -i 's/src="\([^http]\)/src="version\/stable\/\1/g' index.html
elif [[ -f 'version/dev/index.html' ]]; then
cp version/dev/index.html index.html
sed -i 's/href="\([^http]\)/href="version\/dev\/\1/g' index.html
sed -i 's/src="\([^http]\)/src="version\/dev\/\1/g' index.html
else
echo " <title>${{ inputs.redirection-title }}</title>" >> index.html
echo "Error: The 'index.html' file does not exist." >&2
exit 1
fi
echo " <meta name=\"description\" content=\"${{ inputs.redirection-description }}\">" >> index.html
echo " <meta http-equiv=\"refresh\" content=\"0; URL=${{ env.REDIRECTION_URL }}\">" >> index.html
echo " <link rel=\"canonical\" href=\"${{ env.REDIRECTION_URL }}\">" >> index.html
echo " </head>" >> index.html
echo "</html>" >> index.html
- name: "Show the contents of the 'index.html' redirection file"
shell: bash
Expand Down Expand Up @@ -299,6 +278,25 @@ runs:
touch .nojekyll CNAME
echo "${{ inputs.cname }}" > CNAME
# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
# Apply this step only if 'version/stable/' dir exists
if: ${{ hashFiles('version/stable/' != '') }}
with:
level: "INFO"
message: >
Generate the site-map for the latest development or stable
documentation.
- name: "Generate 'sitemap.xml' file"
uses: ansys/actions/_doc-gen-sitemap@main
# Apply this step only if 'version/stable/' dir exists
if: ${{ hashFiles('version/stable/' != '') }}
with:
cname: ${{ inputs.cname }}
html-directory: version/stable

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
Expand Down

0 comments on commit ba4b48e

Please sign in to comment.