Skip to content

Commit

Permalink
Initial gh-pages branch
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertRostohar committed May 23, 2024
0 parents commit 6aaccc3
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to GitHub Pages

on:
# Runs on pushes targeting the default branch
push:
branches: [gh-pages]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Pages
uses: actions/configure-pages@v5

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: '.'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Redirect to the Middleware Documentation after 0 seconds</title>
<meta http-equiv="refresh" content="0; URL=latest/General/index.html">
<meta name="keywords" content="automatic redirection">
</head>

<body>

If the automatic redirection is failing, click <a href="latest/General/index.html">Middleware Documentation</a>.

</body>
</html>
1 change: 1 addition & 0 deletions latest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main
65 changes: 65 additions & 0 deletions update_versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

if [[ "$(uname)" == "Darwin" ]]; then
if ! type gfind >/dev/null 2>&1; then
echo "Error: GNU find requires. Run 'brew install findutils' to install." >&2
exit 1
fi
shopt -s expand_aliases
alias find=gfind
alias head=ghead
alias tail=gtail
fi

LINES=($(grep -n 'list of versions' version.js | cut -d: -f1))
VERSIONS_BEGIN=$(expr ${LINES[0]} - 1)
VERSIONS_END=$(expr ${LINES[1]} + 1)

get_versions() {
local folders=($(find -maxdepth 1 -mindepth 1 -type d) $(find -maxdepth 1 -mindepth 1 -type l))
declare -A versions
for folder in "${folders[@]#./}"; do
if [ -f "${folder}/${1}/footer.js" ]; then
version=$(grep "Version" "${folder}/${1}/footer.js" | \
sed -r "s/.*'Version ([^']+)'.*/\1/" | \
sed -r "s/\+.*$//" | \
sed -r "s/([^0-9])$/\10/")
versions["$version"]="$folder"
fi
done
fields=()
for version in $(IFS=$'\n'; sed -r 's/$/_/' <<< "${!versions[*]}" | sort -Vr | sed -r 's/_$//'); do
fields+=( "\"${versions[$version]}\": \"$version\"" )
done

echo " \"$1\": {"
echo -n " "
echo "$(IFS=,; echo "${fields[*]}")" | sed 's/,/,\n /g'
echo -n " }"
}

mv version.js version.js.bak

head -n "${VERSIONS_BEGIN}" version.js.bak > version.js
echo "//--- list of versions‚ ---" >> version.js
echo "const versions = {" >> version.js

get_versions "General" >> version.js
echo "," >> version.js

get_versions "FileSystem" >> version.js
echo "," >> version.js

get_versions "Network" >> version.js
echo "," >> version.js

get_versions "USB" >> version.js
echo "," >> version.js

echo "}" >> version.js
echo "//--- list of versions ---" >> version.js
tail -n "+${VERSIONS_END}" version.js.bak >> version.js

rm version.js.bak

exit 0
80 changes: 80 additions & 0 deletions version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//--- list of versions‚ ---
const versions = {
"General": {
"main": "8.0.0"
},
"FileSystem": {
"main": "8.0.0"
},
"Network": {
"main": "8.0.0"
},
"USB": {
"main": "8.0.0"
},
}
//--- list of versions ---

const components = {
"MDK-Middleware": "General",
"File System Component": "FileSystem",
"Network Component": "Network",
"USB Component": "USB"
}

var script = document.currentScript
if (script && script.src) {
var scriptUrl = new URL(script.src);
var docUrl = new URL(document.URL);
var baseUrl = new URL(scriptUrl)
baseUrl.pathname = baseUrl.pathname.split('/').slice(0,-1).join("/")

function urlForVersion(url, version) {
url = new URL(url);
pathname = url.pathname.replace(baseUrl.pathname, "");
parts = pathname.split("/");
parts[1] = version;
url.pathname = baseUrl.pathname + parts.join("/");
return url
}

function writeVersionDropdown(component) {
folder = components[component]
currentVersion = document.currentScript.parentNode.innerText;
document.currentScript.parentNode.classList.add("dropdown");
document.currentScript.parentNode.innerText = "";
document.write(' <span onclick="myFunction()" class="dropbtn">'+currentVersion+'</span>');
document.write(' <div id="myDropdown" class="dropdown-content">');
for(var version in versions[folder]) {
var label = versions[folder][version];
if (label != version) {
label += " ("+version+")"
}
label = "Version " + label
document.write(' <a href="'+urlForVersion(docUrl, version)+'">'+label+'</a>');
}
document.write(' </div>');
};
} else {
function writeVersionDropdown() {}
}

/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}

// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}

0 comments on commit 6aaccc3

Please sign in to comment.