Skip to content

Fix typo

Fix typo #108

name: Deploy in Github Pages
on:
push:
paths:
- 'published/**'
- 'index.css'
- 'common/**/*.md'
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Get modified slide directories
run: |
# Get the list of modified files
modified_files=$(git show ${{ github.sha }} --name-only)
echo "Modified files: $modified_files"
# Check if index.css is modified
if echo "$modified_files" | grep -q "^index.css$"; then
echo "index_css_modified=true" >> $GITHUB_ENV
else
echo "index_css_modified=false" >> $GITHUB_ENV
fi
# Check if any markdown files in the common directory are modified
if echo "$modified_files" | grep -q "^common/.*\.md$"; then
echo "common_md_modified=true" >> $GITHUB_ENV
else
echo "common_md_modified=false" >> $GITHUB_ENV
fi
# Get modified published directories
published_dirs=$(echo "$modified_files" | grep "^published/.*/.*\.\(md\|vue\|ts\|tsx\|js\|jsx\|html\|css\)$" | xargs -I {} dirname {} | sort | uniq)
echo "Modified slide directories: $published_dirs"
# Temporary file to store directories
temp_file=$(mktemp)
# Loop through modified files and find the closest parent directory with a markdown file
for dir in $published_dirs; do
while [ "$dir" != "." ]; do
if ls "$dir"/*.md >/dev/null 2>&1; then
echo "$dir" >> "$temp_file"
break
fi
dir=$(dirname "$dir")
done
done
echo "Directories with markdown files: $(cat $temp_file)"
# Remove duplicates and store the result in modified_dirs
modified_dirs=$(sort "$temp_file" | uniq | tr '\n' ' ')
# Clean up temporary file
rm "$temp_file"
echo "Unique modified directories: $modified_dirs"
# Output the modified directories to be used as an environment variable
echo "modified_dirs=${modified_dirs}" >> $GITHUB_ENV
- name: Create build directory
run: |
mkdir -p build
if [ "${{ env.common_md_modified }}" = "true" ]; then
# Create folders for all slide projects if common markdown modified
find published -type f -name "slides.md" | while read -r file; do
dir=$(dirname "$file")
mkdir -p build/$(echo "$dir" | awk -F'published/' '{print $2}')
done
else
# Only create folders for modified directories
for dir in ${{ env.modified_dirs }}; do
mkdir -p build/$(echo "$dir" | awk -F'published/' '{print $2}')
done
fi
- name: Build modified slides
if: env.modified_dirs != '' || env.common_md_modified == 'true'
run: |
if [ "${{ env.common_md_modified }}" = "true" ]; then
# Rebuild all slides if common markdown modified
find published -type f -name "slides.md" | while read -r file; do
dir=$(dirname "$file")
npm run build -- --base /lectures/$(echo "$dir" | awk -F'published/' '{print $2}')/ $file
mv $dir/dist/* build/$(echo "$dir" | awk -F'published/' '{print $2}') -v
done
else
# Only build modified slides
for dir in ${{ env.modified_dirs }}; do
npm run build -- --base /lectures/$(echo "$dir" | awk -F'published/' '{print $2}')/ $dir/slides.md
mv $dir/dist/* build/$(echo "$dir" | awk -F'published/' '{print $2}') -v
done
fi
- name: Build index.html
if: env.index_css_modified == 'true' || env.modified_dirs != '' || env.common_md_modified == 'true'
run: |
if [[ -f index.css ]]; then
mv index.css build/index.css
fi
# Temporary file to store links
temp_links_file=$(mktemp)
# Find all directories containing a slides.md file and extract their relative paths
find published -type f -name "slides.md" | while read -r file; do
dir=$(dirname "$file")
slide_path=$(echo "$dir" | sed 's|published/||')
echo "$slide_path" >> "$temp_links_file"
done
# Sort the links lexicographically and remove duplicates
sorted_links=$(sort "$temp_links_file" | uniq)
echo "Sorted links: $sorted_links"
# Begin writing the new index.html in the lectures directory
{
echo '<!DOCTYPE html>'
echo '<html lang="en">'
echo '<head>'
echo ' <meta charset="UTF-8">'
echo ' <meta name="viewport" content="width=device-width, initial-scale=1.0">'
echo ' <link rel="stylesheet" href="./index.css">'
echo ' <title>Lectures</title>'
echo '</head>'
echo '<body class="container">'
echo ' <h1>Lecture Presentations</h1>'
echo ' <ul>'
# Add sorted links to index.html
for link in $sorted_links; do
echo " <li><a href=\"$link/\">$link</a></li>"
done
echo ' </ul>'
echo '</body>'
echo '</html>'
} > build/index.html
# Clean up temporary files
rm "$temp_links_file"
- name: Deploy slides 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages # The branch the action should deploy to.
folder: build # The folder the action should deploy.
target-folder: ''
clean: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}