Skip to content

Commit

Permalink
달력 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
durumi922 committed Oct 11, 2024
1 parent d48a3bc commit cbbb103
Showing 1 changed file with 44 additions and 20 deletions.
64 changes: 44 additions & 20 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,46 @@ <h3>TIL Calendar</h3>
<script src='https://cdn.jsdelivr.net/npm/@fullcalendar/[email protected]/main.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/@fullcalendar/[email protected]/main.min.js'></script>
<script>
const username = 'durumi922'; // GitHub 사용자명
const repo = 'durumi922.github.io'; // 리포지토리 이름
const baseURL = `https://api.github.com/repos/${username}/${repo}/contents/_posts/TIL/24`; // base URL

// 각 폴더를 가져오는 함수
async function fetchFolder(folder) {
const url = `${baseURL}/${folder}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error('Failed to fetch folder contents');
}
return response.json();
}

// 이벤트를 추가하는 함수
async function addEvents() {
const folders = ['24.7', '24.8', '24.10']; // 하위 폴더 목록
const events = [];

for (const folder of folders) {
try {
const files = await fetchFolder(folder);
files.forEach(file => {
if (file.name.match(/^\d{4}-\d{2}-\d{2}-TIL\.md$/)) {
const dateParts = file.name.split('-TIL.md')[0];
events.push({ title: 'TIL 작성', start: dateParts });
}
});
} catch (error) {
console.error('Error fetching files:', error);
}
}

events.forEach(event => {
calendar.addEvent(event);
});
calendar.render(); // 이벤트가 추가된 후 다시 렌더링
}

// 초기화
document.addEventListener('DOMContentLoaded', function() {
const calendarEl = document.getElementById('small-calendar');
const calendar = new FullCalendar.Calendar(calendarEl, {
Expand All @@ -78,27 +118,11 @@ <h3>TIL Calendar</h3>
events: [] // GitHub API에서 가져온 데이터가 여기에 들어감
});
calendar.render();

const username = 'durumi922'; // GitHub 사용자명
const repo = 'durumi922.github.io'; // 리포지토리 이름
const apiURL = `https://api.github.com/repos/${username}/${repo}/contents/`;

fetch(apiURL)
.then(response => response.json())
.then(data => {
const events = data
.filter(file => file.name.match(/^\d{4}-\d{2}-\d{2}-TIL\.md$/))
.map(file => {
const dateParts = file.name.split('-TIL.md')[0];
return { title: 'TIL 작성', start: dateParts };
});

events.forEach(event => {
calendar.addEvent(event);
});
})
.catch(error => console.error('Error fetching files:', error));

// 이벤트 추가
addEvents();
});

</script>


Expand Down

0 comments on commit cbbb103

Please sign in to comment.