Skip to content

Commit adf3b95

Browse files
Updated scripts (#78)
* updated scripts * added workflow template and updated readme * updated note * updated readme * updated files
1 parent a7c1f47 commit adf3b95

File tree

4 files changed

+71
-11
lines changed

4 files changed

+71
-11
lines changed

assets/scripts/DocsNav.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Add Navbar
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Documentation"] # add workflow names that generates docs in this list like `workflows: ["Docs Workflow", "Previews Workflow]`
6+
types:
7+
- completed
8+
workflow_dispatch: # Allows manual triggering
9+
10+
jobs:
11+
add-navbar:
12+
runs-on: ubuntu-latest
13+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
14+
permissions:
15+
contents: write
16+
steps:
17+
- name: Checkout gh-pages
18+
uses: actions/checkout@v4
19+
with:
20+
ref: gh-pages
21+
fetch-depth: 0
22+
23+
- name: Download insert_navbar.sh
24+
run: |
25+
curl -O https://raw.githubusercontent.com/TuringLang/turinglang.github.io/main/assets/scripts/insert_navbar.sh
26+
chmod +x insert_navbar.sh
27+
28+
- name: Update Navbar
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
run: |
32+
git config user.name github-actions[bot]
33+
git config user.email github-actions[bot]@users.noreply.github.com
34+
35+
# Update all HTML files in the current directory (gh-pages root)
36+
./insert_navbar.sh .
37+
38+
# Remove the insert_navbar.sh file
39+
rm insert_navbar.sh
40+
41+
# Check if there are any changes
42+
if [[ -n $(git status -s) ]]; then
43+
git add .
44+
git commit -m "Added navbar and removed insert_navbar.sh"
45+
git push "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" gh-pages
46+
else
47+
echo "No changes to commit"
48+
fi

assets/scripts/README.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ This `scripts` folder contains utilities for building Turing language satellite
55

66
## How to use
77

8-
Add the following line after `makedocs()` function in `docs/make.jl` of each package:
8+
Add a new Github Actions workflow, `DocsNav.yml` in your `main` or `master` branch and update 5th line, `workflows` in `DocsNav.yml` by adding your other workflow names that are generating docs site, previews and publishing them to gh-pages branch.
99

10-
```julia
11-
# Insert navbar in each html file
12-
run(`sh -c "curl -s https://raw.githubusercontent.com/TuringLang/turinglang.github.io/main/assets/scripts/insert_navbar.sh | bash -s docs/build"`)
13-
```
10+
You can find `DocsNav.yml` template [here](DocsNav.yml).
1411

1512
See https://github.com/TuringLang/AbstractMCMC.jl/pull/141 for an example.

assets/scripts/insert_navbar.sh

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/bash
22

3-
# This script inserts a top navigation bar (e.g., `navbar.html`) into Documenter.jl generated sites.
4-
# The resulting output is similar to MultiDocumenter's navigation menu. The navigation menu is
3+
# This script inserts a top navigation bar (e.g., `navbar.html`) into Documenter.jl generated sites.
4+
# The resulting output is similar to MultiDocumenter's navigation menu. The navigation menu is
55
# hard-coded at the moment, which could be improved in the future.
6+
# It checks all HTML files in the specified directory and its subdirectories.
67

78
# URL of the navigation bar HTML file
89
NAVBAR_URL="https://raw.githubusercontent.com/TuringLang/turinglang.github.io/main/assets/scripts/navbar.html"
@@ -19,15 +20,27 @@ if [ -z "$NAVBAR_HTML" ]; then
1920
exit 1
2021
fi
2122

22-
# Process each HTML file in the directory
23-
for file in $(find $HTML_DIR -name "*.html"); do
23+
# Process each HTML file in the directory and its subdirectories
24+
find "$HTML_DIR" -name "*.html" | while read file; do
25+
# Remove the existing navbar HTML section if present
26+
if grep -q "<!-- NAVBAR START -->" "$file"; then
27+
awk '/<!-- NAVBAR START -->/{flag=1;next}/<!-- NAVBAR END -->/{flag=0;next}!flag' "$file" > temp && mv temp "$file"
28+
echo "Removed existing navbar from $file"
29+
fi
30+
2431
# Read the contents of the HTML file
2532
file_contents=$(cat "$file")
2633

2734
# Insert the navbar HTML after the <body> tag
28-
updated_contents="${file_contents/$'<body>'/$'<body>\n'$NAVBAR_HTML}"
35+
updated_contents="${file_contents/<body>/<body>
36+
$NAVBAR_HTML
37+
}"
2938

3039
# Write the updated contents back to the file
3140
echo "$updated_contents" > "$file"
32-
echo "Updated $file"
41+
42+
# Remove trailing blank lines immediately after the navbar
43+
awk 'BEGIN {RS=""; ORS="\n\n"} {gsub(/\n+$/, ""); print}' "$file" > temp_cleaned && mv temp_cleaned "$file"
44+
45+
echo "Inserted new navbar into $file"
3346
done

assets/scripts/navbar.html

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- NAVBAR START -->
12
<style>
23
html {
34
scroll-padding-top: calc(55px + 1rem);
@@ -459,3 +460,4 @@
459460
setAppropriateHeight();
460461
});
461462
</script>
463+
<!-- NAVBAR END -->

0 commit comments

Comments
 (0)