fix(web): fix Typst PDF generation path resolution
- Change SVG image paths from absolute to relative in typstGenerator
- Execute typst compilation from tempDir with cwd option
- Fixes "file not found" error caused by Typst doubling absolute paths
Root cause: Typst treats absolute paths as relative and prepends working
directory, resulting in incorrect paths like:
/tmp/calendar-123/tmp/calendar-123/year.svg
Solution: Use relative paths ("year.svg") and run from tempDir.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -73,10 +73,11 @@ export async function POST(request: NextRequest) {
|
||||
const typstPath = join(tempDir, 'calendar.typ')
|
||||
writeFileSync(typstPath, typstContent)
|
||||
|
||||
// Compile with Typst
|
||||
// Compile with Typst (run from tempDir so relative paths work)
|
||||
const pdfPath = join(tempDir, 'calendar.pdf')
|
||||
try {
|
||||
execSync(`typst compile "${typstPath}" "${pdfPath}"`, {
|
||||
execSync(`typst compile "calendar.typ" "calendar.pdf"`, {
|
||||
cwd: tempDir,
|
||||
stdio: 'pipe',
|
||||
})
|
||||
} catch (error) {
|
||||
|
||||
@@ -68,7 +68,7 @@ export function generateMonthlyTypst(config: TypstConfig): string {
|
||||
|
||||
// Day cells
|
||||
for (let day = 1; day <= daysInMonth; day++) {
|
||||
cells += ` [#image("${tempDir}/day-${day}.svg", width: 90%)],\n`
|
||||
cells += ` [#image("day-${day}.svg", width: 90%)],\n`
|
||||
}
|
||||
|
||||
return `#set page(
|
||||
@@ -85,7 +85,7 @@ export function generateMonthlyTypst(config: TypstConfig): string {
|
||||
#v(0.5em)
|
||||
|
||||
// Year as abacus
|
||||
#image("${tempDir}/year.svg", width: 35%)
|
||||
#image("year.svg", width: 35%)
|
||||
]
|
||||
|
||||
#v(1.5em)
|
||||
@@ -127,14 +127,14 @@ export function generateDailyTypst(config: TypstConfig): string {
|
||||
// Header: Year
|
||||
#align(center)[
|
||||
#v(1em)
|
||||
#image("${tempDir}/year.svg", width: 30%)
|
||||
#image("year.svg", width: 30%)
|
||||
]
|
||||
|
||||
#v(2em)
|
||||
|
||||
// Main: Day number as large abacus
|
||||
#align(center + horizon)[
|
||||
#image("${tempDir}/day-${day}.svg", width: 50%)
|
||||
#image("day-${day}.svg", width: 50%)
|
||||
]
|
||||
|
||||
#v(2em)
|
||||
|
||||
Reference in New Issue
Block a user