-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate-readme.js
108 lines (98 loc) · 6.28 KB
/
update-readme.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const fs = require('fs');
const Parser = require('rss-parser');
const parser = new Parser();
function splitDescription(description) {
const words = description.split(' ');
const chunkSize = 15;
const chunks = [];
for (let i = 0; i < words.length; i += chunkSize) {
chunks.push(words.slice(i, i + chunkSize).join(' '));
}
return chunks.join('<br>');
}
async function getLatestAnimeData() {
try {
const feed = await parser.parseURL('https://feeds.feedburner.com/crunchyroll/rss/anime');
return feed.items.map(item => ({
title: item.title,
thumb: item.enclosure.url,
date: new Date(item.isoDate).toLocaleDateString(),
time: new Date(item.isoDate).toLocaleTimeString('en-US', { timeZone: 'UTC', timeStyle: 'medium' }),
link: item.link,
description: splitDescription(item.contentSnippet),
}));
} catch (error) {
console.error('Error fetching feed:', error);
return [];
}
}
async function updateReadmeWithAnimeData() {
try {
const animeData = await getLatestAnimeData();
const truncatedAnimeData = animeData.slice(0, 20);
const currentDate = new Date().toLocaleDateString('en-US', {
timeZone: 'Asia/Jakarta'
});
const currentDateTime = new Date().toLocaleString('en-US', {
timeZone: 'Asia/Jakarta',
dateStyle: 'medium',
timeStyle: 'medium'
});
let readmeContent = `<p align="center"><a href="https://github.com/Julius-Ulee/Announcements-Anime"><img src="https://readme-typing-svg.demolab.com?font=Fira+Code&pause=1000&color=FFDA5D¢er=true&vCenter=true&repeat=false&width=435&lines=Latest+Anime+List" alt="Typing SVG" /></a></p>\n\n`;
readmeContent += `<p align="center"><em>Updated on: ${currentDateTime}</em></p>\n\n`;
readmeContent += `<p align="center"><img src="img/news.png" height="100"></p>`;
readmeContent += `<p align="center">This script aims to automate the process of updating the latest anime information, so that users do not need to do it manually. This makes it easier for users to know what anime are newly released and makes it easier for them to access more information.</p>`;
readmeContent += `<p align="center">
<a href="https://github.com/Julius-Ulee/Announcements-Anime/graphs/contributors"><img align="center" src="https://img.shields.io/github/contributors/Julius-Ulee/Announcements-Anime"></a>
<a href="https://github.com/Julius-Ulee/Announcements-Anime/issues"><img align="center" src="https://img.shields.io/github/issues/Julius-Ulee/Announcements-Anime"></a>
<a href="https://github.com/Julius-Ulee/Announcements-Anime/pulls"><img align="center" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=shields"></a>
<a href="https://github.com/Julius-Ulee/Announcements-Anime/pulls"><img align="center" src="https://img.shields.io/github/issues-pr/Julius-Ulee/Announcements-Anime"></a>
<a href="https://github.com/Julius-Ulee/Announcements-Anime/commits/master/"><img align="center" src="https://img.shields.io/github/commit-activity/m/Julius-Ulee/Announcements-Anime"></a>
<img align="center" src="https://github.com/Julius-Ulee/github-profile-views-counter/blob/master/svg/738176371/badge.svg">
<img align="center" height='20' src="https://github.com/Julius-Ulee/github-profile-views-counter/blob/master/graph/738176371/small/week.png"><br>
<a href="https://github.com/Julius-Ulee/Announcements-Anime"><img align="center" src="https://img.shields.io/maintenance/yes/2024"></a></p>`;
readmeContent += `<p align="center"><b>Display GitHub Action Badge</b> <a href="https://github.com/Julius-Ulee/Announcements-Anime/actions/workflows/black.yml"><img align="center" src="https://github.com/Julius-Ulee/Announcements-Anime/actions/workflows/black.yml/badge.svg"></a> <a href="https://github.com/Julius-Ulee/Announcements-Anime/actions/workflows/pages.yml"><img align="center" src="https://github.com/Julius-Ulee/Announcements-Anime/actions/workflows/pages.yml/badge.svg"></a></p>`;
readmeContent += `<p align="center"><a href="https://github.com/Julius-Ulee/Announcements-Anime/blob/master/README.md">Readme</a> • <a href="https://github.com/Julius-Ulee/Announcements-Anime/blob/master/.github/workflows/black.yml">Actions-YML</a> • <a href="https://github.com/Julius-Ulee/Announcements-Anime/blob/master/.gitignore">Gitignore</a> • <a href="https://github.com/Julius-Ulee/Announcements-Anime/blob/master/update-readme.js">Update-readme</a> • <a href="https://github.com/Julius-Ulee/Announcements-Anime/blob/master/package.json">Package</a></p>`;
truncatedAnimeData.forEach(anime => {
readmeContent += `<table align="center">\n`;
readmeContent += `<tr>\n`;
readmeContent += `<th><h3 align="center">${anime.title}</h3></th>\n`;
readmeContent += `</tr>\n`;
readmeContent += `<tr>\n`;
readmeContent += `<td>\n`;
readmeContent += `<p align="center">\n`;
readmeContent += `<img src="${anime.thumb}" height="256">\n`;
readmeContent += `</p>\n`;
readmeContent += `</td>\n`;
readmeContent += `</tr>\n`;
readmeContent += `<tr>\n`;
readmeContent += `<td>\n`;
readmeContent += `<table align="center">\n`;
readmeContent += `<tr>\n`;
readmeContent += `<td>📔 Publish Date :</td>\n`;
readmeContent += `<td align="center">${anime.date}</td>\n`;
readmeContent += `</tr>\n`;
readmeContent += `<tr>\n`;
readmeContent += `<td>📕 Link :</td>\n`;
readmeContent += `<td align="center"><a href="${anime.link}">Anime Information</a></td>\n`;
readmeContent += `</tr>\n`;
readmeContent += `<tr>\n`;
readmeContent += `<td colspan="2">📙 Description :</td>`;
readmeContent += `</tr>\n`;
readmeContent += `<tr>\n`;
readmeContent += `<td colspan="2">\n`;
readmeContent += `<p align="center">${anime.description}</p>\n`;
readmeContent += `</td>\n`;
readmeContent += `</tr>\n`;
readmeContent += `</table>\n`;
readmeContent += `</td>\n`;
readmeContent += `</tr>\n`;
readmeContent += `</table>\n\n`;
});
fs.writeFileSync('README.md', readmeContent);
console.log('README.md updated successfully with latest anime data and date!');
} catch (error) {
console.error('Error updating README.md:', error);
}
}
updateReadmeWithAnimeData().catch(error => console.error('Error:', error));