2121 with :
2222 ref : Admin
2323 path : logseq-source
24+ fetch-depth : 0
2425
2526 - name : Checkout Web-live branch (Quartz site)
2627 uses : actions/checkout@v4
@@ -49,43 +50,64 @@ jobs:
4950 echo "files_before=$before" >> $GITHUB_OUTPUT
5051 echo "files_after=$after" >> $GITHUB_OUTPUT
5152
52- - name : Setup Node.js
53- uses : actions/setup-node@v4
54- with :
55- node-version : 22
56-
57- - name : Cache node_modules
58- id : cache-node-modules
59- uses : actions/cache@v4
60- with :
61- path : quartz-site/node_modules
62- key : ${{ runner.os }}-node-modules-${{ hashFiles('quartz-site/package-lock.json') }}
63-
64- - name : Install dependencies
65- if : steps.cache-node-modules.outputs.cache-hit != 'true'
53+ - name : Inject Git Timestamps into Frontmatter
6654 run : |
67- cd quartz-site
68- npm ci
69-
70- - name : Cache Quartz build cache
71- uses : actions/cache@v4
72- with :
73- path : quartz-site/.quartz-cache
74- key : ${{ runner.os }}-quartz-cache-${{ github.run_id }}-${{ github.run_attempt }}
75- restore-keys : |
76- ${{ runner.os }}-quartz-cache-
77-
78- - name : Build Quartz site
79- run : |
80- cd quartz-site
81- npx quartz build
82-
83- - name : Check for changes in content/ and public/
55+ cat << 'EOF' > inject_dates.py
56+ import os
57+ import subprocess
58+ import re
59+
60+ source_dir = 'logseq-source/pages'
61+ dest_dir = 'quartz-site/content'
62+
63+ if not os.path.exists(source_dir):
64+ exit(0)
65+
66+ for filename in os.listdir(source_dir):
67+ if not filename.endswith('.md'):
68+ continue
69+
70+ dest_path = os.path.join(dest_dir, filename)
71+ if not os.path.exists(dest_path):
72+ continue
73+
74+ created_cmd = ['git', 'log', '--diff-filter=A', '--format=%aI', '-1', '--', f"pages/{filename}"]
75+ updated_cmd = ['git', 'log', '-1', '--format=%aI', '--', f"pages/{filename}"]
76+
77+ try:
78+ created = subprocess.run(created_cmd, cwd='logseq-source', capture_output=True, text=True, check=True).stdout.strip()
79+ updated = subprocess.run(updated_cmd, cwd='logseq-source', capture_output=True, text=True, check=True).stdout.strip()
80+ except subprocess.CalledProcessError:
81+ continue
82+
83+ if not created or not updated:
84+ continue
85+
86+ with open(dest_path, 'r', encoding='utf-8') as f:
87+ content = f.read()
88+
89+ inject = ""
90+ if not re.search(r'^date:\s+', content, flags=re.MULTILINE):
91+ inject += f"date: {created}\n"
92+ if not re.search(r'^lastmod:\s+', content, flags=re.MULTILINE):
93+ inject += f"lastmod: {updated}\n"
94+
95+ if inject:
96+ if content.startswith('---'):
97+ content = content.replace('---', f'---\n{inject}', 1)
98+ else:
99+ content = f'---\n{inject}---\n' + content
100+
101+ with open(dest_path, 'w', encoding='utf-8') as f:
102+ f.write(content)
103+ EOF
104+ python3 inject_dates.py
105+
106+ - name : Check for changes in content/
84107 id : changes
85108 run : |
86109 cd quartz-site
87110 git add content/
88- git add -f public/
89111 if git diff --staged --quiet; then
90112 echo "has_changes=false" >> $GITHUB_OUTPUT
91113 echo "No changes detected — skipping deploy."
@@ -104,19 +126,18 @@ jobs:
104126 COMMIT_SHA=$(cd ../logseq-source && git rev-parse --short HEAD)
105127
106128 git add content/
107- git add -f public/
108129 git commit -m "sync: ${{ steps.changes.outputs.changed_count }} file(s) updated from Logseq (Admin@$COMMIT_SHA)"
109130 git push origin Web-live
110131
111132 - name : Summary
112133 run : |
113134 if [ "${{ steps.changes.outputs.has_changes }}" == "true" ]; then
114- echo "### ✅ Sync & Build complete" >> $GITHUB_STEP_SUMMARY
135+ echo "### ✅ Sync complete" >> $GITHUB_STEP_SUMMARY
115136 echo "- **Files before:** ${{ steps.sync.outputs.files_before }}" >> $GITHUB_STEP_SUMMARY
116137 echo "- **Files after:** ${{ steps.sync.outputs.files_after }}" >> $GITHUB_STEP_SUMMARY
117- echo "- **Changed files (source & build) :** ${{ steps.changes.outputs.changed_count }}" >> $GITHUB_STEP_SUMMARY
118- echo "- Pre-built \`public/\` files pushed to **Web-live**. Vercel will deploy instantly ." >> $GITHUB_STEP_SUMMARY
138+ echo "- **Changed files:** ${{ steps.changes.outputs.changed_count }}" >> $GITHUB_STEP_SUMMARY
139+ echo "- Content files pushed to **Web-live**. Vercel will build and deploy ." >> $GITHUB_STEP_SUMMARY
119140 else
120141 echo "### ⏭️ No changes" >> $GITHUB_STEP_SUMMARY
121- echo "Content and build output were already up to date — no commit made." >> $GITHUB_STEP_SUMMARY
142+ echo "Content was already up to date — no commit made." >> $GITHUB_STEP_SUMMARY
122143 fi
0 commit comments