Skip to content

Commit

Permalink
eetc
Browse files Browse the repository at this point in the history
  • Loading branch information
elringus committed Nov 15, 2023
1 parent 22b58e3 commit 50ea5dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions docs/.vitepress/ext/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ export const vite: UserConfig = {
local: "./docs/public/assets",
cache: "./docs/public/assets/remote/.cache",
width: 720,
// poster: "/assets/img/video-poster.svg",
build: { // Hack for chrome. TODO: Remove after implementing posters w/o video.poster attribute.
...defaults.build,
video: async asset => {
const base = await defaults.build.video(asset);
const mod = asset.sourceInfo.width > 720 ? 720 / asset.sourceInfo.width : 1;
const width = Math.floor(asset.sourceInfo.width * mod);
const height = Math.floor(asset.sourceInfo.height * mod);
const mod = asset.sourceInfo!.width > 720 ? 720 / asset.sourceInfo!.width : 1;
const width = Math.floor(asset.sourceInfo!.width * mod);
const height = Math.floor(asset.sourceInfo!.height * mod);
return base.replace("width=", `style="width: ${width}px; height: ${height}px;" width=`);
}
}
Expand Down
7 changes: 4 additions & 3 deletions docs/.vitepress/imgit/server/transform/5-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export async function buildAnimation(asset: EncodedAsset): Promise<string> {
}

export async function buildVideo(asset: EncodedAsset): Promise<string> {
const { src, encodedSrc } = buildSources(asset);
const { src, encodedSrc, posterSrc } = buildSources(asset);
const size = buildSizes(asset.sourceInfo);
const cls = `class="${config.style.className.video}"`;
return `
<video ${cls} preload="none" loop autoplay muted playsinline poster="/assets/img/video-poster.svg" ${size}>
<video ${cls} preload="none" loop autoplay muted playsinline poster="${posterSrc}" ${size}>
${encodedSrc ? `<source data-src="${encodedSrc}" type="video/mp4; codecs=av01.0.05M.08">` : ""}
<source data-src="${src}" type="video/mp4">
</video>
Expand All @@ -67,7 +67,8 @@ function buildSources(asset: EncodedAsset) {
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 };
const posterSrc = asset.posterPath ? path.join(root, path.basename(asset.posterPath)) : config.poster;
return { src, encodedSrc, posterSrc };
}

function buildServeRoot(asset: EncodedAsset): string {
Expand Down

0 comments on commit 50ea5dd

Please sign in to comment.