Skip to content

Fix path issue?

Fix path issue? #36

name: Deploy in Github Pages
on:
push:
paths:
- 'slides/**'
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: Install slidev
run: npm i -g @slidev/cli
- name: Get modified slide directories
run: |
# Get the list of modified slide markdown files
modified_files=$(git show ${{ github.sha }} --name-only | grep "^slides/.*/.*\.\(md\|vue\|ts\|tsx\|js\|jsx\|html\|css\)$")
echo "Modified files: $modified_files"
# Temporary file to store directories
temp_file=$(mktemp)
# Loop through modified files and extract their directories
for file in $modified_files; do
dir=$(dirname $file)
first_two_parts=$(echo "$dir" | awk -F'/' '{print $1 "/" $2}')
# Add directory to temporary file
echo "$first_two_parts" >> "$temp_file"
done
echo "Modified directories: $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
for dir in ${{ env.modified_dirs }}; do
mkdir -p build/$(echo "$dir" | awk -F'slides/' '{print $2}')
done
- name: Build modified slides
if: env.modified_dirs != ''
run: |
for dir in ${{ env.modified_dirs }}; do
slidev build --base /lectures/$dir $dir/slides.md
echo */*/*/
mv lectures/$dir/dist /build/$(echo "$dir" | awk -F'slides/' '{print $2}') -v
done
- name: Create index.html
run: |
# Create index.html with links to all talks
echo "<html><body><h1>Lectures</h1><ul>" > build/index.html
for dir in ${{ env.modified_dirs }}; do
slide=$(basename "$dir")
echo "<li><a href=\"/lectures/$slide\">$slide</a></li>" >> build/index.html
done
echo "</ul></body></html>" >> build/index.html
- 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 }}