-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Revathy Venugopal <[email protected]> Co-authored-by: Roberto Pastor Muela <[email protected]> Co-authored-by: Revathyvenugopal162 <[email protected]>
- Loading branch information
1 parent
53d8d5e
commit ba4b48e
Showing
6 changed files
with
290 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.