From 826fcc8efd80cde7196bfddb4b8d5bcd0610c2ad Mon Sep 17 00:00:00 2001 From: Artyom Sovetnikov <2056864+Elringus@users.noreply.github.com> Date: Tue, 14 Nov 2023 19:53:23 +0300 Subject: [PATCH] iteration --- .../imgit/server/config/defaults.ts | 8 ++++ .../.vitepress/imgit/server/config/options.ts | 17 +++++++ .../imgit/server/transform/5-build.ts | 45 +++++++++++++++---- docs/.vitepress/theme/style.css | 6 +-- 4 files changed, 62 insertions(+), 14 deletions(-) diff --git a/docs/.vitepress/imgit/server/config/defaults.ts b/docs/.vitepress/imgit/server/config/defaults.ts index a3fa95572..c96bbba72 100644 --- a/docs/.vitepress/imgit/server/config/defaults.ts +++ b/docs/.vitepress/imgit/server/config/defaults.ts @@ -55,5 +55,13 @@ export const defaults: Readonly> = { encode, build: builds.build, rewrite + }, + style: { + className: { + image: "imgit-image", + animation: "imgit-animation", + video: "imgit-video", + youtube: "imgit-youtube" + } } }; diff --git a/docs/.vitepress/imgit/server/config/options.ts b/docs/.vitepress/imgit/server/config/options.ts index 590bf1ec3..4e6dbc89a 100644 --- a/docs/.vitepress/imgit/server/config/options.ts +++ b/docs/.vitepress/imgit/server/config/options.ts @@ -49,6 +49,8 @@ export type Options = Record & { build?: BuildOptions; /** Configure document transformation process. */ transform?: TransformOptions; + /** Configure generated CSS styles. */ + style?: StyleOptions; }; /** Configures logging behaviour. */ @@ -128,3 +130,18 @@ export type TransformOptions = { /** 6th phase: rewrites content of the document with specified assets; returns modified document content. */ rewrite: (content: string, assets: BuiltAsset[]) => Promise; }; + +/** Configures generated CSS styles. */ +export type StyleOptions = { + /** Class names assigned to generated HTML. */ + className: { + /** Class name assigned to generated images HTML; imgit-image by default. */ + image: string; + /** Class name assigned to generated video HTML; imgit-video by default. */ + video: string; + /** Class name assigned to generated animation HTML; imgit-animation by default. */ + animation: string; + /** Class name assigned to generated YouTube HTML; imgit-youtube by default. */ + youtube: string; + } +} diff --git a/docs/.vitepress/imgit/server/transform/5-build.ts b/docs/.vitepress/imgit/server/transform/5-build.ts index 4c739c02c..56a566350 100644 --- a/docs/.vitepress/imgit/server/transform/5-build.ts +++ b/docs/.vitepress/imgit/server/transform/5-build.ts @@ -17,30 +17,57 @@ async function buildAsset(asset: EncodedAsset): Promise { } export async function buildImage(asset: EncodedAsset): Promise { - const path = platform.path; - const src = path.join(buildServeRoot(asset), path.basename(asset.sourceUrl)); + const { src, encodedSrc } = buildSources(asset); const alt = asset.title ?? ""; const size = buildSizes(asset.sourceInfo); - return `${alt}`; + const cls = `class="${config.style.className.image}"`; + return ` + + ${encodedSrc ? `` : ""} + ${alt} + +`; } export async function buildAnimation(asset: EncodedAsset): Promise { - return buildImage(asset); + const { src, encodedSrc } = buildSources(asset); + const alt = asset.title ?? ""; + const size = buildSizes(asset.sourceInfo); + const cls = `class="${config.style.className.animation}"`; + return ` + + ${encodedSrc ? `` : ""} + ${alt} + +`; } export async function buildVideo(asset: EncodedAsset): Promise { - const path = platform.path; - const src = path.join(buildServeRoot(asset), path.basename(asset.sourceUrl)); + const { src, encodedSrc } = buildSources(asset); const size = buildSizes(asset.sourceInfo); - const source = ``; - return ``; + const cls = `class="${config.style.className.video}"`; + return ` + +`; } export async function buildYouTube(asset: EncodedAsset): Promise { const title = asset.title ?? ""; + const cls = `class="${config.style.className.youtube}"`; const id = asset.sourceUrl.split("youtube.com/watch?v=")[1]; const source = `https://www.youtube-nocookie.com/embed/${id}`; - return ``; + return ``; +} + +function buildSources(asset: EncodedAsset) { + const path = platform.path; + const root = buildServeRoot(asset); + const src = path.join(root, path.basename(asset.sourceUrl)); + const encodedSrc = asset.encodedPath ? path.join(root, path.basename(asset.encodedPath)) : undefined; + return { src, encodedSrc }; } function buildServeRoot(asset: EncodedAsset): string { diff --git a/docs/.vitepress/theme/style.css b/docs/.vitepress/theme/style.css index 21c7e1d68..8528ae6ef 100644 --- a/docs/.vitepress/theme/style.css +++ b/docs/.vitepress/theme/style.css @@ -312,11 +312,7 @@ table > tfoot:not(:last-child) { display: block; } -.imgit-image { - border-radius: 8px; -} - -.imgit-video { +.imgit-image, .imgit-animation, .imgit-video { border-radius: 8px; }