-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update background image URL in stylesheet.css and add lazy load…
…ing for images in TalkListContent
- Loading branch information
Showing
9 changed files
with
65 additions
and
11 deletions.
There are no files selected for viewing
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
export const handler = { | ||
async GET(req: Request, ctx: any) { | ||
const userid = ctx.state.data.userid; | ||
try { | ||
// ./backgroundImages/にある画像すべてを取得 | ||
const dirPath = "./backgroundImages"; | ||
const result = await readRandomImageFromDir(dirPath).catch(console.error); | ||
return new Response(result, { | ||
status: 200, | ||
headers: { | ||
"Content-Type": "image/jpeg", | ||
}, | ||
}); | ||
} catch (e) { | ||
console.log(e); | ||
return new Response("Internal Server Error", { status: 500 }); | ||
} | ||
}, | ||
}; | ||
|
||
// ランダムに数値を生成する関数 | ||
function getRandomInt(max: number): number { | ||
return Math.floor(Math.random() * max); | ||
} | ||
|
||
// 指定されたディレクトリからランダムな画像ファイルを読み込む関数 | ||
async function readRandomImageFromDir(dir: string) { | ||
const imageExtensions = [".jpg", ".jpeg", ".png", ".gif",".webp"]; | ||
const files: string[] = []; | ||
for await (const dirEntry of Deno.readDir(dir)) { | ||
if (dirEntry.isFile && imageExtensions.some((ext) => dirEntry.name.toLowerCase().endsWith(ext))) { | ||
files.push(dirEntry.name); | ||
} | ||
} | ||
|
||
if (files.length === 0) { | ||
throw new Error("ディレクトリに画像ファイルがありません。"); | ||
} | ||
|
||
const randomIndex = getRandomInt(files.length); | ||
const randomFile = `${dir}/${files[randomIndex]}`; | ||
const imageData = await Deno.readFile(randomFile); | ||
return imageData; | ||
// 画像の内容はバイナリデータとして出力されるため、ここでは内容の表示は省略 | ||
// 必要に応じて画像データを処理するコードを追加してください | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters