Commit 88fac2f

HPCesia <me@hpcesia.com>
2026-03-12 10:35:18
Fix assets import path
1 parent c4d6668
Changed files (1)
src
integrations
src/integrations/extract-image.ts
@@ -5,7 +5,8 @@ import { z } from "astro/zod";
 import { defineIntegration } from "astro-integration-kit";
 import * as cheerio from "cheerio";
 import { getBase64ImageInfo } from "../utils/image.js";
-import { url } from "../utils/url.js";
+import { joinUrl, url } from "../utils/url.js";
+import type { AstroConfig } from "astro";
 
 // TODO: After Typst 0.15 published, use jsx and path to auto optimize images in typst
 // See https://github.com/typst/typst/pull/7555
@@ -17,8 +18,12 @@ export const extractImage = defineIntegration({
     dir: z.string().optional().default("assets/img/typ"),
   }),
   setup({ options }) {
+    let _astroConfig: AstroConfig;
     return {
       hooks: {
+        "astro:config:done": async ({ config }) => {
+          _astroConfig = config;
+        },
         "astro:build:done": async ({ dir, logger }) => {
           const rootDir = fileURLToPath(dir);
           const outDir = path.join(rootDir, options.dir);
@@ -71,7 +76,10 @@ export const extractImage = defineIntegration({
                     }
                   }
 
-                  $(el).attr("src", url(`/${options.dir}/${filename}`));
+                  $(el).attr(
+                    "src",
+                    joinUrl(_astroConfig.base, `/${options.dir}/${filename}`),
+                  );
                   htmlChanged = true;
                 }