Skip to content

Commit

Permalink
🚀Perf: 画像の読み取り方法変更
Browse files Browse the repository at this point in the history
  • Loading branch information
SoniPana committed Sep 2, 2024
1 parent aee3669 commit 5f07c56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/pages/profile.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import BaseLayout from '../layouts/BaseLayout.astro';
import ProfileCard from '../components/ProfileCard.astro';
import members from '../data/members.json';
import { Image } from 'astro:assets';
import monitor from "../assets/profile/monitor.jpg"; // Image is 1600x941
import github from "../assets/profile/github.png"; // Image is 1600x900
const pageTitle = 'Profile';
const files = await Astro.glob("../assets/profile/*");
const images = files.reduce((acc, file) => {
acc[file.default.src.split('/').pop().split('.')[0]] = file.default;
return acc;
}, {});
---

<BaseLayout pageTitle={pageTitle}>
Expand Down Expand Up @@ -35,13 +38,13 @@ const pageTitle = 'Profile';
</div>

<div class="relative ms-4">
<Image class="w-full rounded-md" src={monitor} alt="monitor" />
<Image class="w-full rounded-md" src={images.monitor} alt="monitor" />
</div>
</div>

<div class="grid mt-20 md:grid-cols-2 gap-4 md:gap-8 xl:gap-20 md:items-center">
<div class="relative ms-4">
<Image class="w-full rounded-md border border-gray-200" src={github} alt="GitHub" />
<Image class="w-full rounded-md border border-gray-200" src={images.github} alt="GitHub" />
</div>

<div class="justify-center">
Expand Down
9 changes: 9 additions & 0 deletions src/scripts/images.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
async function getImages(files) {
const images = files.reduce((acc, file) => {
const image = file.default;
const fileName = image.src.split('/').pop().split('.')[0]; // ファイル名を抽出
acc[fileName] = image;
return acc;
}, {});
return images;
}

0 comments on commit 5f07c56

Please sign in to comment.