forked from mmistakes/minimal-mistakes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
20 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -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, { | ||
|
@@ -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> | ||
|
||
|
||
|