Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: seo improvements #421

Merged
merged 38 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
14b13ea
feat: do not include sitemap.xml
jorgepiloto Feb 2, 2024
868261a
fix: stop using redirect in favor of dev or stable index.html file (…
jorgepiloto Feb 26, 2024
9b252fa
feat: new _doc-gen-robots action to generate seo-compliant "robots.tx…
jorgepiloto Mar 11, 2024
a0c1413
Merge branch 'main' into feat/seo-improvements
Revathyvenugopal162 Mar 12, 2024
0bbc679
Merge branch 'main' into feat/seo-improvements
Revathyvenugopal162 Mar 13, 2024
ab9cad7
feat: new canonical link action (#425)
jorgepiloto Mar 20, 2024
b9be610
Merge branch 'main' into feat/seo-improvements
jorgepiloto Mar 20, 2024
3baad00
fix: action ref
jorgepiloto Mar 22, 2024
ac33eef
fix: variable substitution
jorgepiloto Mar 25, 2024
3d146bc
fix: Typo in ``Robots.txt`` file (#434)
Revathyvenugopal162 Mar 25, 2024
0e93d1c
Merge branch 'main' into feat/seo-improvements
jorgepiloto Apr 2, 2024
5d5e268
fix: step description
jorgepiloto Apr 2, 2024
88466a9
fix: variable substitution
jorgepiloto Apr 2, 2024
386032e
fix: always rewrite canonical link
jorgepiloto Apr 2, 2024
6bb7838
fix: update canonical in dev and stable
jorgepiloto Apr 2, 2024
1ad1bf6
fix: variable substitution in baseurl
jorgepiloto Apr 3, 2024
25bf384
Merge branch 'main' into feat/seo-improvements
jorgepiloto Apr 3, 2024
5a63c6d
fix: actions order
jorgepiloto Apr 5, 2024
b9b4cca
feat: restore sitemap creation
jorgepiloto Apr 8, 2024
b5f2df9
doc: improve step description
jorgepiloto Apr 8, 2024
3bad719
fix: canonical for landing page
jorgepiloto Apr 8, 2024
8f3596d
Merge branch 'main' into feat/seo-improvements
jorgepiloto Apr 8, 2024
fde6f92
feat: deploy sitemap in dev too
jorgepiloto Apr 9, 2024
a1cc531
doc: improve step description
jorgepiloto Apr 9, 2024
83de792
Merge branch 'main' into feat/seo-improvements
jorgepiloto Apr 9, 2024
fdcab00
fix: syntax
jorgepiloto Apr 9, 2024
f20e2af
Merge branch 'main' into feat/seo-improvements
jorgepiloto Apr 9, 2024
aefbd62
doc: include info about new SEO improvements
jorgepiloto Apr 10, 2024
a08f4d1
doc: remove base_url option in conf.py
jorgepiloto Apr 10, 2024
91ba8d9
doc: document under development section
jorgepiloto Apr 11, 2024
d6ddc4d
Merge branch 'main' into feat/seo-improvements
jorgepiloto Apr 15, 2024
824334b
fix: ensure canonical links are removed and do not include canonical …
jorgepiloto Apr 16, 2024
9da9881
fix: remove duplicated function
jorgepiloto Apr 16, 2024
3701afe
Merge branch 'main' into feat/seo-improvements
jorgepiloto Apr 16, 2024
ef3622f
doc: fix style
jorgepiloto Apr 16, 2024
9ecbfe7
doc: fix style
jorgepiloto Apr 16, 2024
014aca0
Merge branch 'main' into feat/seo-improvements
jorgepiloto Apr 17, 2024
24b033e
fix: update references to main
jorgepiloto Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
90 changes: 90 additions & 0 deletions _doc-gen-canonical/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# 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

html-directory:
description: >
Name of the directory containing the HTML files 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
grep -vP '<link\s+rel="canonical".*\/>' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
}

add_canonical_tag() {
local file=$1
local filename=$(basename "$file")
local relative_path=${file#*version/*/}
local baseurl="https://geometry.docs.pyansys.com/version/stable"
jorgepiloto marked this conversation as resolved.
Show resolved Hide resolved
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
find "$directory" -type f -name "*.html" \
! \( -name "announcement.html" -o -name "webpack-macros.html" \) \
-exec bash -c 'remove_canonical_tag "$0" && add_canonical_tag "$0"' {} \;
}

find_html_files ${{ inputs.html-directory }}
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
77 changes: 34 additions & 43 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,36 @@ 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.
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: "Generate the redirection URL"
- name: "Update the canonical link tags in the 'index.html' file"
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
if [[ -f 'version/stable/index.html' ]]; then
sed -i "s|<link rel=\"canonical\" href=\"https://${{ inputs.cname }}/version/stable/\"|<link rel=\"canonical\" href=\"https://${{ inputs.cname }}/\"|g" version/stable/index.html
elif [[ -f 'version/dev/index.html' ]]; then
sed -i "s|<link rel=\"canonical\" href=\"https://${{ inputs.cname }}/version/dev/\"|<link rel=\"canonical\" href=\"https://${{ inputs.cname }}/\"|g" version/dev/index.html
else
echo "Redirecting to the latest development version..."
echo "REDIRECTION_URL=https://${{ inputs.cname }}/version/dev/" >> $GITHUB_ENV
echo "Error: The 'index.html' file does not exist." >&2
exit 1
fi

- name: "Create the 'index.html' redirection file"
- name: "Use the latest 'index.html' in base index.html 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 +276,20 @@ runs:
touch .nojekyll CNAME
echo "${{ inputs.cname }}" > CNAME

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

- uses: ansys/actions/_logging@main
with:
level: "INFO"
message: >
Include a link canonical tag in old versions if not present.

- name: "Include link canonical tag in pages"
uses: ansys/actions/_doc-gen-canonical@feat/seo-improvements
with:
cname: ${{ inputs.cname }}
html-directory: version

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

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