Skip to content

Commit 58ad59a

Browse files
committed
build: improve typst build workflow
1 parent ae1b35d commit 58ad59a

File tree

1 file changed

+88
-12
lines changed

1 file changed

+88
-12
lines changed

.github/workflows/ci.yml

Lines changed: 88 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
steps:
1515
- name: Checkout repository
1616
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0 # Fetch all history for git log commands
1719

1820
- name: Setup Typst
1921
uses: typst-community/setup-typst@v3
@@ -33,6 +35,9 @@ jobs:
3335
3436
- name: Build PDFs from Typst projects
3537
run: |
38+
# Create a file to store modification dates
39+
touch modification_dates.txt
40+
3641
for dir in $TYPST_DIRS; do
3742
if [ -f "$dir/main.typst" ]; then
3843
main_file="$dir/main.typst"
@@ -48,25 +53,96 @@ jobs:
4853
4954
# Try to compile, continue if there's an error
5055
typst compile "$main_file" "build/$rel_dir/main.pdf" || echo "Failed to build $main_file, continuing..."
56+
57+
# If build was successful, get the last modified date based on content changes
58+
if [ -f "build/$rel_dir/main.pdf" ]; then
59+
# Get the last commit date that modified ANY file in this directory or subdirectories
60+
# This captures changes to includes, images, data files, etc.
61+
last_modified=$(git log -1 --format="%ad" --date=format:"%Y-%m-%d" -- "$dir")
62+
63+
# If git log fails (e.g., directory not yet committed), use file system date
64+
if [ -z "$last_modified" ]; then
65+
last_modified=$(find "$dir" -type f -printf "%TY-%Tm-%Td\n" | sort -r | head -n1)
66+
fi
67+
68+
# Store the file path and its last modified date
69+
echo "$rel_dir/main.pdf|$last_modified" >> modification_dates.txt
70+
fi
5171
done
5272
53-
- name: Generate README with links
73+
- name: Generate Enhanced README
5474
run: |
55-
echo "# Typst Project PDFs" > build/README.md
56-
echo "" >> build/README.md
57-
echo "This branch contains automatically built PDFs from Typst source files." >> build/README.md
75+
# Create header with site info
76+
cat > build/README.md << 'EOF'
77+
# 📚 Typst Project Documentation
78+
79+
<div align="center">
80+
<img src="https://raw.githubusercontent.com/typst/typst/main/assets/images/isologo.svg" width="120" alt="Typst Logo">
81+
<h3>Automatically Generated PDF Documents</h3>
82+
<p>
83+
<em>This site hosts the compiled PDF files from the Typst project source files.</em>
84+
</p>
85+
</div>
86+
87+
---
88+
89+
## 📄 Available Documents
90+
91+
<table>
92+
<thead>
93+
<tr>
94+
<th align="left">Document</th>
95+
<th align="left">Last Content Update</th>
96+
<th align="center">View</th>
97+
<th align="center">Download</th>
98+
</tr>
99+
</thead>
100+
<tbody>
101+
EOF
102+
103+
# Add table rows for each PDF
104+
while IFS="|" read -r file_path last_mod_date; do
105+
pdf_name=$(basename "$(dirname "$file_path")")
106+
echo " <tr>" >> build/README.md
107+
echo " <td><strong>$pdf_name</strong></td>" >> build/README.md
108+
echo " <td>$last_mod_date</td>" >> build/README.md
109+
echo " <td align=\"center\"><a href=\"$file_path\">📕 View</a></td>" >> build/README.md
110+
echo " <td align=\"center\"><a href=\"$file_path\" download>⬇️ PDF</a></td>" >> build/README.md
111+
echo " </tr>" >> build/README.md
112+
done < modification_dates.txt
113+
114+
# Close the table
115+
echo " </tbody>" >> build/README.md
116+
echo " </table>" >> build/README.md
58117
echo "" >> build/README.md
59-
echo "## Available PDFs" >> build/README.md
118+
119+
# Add original README content if it exists
120+
echo "## 📝 Project Information" >> build/README.md
60121
echo "" >> build/README.md
61122
62-
find build -name "*.pdf" | sort | while read pdf; do
63-
relative_path="${pdf#build/}"
64-
echo "- [$relative_path]($relative_path)" >> build/README.md
65-
done
123+
if [ -f "README.md" ]; then
124+
echo "<details open>" >> build/README.md
125+
echo "<summary><strong>Original README from main branch</strong></summary>" >> build/README.md
126+
echo "" >> build/README.md
127+
echo "$(cat README.md)" >> build/README.md
128+
echo "" >> build/README.md
129+
echo "</details>" >> build/README.md
130+
else
131+
echo "*No README.md found in the main branch*" >> build/README.md
132+
fi
66133
67-
# Add timestamp to show when the build was last run
68-
echo "" >> build/README.md
69-
echo "Last built: $(date)" >> build/README.md
134+
# Add footer with build info
135+
cat >> build/README.md << EOF
136+
137+
---
138+
139+
<div align="center">
140+
<p>
141+
<small>Last build: $(date)</small><br>
142+
<small>Generated by GitHub Actions • <a href="https://github.com/${GITHUB_REPOSITORY}/tree/main">View Source</a></small>
143+
</p>
144+
</div>
145+
EOF
70146
71147
- name: Deploy to GitHub Pages
72148
uses: JamesIves/github-pages-deploy-action@v4

0 commit comments

Comments
 (0)