From adad84d3aba7c97d1a2359b75f212973f2c77968 Mon Sep 17 00:00:00 2001 From: Artyom Sovetnikov <2056864+elringus@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:00:47 +0300 Subject: [PATCH] add asset import (#15) --- docs/.vitepress/config.ts | 1 + docs/guide/asset-import.md | 48 +++++++++++++++++++++++++++ docs/guide/getting-started.md | 2 +- docs/guide/integrations/astro.md | 49 +++++++++++++++++++++++++++- docs/guide/integrations/nuxt.md | 2 +- docs/guide/integrations/remix.md | 2 +- docs/guide/integrations/solid.md | 2 +- docs/guide/integrations/svelte.md | 2 +- docs/guide/integrations/vite.md | 2 +- docs/guide/integrations/vitepress.md | 2 +- docs/package.json | 2 +- package.json | 8 ++--- samples/astro/README.md | 2 +- samples/astro/package.json | 4 +-- samples/astro/src/env.d.ts | 1 + samples/astro/src/pages/import.astro | 31 ++++++++++++++++++ samples/astro/src/pages/index.astro | 2 ++ scripts/build.sh | 1 + src/client.d.ts | 5 +++ src/plugin/vite.ts | 10 ++++-- src/server/import.ts | 46 ++++++++++++++++++++++++++ src/server/index.ts | 1 + src/server/transform/5-encode.ts | 4 +-- src/server/transform/6-build.ts | 22 ++++++++----- src/server/transform/index.ts | 8 ++--- src/tsconfig.json | 2 -- test/server/import.spec.ts | 45 +++++++++++++++++++++++++ test/server/vite.spec.ts | 26 +++++++++++++++ 28 files changed, 297 insertions(+), 35 deletions(-) create mode 100644 docs/guide/asset-import.md create mode 100644 samples/astro/src/pages/import.astro create mode 100644 src/client.d.ts create mode 100644 src/server/import.ts create mode 100644 test/server/import.spec.ts diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 1fe3503..1e77ee2 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -55,6 +55,7 @@ export default defineConfig({ items: [ { text: "Introduction", link: "/guide/" }, { text: "Getting Started", link: "/guide/getting-started" }, + { text: "Asset Import", link: "/guide/asset-import" }, { text: "GPU Acceleration", link: "/guide/gpu-acceleration" }, { text: "Plugins", link: "/guide/plugins" } ] diff --git a/docs/guide/asset-import.md b/docs/guide/asset-import.md new file mode 100644 index 0000000..fe9e593 --- /dev/null +++ b/docs/guide/asset-import.md @@ -0,0 +1,48 @@ +# Asset Import + +By default, imgit is set up to detect and transform Markdown syntax in the source content. This works best for simple documentation and blog websites, but may not be flexible enough for more complex apps authored with frameworks like React. + +To better fit component-based apps, imgit allows importing media assets with `import` statement to manually author the desired HTML. + +Use `imgit:` namespace when importing a media asset to make imgit optimize it and return sources of the generated assets. For example, consider following [Astro](https://astro.build) page: + +```astro +--- +import psd from "imgit:https://example.com/photo.psd"; +import mkv from "imgit:/assets/video.mkv"; +--- + + + +