Skip to content

Commit

Permalink
Merge pull request #3 from Konkuk-KUIT/dev/dynamic-index-html
Browse files Browse the repository at this point in the history
feat: add index page builder
  • Loading branch information
Jinho1011 authored Sep 10, 2024
2 parents e9c4ebd + bb2c238 commit 34f323c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ jobs:
# done
pnpm build
- name: Create dynamic index.html
run: |
echo "Generating dynamic index.html"
node .scripts/index-page-builder.js
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
personal_token: ${{ secrets.GH_ACTIONS_TOKEN }}
publish_dir: ./build

50 changes: 50 additions & 0 deletions .scripts/index-page-builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const fs = require("fs");
const path = require("path");

// 'build' 폴더를 기준으로 탐색 시작
const baseDir = "../build";

// HTML 템플릿을 시작합니다.
let htmlContent = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Project Index</title>
</head>
<body>
<h1>Projects</h1>
<ul>
`;

// 주차별로 디렉토리를 탐색
const weeks = fs.readdirSync(baseDir);
weeks.forEach((week) => {
const weekPath = path.join(baseDir, week);
if (fs.lstatSync(weekPath).isDirectory()) {
htmlContent += `<li>${week}<ul>\n`;

// 주차별 하위 프로젝트 탐색
const projects = fs.readdirSync(weekPath);
projects.forEach((project) => {
const projectPath = path.join(weekPath, project);
if (fs.lstatSync(projectPath).isDirectory()) {
htmlContent += `<li><a href="/${week}/${project}">${project}</a></li>\n`;
}
});

htmlContent += `</ul></li>\n`;
}
});

htmlContent += `
</ul>
</body>
</html>
`;

// 생성된 HTML을 'build/index.html'에 작성
fs.writeFileSync(path.join(baseDir, "index.html"), htmlContent);

console.log("index.html created successfully.");

0 comments on commit 34f323c

Please sign in to comment.